【问题标题】:UIImagePickerController in UIPopoverController - location not workingUIPopoverController 中的 UIImagePickerController - 位置不起作用
【发布时间】:2014-03-06 07:31:57
【问题描述】:

在我正在编写的 iPad 应用程序中,我在一个静态表格单元格中有一个按钮,该按钮在弹出框内启动一个图像选择器。

我希望弹出框的箭头指向启动弹出框的按钮。现在,当我点击按钮时,它没有。它会在屏幕上抛出弹出框(使用工作图像选择器),但箭头指向屏幕顶部或其他任何地方(无法确定它是否是随机的——见下文)。

包含按钮的静态单元格的表格视图已禁用其滚动,但位于滚动视图上。这会导致随机箭头位置吗?

这是我的代码:

// present image picker in a popover
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePicker.allowsEditing = NO;
_imagePicker.navigationBar.tintColor = [UIColor redColor];
_imagePicker.navigationBar.backgroundColor = [UIColor greenColor];
_popover = [[UIPopoverController alloc] initWithContentViewController:_imagePicker];
[_popover presentPopoverFromRect:self.theButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

谁能解释一下为什么箭头没有指向按钮的框架和/或如何解决它?

谢谢。

【问题讨论】:

    标签: uiimagepickercontroller uipopovercontroller


    【解决方案1】:

    该按钮可能不是self.view 的直接子视图。

    试试:

    [_popover presentPopoverFromRect:self.theButton.frame inView:self.theButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    

    【讨论】:

    • 哈!这正是问题所在!谢谢! (现在我必须弄清楚如果在弹出窗口打开时方向发生变化,如何让它重新定位。)
    • @Kent 旋转后,可以调用presentPopoverFromRect:...将其移动到正确的位置。
    • 有道理。谢谢!
    • 我知道如何检查旋转,但如何检查弹出框是否仍在屏幕上? if (_popover) 在第一次被调用后不起作用,即使它不再出现在屏幕上(可能是因为现在对象存在)。
    • 没关系。想通了:if ([_popover isPopoverVisible])
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 2018-10-05
    • 2014-01-28
    • 2013-08-05
    相关资源
    最近更新 更多