在ios6/7上未调用WillAnimateRotationInterfaceOrientation
我有一个旧的应用程序,它仍然存在于iTunes上,是用iOS 5编写的。我想将其更新为在ios 6和ios 7上运行。到目前为止,一切都很好,我已经更新了我的代码以使用ARC。然而,当我试图保持同样的自转哲学时,我总是碰壁。我已经检查了中的相关主题,例如: , 根据一个类似的主题,我发现: 这让我做了以下几点: 我在AppDelegate中设置了rootViewController,如下所示:在ios6/7上未调用WillAnimateRotationInterfaceOrientation,ios,iphone,objective-c,uiviewcontroller,autorotate,Ios,Iphone,Objective C,Uiviewcontroller,Autorotate,我有一个旧的应用程序,它仍然存在于iTunes上,是用iOS 5编写的。我想将其更新为在ios 6和ios 7上运行。到目前为止,一切都很好,我已经更新了我的代码以使用ARC。然而,当我试图保持同样的自转哲学时,我总是碰壁。我已经检查了中的相关主题,例如: , 根据一个类似的主题,我发现: 这让我做了以下几点: 我在AppDelegate中设置了rootViewController,如下所示: self.preloadingViewController = [[PreloadingViewC
self.preloadingViewController = [[PreloadingViewController alloc] initWithNibName:@"PreloadingViewController" bundle:nil];
self.window.rootViewController = self.preloadingViewController;
我已提出:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
在我的AppDelegate中。我已在我的应用程序的所有UIViewController(包括上面提到的Preload ViewController)的SuperViewController(继承术语中的父级)中覆盖了shouldAutorotate
和supportedInterfaceOrientations
:
在每个子UIViewController中,我覆盖
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
使用代码以理想的方式为纵向和横向布局ui元素
最后,我的应用程序的plist文件
支持的界面方向
包含:
纵向(底部主按钮)、横向(左主按钮)、横向
(右主页按钮)
所有我想支持的方向
尽管如此,在我的rootViewController上,每次方向更改都会调用
支持的接口方向
和应该自动旋转
,WillAnimateRotationInterfaceOrientation
但永远不会调用。我甚至在我的SuperViewController中重写了shouldAutomaticallyForwardRotationMethods
,以返回YES,但没有结果
我做错了什么?有什么想法吗?我甚至认为旧的ios5风格的XIB会导致问题,但我认为情况并非如此
提前感谢。在iOS 6中,
将AnimateRotationInterfaceOrientation
的方式称为已更改
使用:
在根控制器中
编辑:
新干线
#import <UIKit/UIKit.h>
#import "yourAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yourAppDelegate class]));
}
}
#导入
#导入“yourAppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([yourAppDelegate类]);
}
}
在iOS 6中,将AnimateRotationInterfaceOrientation
的调用方式已更改
使用:
在根控制器中
编辑:
新干线
#import <UIKit/UIKit.h>
#import "yourAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yourAppDelegate class]));
}
}
#导入
#导入“yourAppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([yourAppDelegate类]);
}
}
若要实现此方法,请根据需要返回YES
-(BOOL)应该自动旋转指向器面方向:(UIInterfaceOrientation)到接口方向
要实现此方法,请根据需要返回YES
-(BOOL)应该自动旋转指针FaceOrientation:(UIInterfaceOrientation)到InterfaceOrientation
,因为只有我的rootViewController调用了它的应该自动旋转
和支持的InterfaceOrientations
方法,我决定每隔一个视图控制器注册一次,以获得任何UIDeviceOrientationIDChangeNotification
的通知
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
- (void)orientationChanged:(NSNotification *)notification
{
NSLog(@"Orientation changed!");
[self layoutForOrientation:[[UIDevice currentDevice] orientation]];
}
在我的layoutForOrientation:
方法中,我处理了uiview的控件方向
但是,尽管我通常会收到UIDeviceOrientationIDChangeNotification
通知,但我的视图方向实际上不会改变以匹配当前方向,即,如果新方向是说,UIInterfaceOrientationAndscapeRight
,视图方向将保持在ui界面方向纵向中,其子视图将旋转90度。这显然是不对的。在拔了很多头发后,我决定放弃这条路线
相反,我将rootViewController设置为UINavigationController,并让它将连续的UIViewController推到其上。由于我不希望导航栏在我的应用程序中可见,我已将导航控制器的navigationBarHidden
属性设置为YES。这样,将在当前位于navigationCotroller控制器堆栈顶部的每个UIViewController上调用方法WillAnimateRotationInterfaceOrientation
,其相应的视图和视图控件将正确旋转以获得所需的方向
这是因为大多数my view控制器支持的界面方向与掩码匹配:UIInterfaceOrientationMaskAllButUpsideDown
,这是iPhone的默认行为。如果我需要支持不同的方向,我必须对UINavigationController进行子类化,并覆盖支持的接口方向
和应自动旋转
,以支持导航堆栈的俯视图控制器所需的方向,根据苹果的示例项目:.由于我的rootViewController是唯一一个获得其shouldAutorotate
和支持的interfaceOrientations
调用方法的人,我决定每隔一个视图控制器注册一次,以获得任何UIDeviceOrientationIDChangeNotification
的通知
[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
- (void)orientationChanged:(NSNotification *)notification
{
NSLog(@"Orientation changed!");
[self layoutForOrientation:[[UIDevice currentDevice] orientation]];
}
在我的layoutForOrientation:
方法中,我处理了uiview的控件方向
但是,尽管我通常会收到UIDeviceOrientationIDChangeNotification
通知,但我的视图方向实际上不会改变以匹配当前方向,即,如果新方向是说,UIInterfaceOrientationAndscapeRight
,视图方向将保持在ui界面方向纵向中,其子视图将旋转90度。这显然是不对的。在拔了很多头发后,我决定放弃这条路线
相反,我将rootViewController设置为