调用系统的相机和相册
2016-01-13 15:30
281 查看
UIActionSheet *as = [[UIActionSheet alloc]initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"打开照相机"
otherButtonTitles:@"从手机相册获取", nil
];
as.tag=1;
[as showInView:self.view];
//actionSheet协议
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypeCamera];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}else{
NSLog(@"这设备没相机");
}
}
break;
case 1:{
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}
break;
}
}
//选择完成
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage*image=[info objectForKey:@"UIImagePickerControllerEditedImage"];
self.sendimg=[NSMutableArray arrayWithObjects:image, nil];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
//取消选择图片
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"打开照相机"
otherButtonTitles:@"从手机相册获取", nil
];
as.tag=1;
[as showInView:self.view];
//actionSheet协议
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypeCamera];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}else{
NSLog(@"这设备没相机");
}
}
break;
case 1:{
UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
[ipc setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
ipc.delegate = self;
ipc.allowsEditing = YES;
[self presentViewController:ipc animated:YES completion:nil];
}
break;
}
}
//选择完成
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage*image=[info objectForKey:@"UIImagePickerControllerEditedImage"];
self.sendimg=[NSMutableArray arrayWithObjects:image, nil];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
//取消选择图片
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
相关文章推荐
- Objective-C的内省(Introspection)用法小结
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect实例分析
- Objective-C中NSNumber与NSDictionary的用法简介
- Objective-C中NSLog输出格式大全
- 全面解析Objective-C中的block代码块的使用
- Swift调用Objective-C编写的API实例
- Swift、Objective-C、Cocoa混合编程设置指南
- Objective-c代码如何移植为Swift代码 Objective-c代码转移到Swift过程介绍
- Swift调用Objective-C代码
- 以实例讲解Objective-C中的KVO与KVC机制
- 理解Objective-C的变量以及面相对象的继承特性
- 简单讲解Objective-C的基本特性及其内存管理方式
- objective-c中生成随机数的方法
- 在Swift中使用Objective-C编写类、继承Objective-C类
- Swift能代替Objective-C吗?
- Objective-C 消息传递机制详解
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- vm安装mac os x 10.7 lion
- objective-c(一)