我使用以下代码来获取屏幕大小宽度:
CGFloat width = [UIScreen mainScreen].bounds.size.width - 100;
但它的纵向和横向宽度为“668.0”.
如何根据设备的方向获得不同的宽度.
解决方法
我遇到了和你一样的问题,我找到的就是检查方向并计算高度和宽度,如下所示:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; screenHeight = orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ? 748 : 1004; screenWidth = orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ? 1024 : 768;
这些尺寸适用于iPad显而易见,但它可以适用于尺寸合适的iPhone.
我个人觉得它有点差,但我找不到别的东西.