我有一个应用程序可以从现有库中获取图像,或者从相机中获取新图像。
在 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 ];
}
}