相关疑难解决方法(0)

[UIScreen mainScreen] .bounds.size在iOS8中是否依赖于方向?

我在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中的临时错误?

orientation uiinterfaceorientation ios uiscreen ios8

184
推荐指数
8
解决办法
8万
查看次数

IPhone/IPad:如何以编程方式获取屏幕宽度?

嗨,我想知道是否有办法以编程方式获得宽度.

我正在寻找足以容纳iphone 3gs,iphone 4,ipad的东西.此外,宽度应根据设备是纵向还是横向(对于ipad)而改变.

谁知道怎么做?我一直在寻找...谢谢!

iphone cocoa-touch objective-c ipad

81
推荐指数
3
解决办法
13万
查看次数

47
推荐指数
3
解决办法
7万
查看次数

在iPhone中重新定位后,"不正确"的框架/窗口大小

在我的iPhone OS应用程序中,我希望(需要)观察设备方向的变化,以便重新排列屏幕的某些部分.我使用的方法是用来CGRect frame = [UIScreen mainScreen].applicationFrame获取屏幕大小,并从那里计算其他控件的大小和/或位置(我也尝试过self.view.frame).

所有测试都是在Portrait模式下完成的,所以我可以专注于编写主要功能,然后再对Landscape进行一些调整.这里输入问题:-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation我在继续之前添加了一些日志来检查大小,但显然宽度和高度的值是"错误的"(我说"错误",因为乍一看这些值对我来说没有意义) .

这是一些日志记录的输出:

  • 旋转:横向[w = 300.000000,h = 480.000000]
  • 旋转:纵向[w = 320.000000,h = 460.000000]

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)

iphone frame uiview

38
推荐指数
3
解决办法
4万
查看次数

Iphone:获取当前视图尺寸或屏幕尺寸

您好我想获得主视图的宽度和高度.我想在横向或纵向模式下使用正确的值.我尝试过以下方法:


  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.其余像素发生了什么.我必须对这些值进行硬编码吗?谢谢.

iphone screen objective-c dimensions

34
推荐指数
3
解决办法
6万
查看次数

如何获得iOS设备屏幕的高度和宽度

可能重复:
IPhone/IPad:如何以编程方式获取屏幕宽度?
如何获得与方向相关的屏幕高度和宽度?

考虑到各种iOS设备和方向,获取当前屏幕分辨率的最简单方法是什么,包括高度和宽度?

objective-c ios uiscreen

20
推荐指数
2
解决办法
4万
查看次数

目标C - 如何获得当前的屏幕分辨率?

有没有办法让客户的屏幕分辨率与目标c?

谢谢.

解:

int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
Run Code Online (Sandbox Code Playgroud)

resolution screen objective-c screen-resolution

16
推荐指数
1
解决办法
1万
查看次数

为纵向和横向模式获得相同的屏幕宽度和高度

我用这段代码来获取屏幕宽度和屏幕高度,

    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 orientation uiinterfaceorientation ios

6
推荐指数
1
解决办法
5481
查看次数