2015-01-16 24 views
0

Bonjour,iOS项目在iPhone上工作,但不在模拟器中

我的iOS项目支持风景,并在我的iPhone 4s 7.1.2上完美运行,但在模拟器中没有。

这里是一些截图:

iPhone Landscape

Simulator Landscape

两个截图已经采取了横向模式和模拟器似乎并没有调整板正确

这里我使用的代码改变方向。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
    [UIView animateWithDuration:duration animations:^{ 

     [[UIApplication sharedApplication] setStatusBarHidden:YES]; 

     int width = [[UIScreen mainScreen] bounds].size.width - [[UIApplication sharedApplication] statusBarFrame].size.width - 10; 
     int height = width; 

     int x = 5; 
     int y = ([[UIScreen mainScreen] bounds].size.width/2) - (width/2); 

     [board setFrame:CGRectMake(x, y, width, height)]; 
    }]; 
} 
else { 
    [UIView animateWithDuration:duration animations:^{ 

     [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
     [board setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.width)]; 
    }]; 
} 

}

感谢您的帮助:)

+0

你有没有设置断点,看看有什么价值你得到? – AdamPro13

+0

据我所知,willAnimateRotationToInterfaceOrientation不能在模拟器上工作,因为它是由iPhone设备的加速度传感器触发的。显然,模拟器没有。 – skyline75489

+0

你可以在iOS模拟器 - >硬件 - >向左旋转/向右旋转 – user3650409

回答

0

我没试过你的代码,但我坚信你所看到的是由过时的API引起的。 Official documentation here得到更多细节,以及新的API,你想要做什么是viewWillTransitionToSize:withTransitionCoordinator:

还有一些计算器上其他一些类似这样的问题在谈论解决方案:willAnimateRotationToInterfaceOrientation not called on ios6/7

+0

You are right,willAnimateRotationToInterfaceOrientation:duration:is used in iOS 8 ... 我试过viewWillTransitionToSize:withTransitionCoordinator:它似乎可以在模拟器上正常工作。 非常感谢 – user3650409

+0

很高兴提供帮助。另外,感谢给我一个“答案”标记和1UP :) – kcome

相关问题