如何在 iOS 中设置视图大小以匹配设备屏幕?
我有一个 UIView,我需要将其大小调整为屏幕高度的一半,它在纵向模式下工作正常,但如果我在横向模式下与 iPad 一起使用应用程序,UIView 总是会获得屏幕纵向尺寸,有什么想法如何获得尺寸发射时和方向改变后?
我尝试以下操作,但总是得到 protrait,其中宽度 = 768 且高度 = 1024
NSLog( @"bounds: %@", NSStringFromCGRect( [UIScreen mainScreen].bounds ) );
NSLog( @"frame: %@", NSStringFromCGRect( [UIScreen mainScreen].applicationFrame ) );
I have a UIView that I need to resize to half the height of the screen, it works fine in Portrait mode but if I lunch the app with the iPad in landscape the UIView always get the screen portrait size, any ideas how to get the size at launch and after change in orientation?
I try the following but always get protrait where width = 768 and height = 1024
NSLog( @"bounds: %@", NSStringFromCGRect( [UIScreen mainScreen].bounds ) );
NSLog( @"frame: %@", NSStringFromCGRect( [UIScreen mainScreen].applicationFrame ) );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将视图的属性
autoresizingMask
设置为UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleBottomMargin
。或者尝试用它的价值来放置。设置此值后,您的视图将在设备旋转后自动调整大小。
Try to set property
autoresizingMask
of your view toUIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin
.Or try to place with its value. After setting this value your view will automatically resize after device rotation.