Tim*_*Tim 1 objective-c autorotate ios ios6
直接参考这个问题:
如何在iphone中以横向模式停止ABPersonViewController和ABNewPersonViewController的旋转
当我不是推动视图控制器的人时,如何阻止此屏幕在iOS 6中旋转?方案是我创建一个新联系人,然后用户按下"创建新联系人"或"添加到现有联系人"按钮.生成的屏幕是ABNewPersonViewController,但因为我没有直接访问旋转方法,我无法阻止它旋转.
截图:

上面的图片是从子类中获取的ABUnknownPersonViewController,在这个子类中,我实现的唯一功能是覆盖旋转方法,如下所示:
- (BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
Run Code Online (Sandbox Code Playgroud)
然而,问题是,当我ABNewPersonViewController按下上面图像中的一个按钮以覆盖iOS 6上的旋转时,我无法继承按下的屏幕.有关如何合法地访问这些按钮的任何想法或覆盖旋转在屏幕上被推,以防止它这样做?
更新1:
我试图创建一个类别,ABNewPersonViewController并ABUnknownPersonViewController覆盖旋转方法(不太理想,我知道),然后全局导入,但这不起作用.除此之外,我完全不知道如何覆盖这种行为.有什么建议?
更新2:
是否有可能获得对该按钮的引用UITableView并覆盖它们调用的方法?或者通过访问私有API违反Apple条款?到目前为止试图调查这种方法,并没有真正到达任何地方.
在iOS 6上,旋转处理已更改.有两种方法可以防止旋转:
您可以覆盖应用程序委托中的方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
当方向更改或按下新视图控制器时,在您的代理上调用该方法,您甚至可以使用它暂时禁用横向显示:
// In AppDelegate.h:
@property (nonatomic) BOOL portraitOnly;
// In AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return _portraitOnly ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskAllButUpsideDown;
}
// to switch to portrait only:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = YES;
// to switch back to allowing landscape orientations as well:
((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = NO;
Run Code Online (Sandbox Code Playgroud)这两种方法都完全可以接受App Store提交,因为这些方法仅使用已发布和记录的行为.