IOS调用相机相册
======================================================================================
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考
#import <MobileCoreServices/UTCoreTypes.h>
@interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
-(IBAction)selectDescPic:(id)sender;
@end
@implementation SendViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(IBAction)selectDescPic:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"拍照", @"从手机相册选择",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
UIImagePickerController *camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.allowsEditing = NO;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
//此处设置只能使用相机,禁止使用视频功能
camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
} else {
NSLog(@"相机功能不可用");
return;
}
[self presentViewController:camera animated:YES completion:nil];
} else if (buttonIndex == 1) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
//从相册列表选取
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//此处设置只能使用相机,禁止使用视频功能
picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
}
[self presentViewController:picker animated:YES completion:nil];
} else if(buttonIndex == 2) {
//取消
}
}
@end
=========================================
将图片保存到相册 亲试可用
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
_imageView.image = [UIImage imageNamed:@"hmt.jpg"];
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];
[self.imageView addGestureRecognizer:tapGesture]; } - (void)tapSaveImageToIphone{ /**
* 将图片保存到iPhone本地相册
* UIImage *image 图片对象
* id completionTarget 响应方法对象
* SEL completionSelector 方法
* void *contextInfo
*/
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{ if (error == nil) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show]; }else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
[alert show];
} }
IOS调用相机相册的更多相关文章
- iOS调用相机,相册,上传头像
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- ios调用系统相册、相机 显示中文标题、本地化多语言支持
因为调用系统相册.相机需要显示中文,所以搞了半天才知道是在Project->info->Custom ios Target Properties 添加 Localizations 并加入C ...
- IOS调用相机和相册时无法显示中文
调用系统相册.相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文 需要在info.plist做如下设置 info.plist里面添加 Localizedresourc ...
- iOS调用系统相册、相机 显示中文标题
解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表 ...
- iOS 调用系统相册 相机 时,显示中文标题
解决手机语言已经设置显示中文 在调用系统相册.相机界面 时显示英文问题, 在 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序 ...
- H5-安卓和ios调用相机和相册
<input v-if="ipshow" type="file" accept="image/*" name="file1& ...
- cordova+vue打包ios调用相机闪退解决
cordova+vue项目打包android,打开相机正常使用,但是打包ios后,需要多几个配置,才能打开,否则当调用的时候会闪退,上配置图 需要在选中的文件里面添加 <key>NSCam ...
- ios 调用相机后 view 下沉问题
我只加了一句代码 现在不报错了 因为这个问题是随机性的 我也不太明白这个地方是怎么回事 我只是这样子做了 问题不出来了 if ([[[UIDevice currentDevice] syst ...
随机推荐
- 【LIC】O(nlogn)解法
[LIC--最长递增子序列问题] 在一列数中寻找一些数,这些数满足:任意两个数a[i]和a[j],若i<j,必有a[i]<a[j],这样最长的子序列称为最长递增子序列. O(nlogn)算 ...
- hdu 4340 树状DP
思路:我们定义两个数组,ant[Maxn][2],bob[Maxn][2].ant[i][0]表示还未确定哪个城市被全费用占领,ant[i][1]表示确定了哪个城市被全费用占领.那么ant[i][0] ...
- 谈在一个将TXT按章节分割的PHP程序中的收获
最近在做一个自动分割txt小说的东西,能够将一整个txt文件按照章节进行分割,然后分解成一个个小的.txt文件保存起来并且能够获取有多少章节和每章的章节名. 我最初的想法是: ① 先使用fopen打开 ...
- 一个关于如何创建类似于QQ客户端聊天窗口的模拟小项目
对于不久之前学习到的一个有关的类似于QQ聊天框的模拟项目,对其中涉及到的知识在这里做一下总结. 首先,你要先创建一个客户端聊天框(取名为:ChatClient,它是你创建的类),这个类继承了Frame ...
- 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...
- 第三十八篇、给UITabBar按钮的动画效果
在很多情况下,我们也时常有这样的需求,就是在UITabBar切换的时候,添加一些动画效果 1.在UITabBar触发点击方法的时候捕获当前点击的item 2.使用coreAnimation设置动画效果 ...
- Xcode7网络问题
更新Xcode7以后运行模拟器,控制台打印:Application Transport Security has blocked a cleartext HTTP (http://) resource ...
- log4j定义某个类的日志级别
项目引入了定时任务后,当我把已有的定时任务删除后,控制台一直会打出类似于 [org.springframework.scheduling.quartz.LocalDataSourceJobStore] ...
- 线程间操作无效: 从不是创建控件“label4”的线程访问它。
//主线程 public delegate void UpdateMessage(string mes); public void UpdatePortMessage(string mes) { th ...
- C++ 中 const 和 static 的作用
目录 const 的主要应用如下: const 关键字使用的注意点: C++中static关键字有三个明显的作用: const的主要应用如下: const 用于定义常量:const定义的常量编译器可以 ...