iOS9 popover始终指向锚点的左上角 [英] iOS9 popover always points to top-left corner of anchor
问题描述
我正在使用一个故事板segue,它将视图控制器显示为popover。 seque有一个自定义 UIView
作为其锚点。在iOS9之前,popover将正确指向自定义 UIView
的中心底部(在UIView下面显示)。在iOS9上,它指向 UIView
的左上角。
I'm using a storyboard segue that presents a view controller as popover. The seque has a custom UIView
as its anchor. On pre-iOS9 the popover would correctly point to the centre-bottom of the custom UIView
(presented below the UIView). On iOS9 it points to the top-left corner of the UIView
.
我确实尝试跟踪所有选择器调用到自定义 UIView
,找出我可能需要在我的自定义 UIView
中实现的任何内容,以提供'热点'为popover但找不到任何东西
I did try to trace all selector calls to the custom UIView
to find out if there is anything I may need to implement in my custom UIView
to provide the 'hotspot' for the popover but couldn't find anything
任何想法..?谢谢
感谢@Igor Camilo的回复 - 如果它对某些人有用,这就是我在我的代码中解决这个问题的方法:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIPopoverPresentationController* possiblePopOver = segue.destinationViewController.popoverPresentationController;
if (possiblePopOver != nil) {
//
// iOS9 -- ensure correct sourceRect
//
possiblePopOver.sourceRect = possiblePopOver.sourceView.bounds;
}
...
}
示例:'短'按钮触发弹出窗口,弹出窗口指向'排序'控件的左上角
Example: 'Short' button triggers a popover, the popover points to the top-left corner of 'Sort' control
推荐答案
我遇到了完全相同的问题。我刚刚通过在prepareForSegue中设置sourceRect来解决它:
I had the exact same problem. I just resolved it by setting sourceRect in prepareForSegue:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch segue.identifier {
case "Popover Identifier"?:
if #available(iOS 9.0, *) {
segue.destinationViewController?.popoverPresentationController?.sourceRect = anchorView.bounds
}
default:
break
}
}
这篇关于iOS9 popover始终指向锚点的左上角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!