我正在使用Xcode 5的资产目录,我想用我LaunchImage作为我家视图的背景图像(这是一种非常常见的做法,使得从'加载'到'加载'的过渡看起来很流畅).
我想在资产目录中使用相同的条目来节省空间,而不必在两个不同的图像集中复制图像.
但是,致电:
UIImage *image = [UIImage imageNamed:@"LaunchImage"]; //returns nil
Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式确定我的应用程序的当前高度和宽度.我用这个:
CGRect screenRect = [[UIScreen mainScreen] bounds];
Run Code Online (Sandbox Code Playgroud)
但无论设备是纵向还是横向,这都会产生320的宽度和480的高度.如何确定主屏幕的当前宽度和高度(即取决于设备方向)?
鉴于最新发布的iPhone 6 屏幕尺寸:
iPhone 6: 1334h * 750w @2x (in points: 667h * 375w)
iPhone 6+: 1920 * 1080 @3x (in points: 640h * 360w)
Run Code Online (Sandbox Code Playgroud)
我想知道是否有代码允许我检测用户设备的屏幕尺寸,以便我可以UIImages使用用户的设备相应地调整和调整尺寸和其他材料.
到目前为止,我一直在使用以下内容:
- (NSString *) platform{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
- (NSString *) platformString{
NSString *platform = [self platform];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G"; …Run Code Online (Sandbox Code Playgroud) 在iOS 8中,不推荐使用接口轮换方法.这包括:
willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation:willAnimateRotationToInterfaceOrientation:duration:替代方法包括:
willTransitionToTraitCollection:withTransitionCoordinator:viewWillTransitionToSize:withTransitionCoordinator:如果未实现新的旋转方法,并且使用iOS 8 SDK编译项目,则视图控制器将不会接收调用 - 不推荐的旋转方法.
我担心的是:使用iOS 7 SDK构建的AppStore中的应用程序会发生什么变化?是否仍会在iOS 8设备上调用已弃用的旋转方法?
编辑:
仍然会调用旋转方法,但iOS 8中存在一些更改/问题/错误.
因此,我使用最新版本的XCode创建了一个新项目,并尝试记录我的应用程序的屏幕大小(以确定UI的设备类型).我从iPhone 5运行了以下代码:
NSLog(@"%f", [[UIScreen mainScreen] bounds].size.height);
Run Code Online (Sandbox Code Playgroud)
这返回了480,这是旧iPhone系列的屏幕尺寸.我在模拟器中试过,发生了同样的事情.我必须在项目中启用一些属性来识别屏幕大小吗?
这仅适用于5个以上的设备; 如果我在iPad上运行游戏,它会识别1024屏幕尺寸.
我知道这个代码在过去有效.我使用完全相同的方法做了一段时间的游戏,它没有检测屏幕大小的问题,但这是在XCode 4.x中构建的.
我正在使用自定义视图控制器,我在App Delegate中创建了以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if([Global getDevice] == 1)
{
//iPhone 5+
self.window.rootViewController = [[FivePlus alloc] initWithNibName:nil bundle:nil];
}
else if([Global getDevice] == 2)
{
//iPhone 4S-
self.window.rootViewController = [[FourSMinus alloc] initWithNibName:nil bundle:nil];
}
else
{
//iPad
self.window.rootViewController = [[iPad alloc] initWithNibName:nil bundle:nil];
}
[[self window] makeKeyAndVisible];
// Override point for customization after application launch.
return …Run Code Online (Sandbox Code Playgroud) 在应用程序扩展中检测设备方向的最佳方法是什么?我在这里发现的解决方案的结果好坏参半:
我查看了大小类,UITraitCollection并发现设备不准确地报告它是纵向的,实际上是在横向(不确定这是OS错误,还是我没有正确查询正确的API).
完成的最佳方法是什么:
谢谢,
我创建了一个简单的模块,我将子视图添加到UIWindow.在模拟器ios 7(Xcode 5.1.1)中,我打印了self.windows,我得到:
<UIWindow: 0x8db1670; frame = (0 0; 768 1024); autoresize = W+H; gestureRecognizers = <NSArray: 0x8db1a70>; layer = <UIWindowLayer: 0x8db17d0>>
Run Code Online (Sandbox Code Playgroud)
但在ios8(Xcode 6 beta 6)上,我得到:
<UIWindow: 0x794320d0; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x79437a80>; layer = <UIWindowLayer: 0x7943c400>>
Run Code Online (Sandbox Code Playgroud)
问题是:为什么帧属性存在差异?
这是一个简单的单视图控制器应用程序:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor greenColor];
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
Run Code Online (Sandbox Code Playgroud)
iOS 8中的输出是如此不同.


这与iOS 8与iOS 7的UIWindow界限有什么关系.我如何获得iOS 7的行为?
从iOS 8开始,我的App运行得非常好,但是在测试这个应用程序时我发现了一个问题.它只发生在iPad上,只有我在横向模式下启动应用程序.如果它在Portrait中启动,一切都是正确的(没有旋转问题).如果我旋转设备(模拟器或真实设备),视图将旋转出屏幕,只显示实际视图的剪切,其余为黑色.


其他人确实注意到这样的错误?我该如何解决?
我为部署目标> = 7.1创建应用程序.我看到了"bug"......应用程序只在横向模式下运行!
码:
CGSize frameSize = [[UIScreen mainScreen] bounds].size;
Run Code Online (Sandbox Code Playgroud)
在iOS 7(iPhone 4)中,返回CGSize (width=320, height=480),但必须返回480x320(因为在横向模式下运行应用程序).在iOS 8(iPhone 4S)中,返回CGSize (width=480, height=320)- 正确的结果.
iOS 7在没有检查横向/纵向模式的情况下返回帧的印象,以及纵向模式的返回尺寸.
谢谢.