閑話不多說先上效果圖
這里面用的present?頁面切換
1.先在AppDelegate中重寫-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window方法,交代進入的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.創建一個BaseNavi,就是上一步用到的。方法寫上
- (BOOL)shouldAutorotate
{
return[self.topViewControllershouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return[self.topViewControllersupportedInterfaceOrientations];
}
3.在第一個頁面寫上,支持旋轉 但是這個頁面只支持豎屏,代碼:
//支持旋轉
-(BOOL)shouldAutorotate{
returnYES;
}
//支持的方向因為界面A我們只需要支持豎屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskPortrait;
}
4.第二個頁面我們寫上,我們所需要的橫屏效果,代碼:
//支持旋轉
-(BOOL)shouldAutorotate{
returnYES;
}
//
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
returnUIInterfaceOrientationMaskLandscapeLeft;
}
//一開始的方向很重要
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
returnUIInterfaceOrientationLandscapeLeft;
}
以上就是橫屏設置了,代碼不到位的,請多包涵。