我正在开发一个应用程序,其中我有一个Navigation Controller
,其中少数ViewController
作为孩子。现在很少ViewController
我希望保持纵向模式的方向。如何我这样做?
修改
我创建了自定义视图控制器类PortraitViewController
&在PortraitViewController.m
@interface PortraitViewController ()
@end
@implementation PortraitViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//Here check class name and then return type of orientation
return UIInterfaceOrientationMaskPortrait;
}
@end
之后我实现了PortraitViewController.h
作为基类
#import <UIKit/UIKit.h>
#import "PortraitViewController.h"
@interface Login : PortraitViewController
@end
但是,如果将设备旋转到横向模式,仍然可以正常工作。
答案 0 :(得分:1)
创建自定义类&#34; PortraitViewController&#34;。并编写此代码。
@interface PortraitViewController ()
@end
@implementation PortraitViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//Here check class name and then return type of orientation
return UIInterfaceOrientationMaskPortrait;
}
@end
将此类指定为viewcontroller的基类,您可以为UINavigationController做同样的事情
答案 1 :(得分:0)
创建自定义NavController并将其作为超级类添加到视图控制器中。
#import "PotraitNAVController.h"
@interface PotraitNAVController ()
@end
@implementation PotraitNAVController
//implement this methods in your viewcontroller also, this will tell navigation controller to allow which type of rotation is allowed.
- (BOOL)shouldAutorotate
{
//Here check topviewcontroller and allow rotation to no if you want it in potrait
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
@end