生活随笔
收集整理的這篇文章主要介紹了
调用照相机和相册功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IOS成長之路-調用照相機和相冊功能
分類:?IOS2013-01-04 17:05?
12786人閱讀?
評論(0)?收藏?舉報
打開相機:
[cpp]?view plaincopy
//先設定sourceType為相機,然后判斷相機是否可用(ipod)沒相機,不可用將sourceType設定為相片庫?? ????UIImagePickerControllerSourceType?sourceType?=?UIImagePickerControllerSourceTypeCamera;?? //????if?(![UIImagePickerController?isSourceTypeAvailable:?UIImagePickerControllerSourceTypeCamera])?{?? //????????sourceType?=?UIImagePickerControllerSourceTypePhotoLibrary;?? //????}?? ????//sourceType?=?UIImagePickerControllerSourceTypeCamera;?//照相機?? ????//sourceType?=?UIImagePickerControllerSourceTypePhotoLibrary;?//圖片庫?? ????//sourceType?=?UIImagePickerControllerSourceTypeSavedPhotosAlbum;?//保存的相片?? ????UIImagePickerController?*picker?=?[[UIImagePickerController?alloc]?init];//初始化?? ????picker.delegate?=?self;?? ????picker.allowsEditing?=?YES;//設置可編輯?? ????picker.sourceType?=?sourceType;?? ????[self?presentModalViewController:picker?animated:YES];//進入照相界面?? ????[picker?release];?? 打開相冊:(區分pad和iphone)
for iphone:
[cpp]?view plaincopy
UIImagePickerController?*pickerImage?=?[[UIImagePickerController?alloc]?init];?? ????if([UIImagePickerController?isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])?{?? ????????pickerImage.sourceType?=?UIImagePickerControllerSourceTypePhotoLibrary;?? ????????//pickerImage.sourceType?=?UIImagePickerControllerSourceTypeSavedPhotosAlbum;?? ????????pickerImage.mediaTypes?=?[UIImagePickerController?availableMediaTypesForSourceType:pickerImage.sourceType];?? ?????????? ????}?? ????pickerImage.delegate?=?self;?? ????pickerImage.allowsEditing?=?NO;?? ????[self?presentModalViewController:pickerImage?animated:YES];?? ????[pickerImage?release];?? for ipad:
[cpp]?view plaincopy
UIImagePickerControllerSourceType?sourceType?=?UIImagePickerControllerSourceTypePhotoLibrary;?? ????//sourceType?=?UIImagePickerControllerSourceTypeSavedPhotosAlbum;?//保存的相片?? ????UIImagePickerController?*picker?=?[[UIImagePickerController?alloc]?init];?? ????picker.delegate?=?self;?? ????picker.allowsEditing?=?NO;//是否允許編輯?? ????picker.sourceType?=?sourceType;?? ????/*? ?????如果從一個導航按鈕處呈現,使用:? ?????presentPopoverFromBarButtonItem:permittedArrowDirections:animated:;? ?????如果要從一個視圖出呈現,使用:? ?????presentPopoverFromRect:inView:permittedArrowDirections:animated:? ?????? ?????如果設備旋轉以后,位置定位錯誤需要在父視圖控制器的下面方法里面重新定位:? ?????didRotateFromInterfaceOrientation:(在這個方法體里面重新設置rect)? ?????然后再次調用:? ?????-?(void)presentPopoverFromRect:(CGRect)rect?inView:(UIView?*)view?permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections?animated:(BOOL)animated?????????????? ?????*/?? ????//UIPopoverController只能在ipad設備上面使用;作用是用于顯示臨時內容,特點是總是顯示在當前視圖最前端,當單擊界面的其他地方時自動消失。?? ????UIPopoverController?*popover?=?[[UIPopoverController?alloc]initWithContentViewController:picker];?? ????self.imagePicker?=?popover;?? ????//permittedArrowDirections?設置箭頭方向?? ????[self.imagePicker?presentPopoverFromRect:CGRectMake(0,?0,?300,?300)?inView:self.view?permittedArrowDirections:UIPopoverArrowDirectionAny?animated:YES];?? ????[picker?release];?? ????[popover?release];??
點擊相冊中的圖片 貨照相機照完后點擊use??后觸發的方法
- (void)imagePickerController:(UIImagePickerController?*)picker?didFinishPickingMediaWithInfo:(NSDictionary?*)info
點擊cancel 調用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController?*)picker?
總結
以上是生活随笔為你收集整理的调用照相机和相册功能的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。