Frame according to interface orientation
-
08-10-2019 - |
سؤال
I have a UITextField in a UIAlertView. When the orientation changes, I want to update the UITextField's frame because it would otherwise overlap the UIAlertView's buttons. These are the frames:
portrait: CGRectMake(12.0, 45.0, 260.0, 26.0)
landscape: CGRectMake(12.0, 30.0, 260.0, 26.0)
How can I check if the device's orientation has changed without using the accelerometer directly?
Should it be in -[UIViewController shouldAutorotateToInterfaceOrientation:]
?
المحلول
Try this
if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight)
{
//Landscape Frame
}
if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait)
{
//Portrait Frame
}
لا تنتمي إلى StackOverflow