开发者

Frame according to interface orientation

开发者 https://www.devze.com 2023-01-29 20:23 出处:网络
I have a UITextField in a UIAlertView. When the o开发者_StackOverflow中文版rientation changes, I want to update the UITextField\'s frame because it would otherwise overlap the UIAlertView\'s buttons.

I have a UITextField in a UIAlertView. When the o开发者_StackOverflow中文版rientation 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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号