码迷,mamicode.com
首页 > 移动开发 > 详细

IOS成长之路-调用照相机和相册功能

时间:2014-08-12 13:19:04      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   使用   os   io   for   ar   

打开相机:

  1. //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库  
  2.     UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;  
  3. //    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {  
  4. //        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  5. //    }  
  6.     //sourceType = UIImagePickerControllerSourceTypeCamera; //照相机  
  7.     //sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库  
  8.     //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片  
  9.     UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化  
  10.     picker.delegate = self;  
  11.     picker.allowsEditing = YES;//设置可编辑  
  12.     picker.sourceType = sourceType;  
  13.     [self presentModalViewController:picker animated:YES];//进入照相界面  
  14.     [picker release];  


打开相册:(区分pad和iphone)

for iphone:

  1. UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];  
  2.     if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {  
  3.         pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  4.         //pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;  
  5.         pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];  
  6.           
  7.     }  
  8.     pickerImage.delegate = self;  
  9.     pickerImage.allowsEditing = NO;  
  10.     [self presentModalViewController:pickerImage animated:YES];  
  11.     [pickerImage release];  


for ipad:

  1. UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  2.     //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片  
  3.     UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
  4.     picker.delegate = self;  
  5.     picker.allowsEditing = NO;//是否允许编辑  
  6.     picker.sourceType = sourceType;  
  7.     /* 
  8.      如果从一个导航按钮处呈现,使用: 
  9.      presentPopoverFromBarButtonItem:permittedArrowDirections:animated:; 
  10.      如果要从一个视图出呈现,使用: 
  11.      presentPopoverFromRect:inView:permittedArrowDirections:animated: 
  12.       
  13.      如果设备旋转以后,位置定位错误需要在父视图控制器的下面方法里面重新定位: 
  14.      didRotateFromInterfaceOrientation:(在这个方法体里面重新设置rect) 
  15.      然后再次调用: 
  16.      - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated              
  17.      */  
  18.     //UIPopoverController只能在ipad设备上面使用;作用是用于显示临时内容,特点是总是显示在当前视图最前端,当单击界面的其他地方时自动消失。  
  19.     UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:picker];  
  20.     self.imagePicker = popover;  
  21.     //permittedArrowDirections 设置箭头方向  
  22.     [self.imagePicker presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
  23.     [picker release];  
  24.     [popover release];  


点击相册中的图片 货照相机照完后点击use  后触发的方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info


点击cancel 调用的方法

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker


例子下载地址:http://download.csdn.net/download/like7xiaoben/4958356

本文转自......

IOS成长之路-调用照相机和相册功能,布布扣,bubuko.com

IOS成长之路-调用照相机和相册功能

标签:style   http   color   使用   os   io   for   ar   

原文地址:http://www.cnblogs.com/wlcc/p/3906805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!