我正在使用一个故事板segue,它将视图控制器呈现为popover.seque有一个自定义UIView作为其锚点.在iOS9之前,popover会正确指向自定义的中心底部UIView(在UIView下面显示).在iOS9上,它指向的左上角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;
}
...
}
Run Code Online (Sandbox Code Playgroud)
示例: "短"按钮触发弹出窗口,弹出窗口指向"排序"控件的左上角
Igo*_*ilo 34
我有同样的问题.我刚刚通过在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
}
}
Run Code Online (Sandbox Code Playgroud)
Ala*_* T. 18
有同样的问题,但我的应用程序有多个弹出窗口,所以我为修复程序创建了一个集中的功能(但仍然必须在每个具有弹出窗口的视图控制器上使用它).
// 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 }
}
}
Run Code Online (Sandbox Code Playgroud)
这是Igor Camilo在Objective-C中的片段的一个例子.
- (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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
这是我的解决方案,里面prepareForSegue:
segue.destinationViewController.popoverPresentationController?.sourceRect = CGRectMake(anchorView.frame.size.width/2, anchorView.frame.size.height, 0, 0)
Run Code Online (Sandbox Code Playgroud)
这会将指针移动到锚点视图的底部中间
| 归档时间: |
|
| 查看次数: |
15800 次 |
| 最近记录: |