B.S*_*.S. 21 objective-c uipopovercontroller autorotate ios uipopover
旋转后我无法在屏幕上保持弹出相同的位置.有没有什么好方法可以做到这一点,因为只是设置一些框架到弹出窗口旋转后工作很糟糕.popover.frame = CGRectMake(someFrame);旋转弹出后,只有当它位于屏幕的中心时才会看起来很好.
Max*_*eod 29
苹果就此问题进行了问答.你可以在这里找到详细信息:
基本上,该技术解释了在视图控制器的didRotateFromInterfaceOrientation方法中,您将再次呈现弹出,如下所示:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[aPopover presentPopoverFromRect:targetRect.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请阅读上面的文章,以及UIPopoverController类参考:
如果用户在弹出窗口可见时旋转设备,则弹出控制器会隐藏弹出窗口,然后在旋转结束时再次显示它.弹出控制器会尝试为您适当地定位弹出窗口,但在某些情况下您可能必须再次显示它或完全隐藏它.例如,当从条形按钮项目显示时,弹出控制器自动调整弹出框的位置(并且可能是大小)以考虑条形按钮项目的位置的改变.但是,如果在旋转期间删除了条形按钮项,或者在视图中显示了目标矩形的弹出框,则弹出控制器不会尝试重新定位弹出框.在这些情况下,您必须手动隐藏弹出框或从适当的新位置再次显示弹出框.您可以在用于显示弹出窗口的视图控制器的didRotateFromInterfaceOrientation:方法中执行此操作.
Joh*_*ker 16
从iOS 8.0.2开始,willRotateToInterfaceOrientation 将不会有任何影响.正如mhrrt所提到的,您需要使用委托方法:
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing *)view
因此,例如,如果您希望弹出窗口直接显示在按下的按钮下方,则可以使用以下代码:
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing *)view
{
CGRect rectInView = [self.theButton convertRect:self.theButton.frame toView:self.view];
*rect = CGRectMake(CGRectGetMidX(rectInView), CGRectGetMaxY(rectInView), 1, 1);
*view = self.view;
}
Run Code Online (Sandbox Code Playgroud)
您可以在didRotateFromInterfaceOrientation:用于显示弹出窗口的视图控制器的方法中执行此操作.
使用setPopoverContentSize:animated:方法设置弹出窗口的大小.
| 归档时间: |
|
| 查看次数: |
20983 次 |
| 最近记录: |