iOS-UIActionSheet的简单使用和调用系统相簿

2023-12-04 11:48

本文主要是介绍iOS-UIActionSheet的简单使用和调用系统相簿,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

实现UIActionSheetDelegate


UIActionSheet *menu = [[UIActionSheet alloc]

                           initWithTitle: @""

                           delegate:self

                           cancelButtonTitle:@"Cancel"

                           destructiveButtonTitle:nil

                           otherButtonTitles:@"图库相册",@"拍照", nil];

    [menu showInView:self.view];


# pragma mark UIActionSheet method

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex==0) {

        [self photoalbumr];//图库相册

    

    }else if(buttonIndex==1){

         [self photocamera];//拍照

    }else if(buttonIndex==2){

    

    }


    

    [actionSheet release];

}



调用系统的相簿


实现UIImagePickerControllerDelegate


-(void)photoalbumr{

    if ([UIImagePickerController isSourceTypeAvailable:

         UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *picker =

        [[UIImagePickerController alloc] init];

        picker.delegate = self;

        picker.allowsImageEditing = YES;

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:picker animated:YES];

        [picker release];

    }

    else {

        UIAlertView *alert = [[UIAlertView alloc

                              initWithTitle:@"Error accessing photo library" 

                              message:@"Device does not support a photo library" 

                              delegate:nil 

                              cancelButtonTitle:@"Drat!" 

                              otherButtonTitles:nil];

        [alert show];

        [alert release];

        

    }


}

-(void)photocamera{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController* imagepicker = [[UIImagePickerController alloc] init];

        imagepicker.delegate = self;

        imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

        imagepicker.allowsEditing = YES;

        [self presentModalViewController:imagepicker animated:YES];


    }

    else {

        UIAlertView *alert = [[UIAlertView alloc

                              initWithTitle:@"Sorry" 

                              message:@"设备不支持拍照功能" 

                              delegate:nil 

                              cancelButtonTitle:@"确定" 

                              otherButtonTitles:nil];

        [alert show];

        [alert release];

        

    }


  }

#pragma mark UIImagePicker method

- (void)imagePickerController:(UIImagePickerController *)picker 

        didFinishPickingImage:(UIImage *)image 

                  editingInfo:(NSDictionary *)editingInfo

{  

  /*将图片存储到document下

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];

    NSData *imageData = UIImagePNGRepresentation(image);

    [imageData writeToFile:savedImagePath atomically:NO];   

      _imgName=@"savedImage.png";

    self._imgFilePath=documentsDirectory;

    */

  

    [addPhoto setBackgroundImage:image forState:UIControlStateNormal];

   

     [picker dismissModalViewControllerAnimated:YES];


}


// 完成选取

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [picker dismissModalViewControllerAnimated:YES];

}







这篇关于iOS-UIActionSheet的简单使用和调用系统相簿的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/453351

相关文章

使用Python自建轻量级的HTTP调试工具

《使用Python自建轻量级的HTTP调试工具》这篇文章主要为大家详细介绍了如何使用Python自建一个轻量级的HTTP调试工具,文中的示例代码讲解详细,感兴趣的小伙伴可以参考一下... 目录一、为什么需要自建工具二、核心功能设计三、技术选型四、分步实现五、进阶优化技巧六、使用示例七、性能对比八、扩展方向建

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

使用Python实现一键隐藏屏幕并锁定输入

《使用Python实现一键隐藏屏幕并锁定输入》本文主要介绍了使用Python编写一个一键隐藏屏幕并锁定输入的黑科技程序,能够在指定热键触发后立即遮挡屏幕,并禁止一切键盘鼠标输入,这样就再也不用担心自己... 目录1. 概述2. 功能亮点3.代码实现4.使用方法5. 展示效果6. 代码优化与拓展7. 总结1.

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Linux中的计划任务(crontab)使用方式

《Linux中的计划任务(crontab)使用方式》:本文主要介绍Linux中的计划任务(crontab)使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、前言1、linux的起源与发展2、什么是计划任务(crontab)二、crontab基础1、cro

kotlin中const 和val的区别及使用场景分析

《kotlin中const和val的区别及使用场景分析》在Kotlin中,const和val都是用来声明常量的,但它们的使用场景和功能有所不同,下面给大家介绍kotlin中const和val的区别,... 目录kotlin中const 和val的区别1. val:2. const:二 代码示例1 Java

C++变换迭代器使用方法小结

《C++变换迭代器使用方法小结》本文主要介绍了C++变换迭代器使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1、源码2、代码解析代码解析:transform_iterator1. transform_iterat

C++中std::distance使用方法示例

《C++中std::distance使用方法示例》std::distance是C++标准库中的一个函数,用于计算两个迭代器之间的距离,本文主要介绍了C++中std::distance使用方法示例,具... 目录语法使用方式解释示例输出:其他说明:总结std::distance&n编程bsp;是 C++ 标准

vue使用docxtemplater导出word

《vue使用docxtemplater导出word》docxtemplater是一种邮件合并工具,以编程方式使用并处理条件、循环,并且可以扩展以插入任何内容,下面我们来看看如何使用docxtempl... 目录docxtemplatervue使用docxtemplater导出word安装常用语法 封装导出方

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将