我爲iOS 5和iOS 6製作了應用程序,出於某種原因,它僅在iOS 6設備上使用時才旋轉,在iPhone或iPad上使用,並且不會在使用iOS 5的設備上旋轉。我的應用程序是通用的。請幫我解決這個問題!謝謝應用程序只能在iOS 6中旋轉,而不能在iOS 5中使用
回答
iOS 5和iOS 6調用不同的方向和旋轉代表。在iOS 5中,執行:
shouldAutorotateToInterfaceOrientation:,這是iOS中棄用6
所以,在iOS 6中,確保你設定一個根視圖控制器,並執行:
shouldAutorotate :, supportedInterfaceOrientations並支持InterfaceInterfaceOrientationsForWindow:
我有一個類似的問題。您可以檢查這個問題的答案:
Rotation behaving differently on iOS6
總之,有自轉中的iOS 5和iOS 6,並處理PortraitUpsideDown方向完全工作,我不得不實現自定義的UINavigationController並將其分配給self.window.rootViewController
中的應用代理didFinishLaunchingWithOptions
方法。
shouldAutorotateToInterfaceOrientation在ios6中已棄用。
所以如果你wnat上運行兩個操作系統版本的應用程序,然後添加shouldAutorotateToInterfaceOrientation過如下
//for ios6
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft ||orientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
return NO;
}
//for ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//interfaceOrientation == UIInterfaceOrientationLandscapeRight;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
超越控制這兩個在所有的UIViewController子類方法......這會爲工作ios 6及更早版本
爲了支持ios5和ios6中的自動控制,我們需要在ios6的情況下提供回調。`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
,我們需要調用
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutoRotate{
return YES;
}
對於iOS5的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{ 回報((toInterfaceOrientation == UIInterfaceOrientationPortrait)||(toInt erfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); }
嗯...我沒有格式化這已經?不,這是另一個副本:所以請不要將完全相同的答案張貼在多個問題上:它不是很適合所有問題,或者問題是應該標記/關閉的重複問題。 – kleopatra
- 1. 在iOS 5中手動旋轉後應用程序凍結
- 2. ios 6應用程序正在旋轉,即使與shouldAutorotate:沒有
- 3. 應用程序日曆功能不再在ios 6中工作
- 4. 屏幕旋轉不適用於iOS 5但適用於iOS 6
- 5. 旋轉的iOS 6兼容的iOS 5
- 6. 應用程序崩潰iOS 5中,但不是在6
- 7. iOS 6旋轉,使用UIWebView中的MPMoviePlayerViewController
- 8. 在ios 5中禁用MKMapView(iOS 6)
- 9. PhoneGap的應用工程在iOS 6中,但沒有的iOS 5
- 10. 爲什麼自動旋轉發生在iOS 6而不是iOS 5?
- 11. 只能自動旋轉UITabBar中的一些選項卡? (iOS 5)
- 12. IOS模擬器未能安裝應用程序?在Xcode 5中
- 13. 在iOS 5的iPhone應用程序中實現聊天功能?
- 14. iOS 6的iPhone應用程序不工作在iPad的iOS中
- 15. 使ios 6應用程序與ios 5兼容
- 16. 不能在IOS應用程序中使用自定義字體
- 17. iOS相機在Safari瀏覽器中正常旋轉,但不能在Web應用程序模式下旋轉?
- 18. 在iOS中使用GOOGLE地圖,支持iOS 6和iOS 5
- 19. 應用程序在iOS 5中在iPad中崩潰,並在iOS 6和iOS 7中正常工作
- 20. iOS 6 iPhone 5應用程序不全屏在Phonegap構建?
- 21. IOS通用應用程序旋轉
- 22. iOS 5 MapKit,MKPlacemark,在iOS 5上運行iOS 4.3應用程序
- 23. 如何在iOS 6中實現旋轉?
- 24. iOS 6 - 在UINavigationController中強制旋轉UIViewController
- 25. 方向不在iOS 10中旋轉,但在iOS 11中旋轉
- 26. 代碼只能在cmd中使用,而不能在程序中使用
- 27. 在iOS 6上,PhoneGap 2.1 iPad應用程序不再自動旋轉
- 28. iOS 6旋轉:supportedInterfaceOrientations不起作用?
- 29. 是否有可能在phonegap ios應用程序中使用iframe
- 30. 如何在iOS應用程序中使用「打開...」功能?
請注意,此示例僅支持兩種狀態:「豎直」(縱向)和「倒置」(縱向豎起)。 – Gonen