Adi*_*ane 7 iphone xcode objective-c ios ios6
对于我的应用程序rootViewController是navgationController.
我发现推控制器了
-(BOOL)shouldAutorotate 没有被召唤.
和
-(NSUInteger)supportedInterfaceOrientations 只召唤一次.
我已经在xcode's项目摘要(或plist)中正确检查了Windows所有方向支持.
我希望这些方法被调用,因为有一些uicontrol定位代码,我想以编程方式执行方向更改.
我通过覆盖(类别)导航控制器的以下方法解决了这个问题
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
Run Code Online (Sandbox Code Playgroud)
我检查了哪个控制器被推送,因此在导航控制器的以下方法中调用了相应的推控制器的uicontrol定位代码
(NSUInteger)supportedInterfaceOrientations;
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我不认为这是正确的方法.请帮助我寻求更好的解决方案.
Shr*_*arg 27
您可以查看以下链接,您需要创建自定义导航以支持自动旋转
http://mobileappdevpage.blogspot.in/2012/11/how-to-use-should-autorotateios-6-with.html
另一种方法是通过创建UINaviagationController类来实现
.h文件的代码是
@interface UINavigationController (autorotation)
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
Run Code Online (Sandbox Code Playgroud)
和.m文件的代码是
@implementation UINavigationController (autorotation)
-(BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
[self.topViewController shouldAutorotate];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
@end
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式检查接口方向
[UIApplication sharedApplication].statusBarOrientation
Run Code Online (Sandbox Code Playgroud)
当视图控制器加载时,例如,在viewWillAppear. 在那里您可以进行子视图的布局。一旦视图启动,shouldAutorotate每当设备转动时都会被调用。