iOS9popup窗口总是指向锚点的左上angular
我正在使用一个呈现视图控制器作为popup窗口的故事板segue。 seque有一个自定义的UIView
作为它的锚点。 在iOS9之前,popup窗口将正确地指向自定义UIView
的中心底部(在UIView
下面呈现)。 在iOS9上,它指向UIView
左上angular。
我试图跟踪所有的select器调用到自定义UIView
以找出是否有任何我可能需要在我的自定义UIView
实现为UIView
提供'热点',但找不到任何东西
有任何想法吗..? 谢谢
感谢@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; } ... }
示例: “短”button触发popup窗口,popup窗口指向“sorting”控件的左上angular
我有同样的问题。 我刚刚通过在prepareForSegue中设置sourceRect来解决它:
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 } }
有同样的问题,但我的应用程序有很多popup窗口,所以我创build了一个集中function的修复(但仍然必须在每个视图控制器使用它popup)。
// Fix for IOS 9 pop-over arrow anchor bug // --------------------------------------- // - IOS9 points pop-over arrows on the top left corner of the anchor view // - It seems that the popover controller's sourceRect is not being set // so, if it is empty CGRect(0,0,0,0), we simply set it to the source view's bounds // which produces the same result as the IOS8 behaviour. // - This method is to be called in the prepareForSegue method override of all // view controllers that use a PopOver segue // // example use: // // override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) // { // fixIOS9PopOverAnchor(segue) // } // extension UIViewController { func fixIOS9PopOverAnchor(segue:UIStoryboardSegue?) { guard #available(iOS 9.0, *) else { return } if let popOver = segue?.destinationViewController.popoverPresentationController, let anchor = popOver.sourceView where popOver.sourceRect == CGRect() && segue!.sourceViewController === self { popOver.sourceRect = anchor.bounds } } }
下面是Objective-C中Igor Camilo片段的一个例子。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // If the sender is a UIView, we might have to correct the sourceRect of // a potential popover being presented due to an iOS 9 bug. See: // https://openradar.appspot.com/22095792 and http://stackoverflow.com/a/32698841/368674 if ([sender isKindOfClass:UIView.class]) { // Fetch the destination view controller UIViewController *destinationViewController = [segue destinationViewController]; // If there is indeed a UIPopoverPresentationController involved if ([destinationViewController respondsToSelector:@selector(popoverPresentationController)]) { // Fetch the popover presentation controller UIPopoverPresentationController *popoverPresentationController = destinationViewController.popoverPresentationController; // Set the correct sourceRect given the sender's bounds popoverPresentationController.sourceRect = ((UIView *)sender).bounds; } } }
这是我的解决scheme,在prepareForSegue
:
segue.destinationViewController.popoverPresentationController?.sourceRect = CGRectMake(anchorView.frame.size.width/2, anchorView.frame.size.height, 0, 0)
这将把指针移动到锚点视图的底部中间
我也遇到了这个问题,但现在,当我将它添加到我的PrepareForSegue函数时,它的工作原理。 鉴于我的Segue ID包含stringPopover
if ([[segue identifier] containsString:@"Popover"]) { [segue destinationViewController].popoverPresentationController.sourceRect = self.navigationItem.titleView.bounds; }
如果您在主UIViewController
引用了popup窗口UIViewController
,则可以调整sourceRect
属性来抵消popup窗口。 例如,给定popoverVC
你可以这样做:
float xOffset = 10.0; float yOffset = 5.0; popoverVC.popoverPresentationController.sourceRect = CGMakeRect(xOffset, yOffset, 0.0, 0.0);