[英]Autorotation not working in iOS 7 , works fine in iOS 6
我有一個應用程序僅支持某些部分(照片庫,視頻等)的橫向方向,並且所有在iOS 6上運行正常沒有問題,但是,在iOS 7中應用程序崩潰。
所以繼承我的問題:
--> CRASH: **preferredInterfaceOrientationForPresentation must return a supported interface orientation!** 2013-11-06 10:18:06.220 ausopen-iphone-2014[57605:70b] Stack Trace: ( 0 CoreFoundation 0x03f665e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x03ce38b6 objc_exception_throw + 44 2 CoreFoundation 0x03f663bb +[NSException raise:format:] + 139 3 UIKit 0x01366f1c -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]
+ 580
其他信息:
在我的info.plist中,我支持肖像和風景
在我的AppDelegate中,我實現了以下方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{}
在這個方法中,我指定如果第一個視圖(HomeVC)顯示它應該支持所有方向。
在這個方法中,我還指定如果第二個視圖(PhotoVC)顯示它也應該支持所有方向。
在我的第一個視圖(HomeVC)中,我使用以下方法覆蓋此方法,以便在顯示視圖時僅支持縱向模式:
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
不確定iOS 7中有什么變化因為iOS 6中的一切都運行良好。似乎在iOS 7中,一旦彈出橫向視圖,應用程序就不會自動旋轉。
任何幫助,將不勝感激..
在IOS7中。如果你使用UINavigationController,旋轉處理方式是不同的!
看到UINavigationController,可以看到它是UIViewController的子類,那就是在他上面列出了上面處理方法的輪換; 所以我需要使用UINavigationController也做旋轉處理,
我的方法是添加一個類別到UINavigationController,這樣做。
在類別中。 M寫道
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
你可以簡單地使用它: -
-(void)rotateCameraView
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
}
//Mohit 18 Oct
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtaining the current device orientation
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
//Ignoring specific orientations
if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown) {
return;
}
if ((UIDeviceOrientationIsPortrait(orientation) ||UIDeviceOrientationIsPortrait(orientation)) ||
(UIDeviceOrientationIsLandscape(orientation) || UIDeviceOrientationIsLandscape(orientation))) {
//still saving the current orientation
currentOrientation = orientation;
}
[self performSelector:@selector(orientationChangedMethod) withObject:nil afterDelay:0];
}
//Mohit 18 Oct
-(void)orientationChangedMethod
{
switch (currentOrientation) {
case UIDeviceOrientationPortrait:
}
}
//Note here current orientation is a UIDeviceOrientation currentOrientation; global variable.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.