首页 > 移动平台 > 详细

IOS调用相机相册

时间:2015-10-12 23:58:37      阅读:442      评论:0      收藏:0      [点我收藏+]
  1. #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考
  2. #import <MobileCoreServices/UTCoreTypes.h>  
  3. @interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>  
  4. -(IBAction)selectDescPic:(id)sender;  
  5. @end  
  6.   
  7. @implementation SendViewController  
  8.   
  9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
  10.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  11.     if (self) {  
  12.           
  13.     }  
  14.     return self;  
  15. }  
  16.   
  17. - (void)viewDidLoad {  
  18.     [super viewDidLoad];  
  19. }  
  20.   
  21. - (void)didReceiveMemoryWarning {  
  22.     [super didReceiveMemoryWarning];  
  23. }  
  24.   
  25. -(IBAction)selectDescPic:(id)sender {  
  26.     UIActionSheet *actionSheet = [[UIActionSheet alloc]  
  27.                                   initWithTitle:nil  
  28.                                   delegate:self  
  29.                                   cancelButtonTitle:@"取消"  
  30.                                   destructiveButtonTitle:nil  
  31.                                   otherButtonTitles:@"拍照", @"从手机相册选择",nil];  
  32.     actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;  
  33.     [actionSheet showInView:self.view];  
  34. }  
  35.   
  36. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  
  37.     if (buttonIndex == 0) {  
  38.         UIImagePickerController *camera = [[UIImagePickerController alloc] init];  
  39.         camera.delegate = self;  
  40.         camera.allowsEditing = NO;  
  41.           
  42.         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {  
  43.             camera.sourceType = UIImagePickerControllerSourceTypeCamera;  
  44.             //此处设置只能使用相机,禁止使用视频功能  
  45.             camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];  
  46.         } else {  
  47.             NSLog(@"相机功能不可用");  
  48.             return;  
  49.         }  
  50.         [self presentViewController:camera animated:YES completion:nil];  
  51.     } else if (buttonIndex == 1) {  
  52.         UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
  53.         picker.delegate = self;  
  54.         picker.allowsEditing = NO;  
  55.         //从相册列表选取  
  56.         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  57.           
  58.         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {  
  59.             //此处设置只能使用相机,禁止使用视频功能  
  60.             picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];  
  61.         }  
  62.         [self presentViewController:picker animated:YES completion:nil];  
  63.     } else if(buttonIndex == 2) {  
  64.         //取消  
  65.     }  
  66. }  
  67.   
  68.   
  69. @end  

IOS调用相机相册

原文:http://www.cnblogs.com/isItOk/p/4873100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!