IOS7 UIActionSheet中的UIActionSheetDelegate与UIImagePickerController的协作
UIActionSheet中的UIActionSheetDelegate与UIImagePickerController的协作,实现图片来源的选择,代码如下:
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ UIImagePickerController *picker=[[UIImagePickerController alloc]init]; picker.delegate=self; picker.allowsEditing=YES; switch (buttonIndex){ case 0: { //拍照 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { picker.sourceType=UIImagePickerControllerSourceTypeCamera; } else { return; } } break; case 1: { //相册 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) { picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; } } break; case 2: { //图片库 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) { picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum; } } break; default:{ return; } break; } if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){ [self presentViewController:picker animated:YES completion:nil]; }else{ UIPopoverController * popOver = [[UIPopoverController alloc] initWithContentViewController: picker]; popOver.delegate = self; _popOverController = popOver; [_popOverController presentPopoverFromRect:CGRectMake(0,100, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } }
这里加了一个UIPopoverController,但是UIPopoverController只能在ipad设备上面使用。
记录下先,下次ipad开发的时候用的上哦。
版权声明
由 durban创作并维护的 Gowhich博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证。
本文首发于 博客( https://www.gowhich.com ),版权所有,侵权必究。
本文永久链接: https://www.gowhich.com/blog/533
版权声明
由 durban创作并维护的 Gowhich博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证。
本文首发于 Gowhich博客( https://www.gowhich.com ),版权所有,侵权必究。
本文永久链接: https://www.gowhich.com/blog/533