閑話(huà)不多說(shuō)先上效果圖
這里面用的present?頁(yè)面切換
1.先在A(yíng)ppDelegate中重寫(xiě)-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window方法驱闷,交代進(jìn)入的BaseNavi扶檐,以及RootView。代碼如下
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Override point for customization after application launch.
self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
[self.windowsetBackgroundColor:[UIColorwhiteColor]];
UIStoryboard*storyBoard = [UIStoryboardstoryboardWithName:@"Main"bundle:[NSBundlemainBundle]];
ViewController*vc = [storyBoardinstantiateViewControllerWithIdentifier:@"ViewController"];
BaseViewController* nav = [[BaseViewControlleralloc]initWithRootViewController:vc];
[self.windowsetRootViewController:nav];
[self.windowmakeKeyAndVisible];
returnYES;
}
-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{
returnUIInterfaceOrientationMaskAll;
}
2.創(chuàng)建一個(gè)BaseNavi粹排,就是上一步用到的。方法寫(xiě)上
- (BOOL)shouldAutorotate
{
return[self.topViewControllershouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return[self.topViewControllersupportedInterfaceOrientations];
}
3.在第一個(gè)頁(yè)面寫(xiě)上涩澡,支持旋轉(zhuǎn) 但是這個(gè)頁(yè)面只支持豎屏顽耳,代碼:
//支持旋轉(zhuǎn)
-(BOOL)shouldAutorotate{
returnYES;
}
//支持的方向因?yàn)榻缑鍭我們只需要支持豎屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskPortrait;
}
4.第二個(gè)頁(yè)面我們寫(xiě)上,我們所需要的橫屏效果妙同,代碼:
//支持旋轉(zhuǎn)
-(BOOL)shouldAutorotate{
returnYES;
}
//
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskLandscapeLeft;
}
//一開(kāi)始的方向很重要
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
returnUIInterfaceOrientationLandscapeLeft;
}
以上就是橫屏設(shè)置了射富,代碼不到位的,請(qǐng)多包涵粥帚。