from: 使用UIImagePickerController從IPhone照片庫或照相機擷取映像
使用UIimagePickerController選取照片庫操作十分簡單:
在對應響應中:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self; //控制器當然要遵循響應的delegate協議
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //指定picker的資源,有三種
//enum { UIImagePickerControllerSourceTypePhotoLibrary,
// UIImagePickerControllerSourceTypeCamera,
// UIImagePickerControllerSourceTypeSavedPhotosAlbum }
[selfpresentModalViewController:picker animated:YES]; //顯示picker view
在delegate方法中:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//info: A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked
[picker dismissModalViewControllerAnimated:YES]; //讓其消失
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
NSString *const UIImagePickerControllerMediaType;NSString *const UIImagePickerControllerOriginalImage;NSString *const UIImagePickerControllerEditedImage;NSString *const UIImagePickerControllerCropRect;NSString *const UIImagePickerControllerMediaURL;NSString *const UIImagePickerControllerReferenceURL;NSString *const UIImagePickerControllerMediaMetadata;
RootViewController - tableView:cellForRowAtIndexPath - Load image from assetsLibrary
Using AssetsLibrary Framework loading images too slow
補充:ipad的不能調出UIImagePickerController,需要通過PopOver調出