我在iOS 7和iOS 8中运行了以下代码:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(@"Currently landscape: %@, width: %.2f, height: %.2f",
(landscape ? @"Yes" : @"No"),
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height);
Run Code Online (Sandbox Code Playgroud)
以下是iOS 8的结果:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
Run Code Online (Sandbox Code Playgroud)
与iOS 7中的结果相比:
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
Run Code Online (Sandbox Code Playgroud)
是否有任何文件指定此更改?或者它是iOS 8 API中的临时错误?
嗨,我想知道是否有办法以编程方式获得宽度.
我正在寻找足以容纳iphone 3gs,iphone 4,ipad的东西.此外,宽度应根据设备是纵向还是横向(对于ipad)而改变.
谁知道怎么做?我一直在寻找...谢谢!
在我的iPhone OS应用程序中,我希望(需要)观察设备方向的变化,以便重新排列屏幕的某些部分.我使用的方法是用来CGRect frame = [UIScreen mainScreen].applicationFrame获取屏幕大小,并从那里计算其他控件的大小和/或位置(我也尝试过self.view.frame).
所有测试都是在Portrait模式下完成的,所以我可以专注于编写主要功能,然后再对Landscape进行一些调整.这里输入问题:-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation我在继续之前添加了一些日志来检查大小,但显然宽度和高度的值是"错误的"(我说"错误",因为乍一看这些值对我来说没有意义) .
这是一些日志记录的输出:
Landscape中"w"和"h"的值似乎与我相反 - 我期待w = 480和h = 300.
我究竟做错了什么?我用来调试的代码如下.
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGRect frame = [UIScreen mainScreen].applicationFrame;
CGSize size = frame.size;
NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]",
UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? "Portrait" : "Landscape",
size.width, size.height]);
}
Run Code Online (Sandbox Code Playgroud) 您好我想获得主视图的宽度和高度.我想在横向或纵向模式下使用正确的值.我尝试过以下方法:
NSLog(@"aaa %f", [UIScreen mainScreen].applicationFrame.size.width);
NSLog(@"zzz %f", self.view.frame.size.width);
Run Code Online (Sandbox Code Playgroud)
这些在横向模式下提供300,在纵向模式下提供320,是的在纵向模式下更大.所以..我的视图占据整个屏幕( - 状态栏)所以我希望横向模式为480,纵向模式为320.其余像素发生了什么.我必须对这些值进行硬编码吗?谢谢.
考虑到各种iOS设备和方向,获取当前屏幕分辨率的最简单方法是什么,包括高度和宽度?
有没有办法让客户的屏幕分辨率与目标c?
谢谢.
解:
int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
Run Code Online (Sandbox Code Playgroud) 我用这段代码来获取屏幕宽度和屏幕高度,
float scaleFactor = [[UIScreen mainScreen] scale];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat widthInPixel = screen.size.width * scaleFactor;
CGFloat heightInPixel = screen.size.height * scaleFactor;
NSLog(@"%f",widthInPixel);
NSLog(@"%f",heightInPixel);
Run Code Online (Sandbox Code Playgroud)
和
CGRect screenBounds = [[UIScreen mainScreen] bounds];
NSLog(@"screenBounds W %f",screenBounds.size.width);
NSLog(@"screenBounds H %f",screenBounds.size.height);
Run Code Online (Sandbox Code Playgroud)
但它在纵向和横向模式下显示相同的宽度= 768和高度= 1024.
objective-c ×5
ios ×4
iphone ×4
uiscreen ×3
cocoa-touch ×2
orientation ×2
screen ×2
dimensions ×1
frame ×1
ios8 ×1
ipad ×1
resolution ×1
uiview ×1