[英]iOS project works on iPhone but not in simulator
你好,
我的iOS項目支持橫向環境,並且可以在iPhone 4s 7.1.2上完美運行,但不能在模擬器中運行。
這里有一些截圖:
這兩個屏幕截圖都是在橫向模式下拍攝的,模擬器似乎無法正確調整板子的大小
這是我用來更改方向的代碼。
- (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)];
}];
}
}
謝謝你的幫助 :)
我沒有嘗試過您的代碼,但是我堅信您看到的是過時的API引起的。 此處的官方文檔提供了詳細信息,而您所需的新API是viewWillTransitionToSize:withTransitionCoordinator:
在stackoverflow上還有其他一些問題,例如關於解決方案的討論: 在iOS6 / 7上未調用willAnimateRotationToInterfaceOrientation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.