问题
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