既存のライブラリから、またはカメラから新しい画像を取得するアプリがあります。
iPad では、[ライブラリから] ボタンを押すと、ポップオーバーが押されたボタンの上に (正しく) 表示されますが、カメラ ボタンから [写真を撮る] を押すと、カメラ コントローラーが [ライブラリから] ボタンの上に表示されます。ライブラリ」ボタンも...「写真を撮る」ボタンの上に表示するには、これが必要です。そうしないと、少し奇妙に見えます!
使用したコードは次のとおりです。
- (void)pickImageFromLibrary: (id)sender
{
[Flurry logEvent: @"PickImage"];
[self openImagePickerWithSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
}
- (void)takePicture: (id)sender
{
[Flurry logEvent: @"TakeImage"];
[self openImagePickerWithSourceType: UIImagePickerControllerSourceTypeCamera];
}
- (void)openImagePickerWithSourceType: (UIImagePickerControllerSourceType)sourceType
{
if ( ![UIImagePickerController isSourceTypeAvailable: sourceType] ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Error", @"" )
message: NSLocalizedString( @"We are sorry, but this functionality is not available at your device.", @"No camera eror" )
delegate: nil
cancelButtonTitle: NSLocalizedString( @"Dismiss", @"")
otherButtonTitles: nil];
[alert show];
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = sourceType;
self.isCameraShown = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:(UIViewController *)picker];
CGRect takePhotoRect;
takePhotoRect.origin = self.view.frame.origin;
takePhotoRect.size.width = 1;
takePhotoRect.size.height = 1;
[self.popover setPopoverContentSize:CGSizeMake(320.0, 216.0)];
[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else{
[self presentViewController:picker animated:YES completion:NULL ];
}
}