【问题标题】:UIPopover appearing from wrong buttonUIPopover 从错误的按钮出现
【发布时间】:2013-10-11 16:28:31
【问题描述】:

我有一个应用程序,它从现有库中获取图像,或者从相机中获取新图像。

在 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 ];
    }


}

【问题讨论】:

  • 您似乎在强制它始终使用fromLibrary 框架[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  • 旁注 - 不要在弹出窗口中显示相机。仅对照片库使用弹出框。

标签: ios objective-c ipad uipopovercontroller


【解决方案1】:

您正在展示来自openLibraryButton 的弹出框。

[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

您需要添加检查以查看是否按下了 take photochoose from library 按钮,然后显示该按钮的弹出框。

SUDO 代码:

if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
    [self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
    [self.popover presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

【讨论】:

  • 嗨 Bot,我将如何添加检查部分?你有我可以使用的例子吗?
  • @DaveBradford 你可以检查你传入的 sourceType
  • Bot - 完美运行,非常感谢!标记为已接受!
猜你喜欢
  • 2011-08-20
  • 2021-09-14
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-17
  • 1970-01-01
相关资源
最近更新 更多