UIPopOverController issues while autorotation

青春壹個敷衍的年華 提交于 2019-12-08 11:48:12

问题


I am presenting a UIPopovercontroller using PresentPopOverFromRect: method. in Portrait Orientation. When i autorotate to Landscape UIPopoverController is not presenting at the proper position. How to position the UIPopoverController while autorotating the device.


回答1:


You need to override this function:

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

where you can change the dimension and position of the UIPopovercontroller depending of your current orientation. This function is convenient because it is called just before the screen is being redrawn and just before the user interface begins to rotate.

You should check this tutorial for an understanding of how you should handle the layout for different orientations of the IPad.




回答2:


Yes, as tiguero says, in your custom UIViewController, you can override the method:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [self.popOverViewController dismissPopoverAnimated:NO];
    CGRect yourNewRect = CGRectMake(0.0, 0.0, 20, 20);
    [self.popOverViewController presentPopoverFromRect:yourNewRect inView:yourView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

You can have a try!



来源:https://stackoverflow.com/questions/7512782/uipopovercontroller-issues-while-autorotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!