先吐槽下簡(jiǎn)書(shū)鹃两,本來(lái)昨天在簡(jiǎn)書(shū)中搜索到的文章http://www.reibang.com/p/18115d353df9解決了問(wèn)題草添。今天在來(lái)看文章沒(méi)了溢吻, 作者也沒(méi)了,果元,促王,,我勒個(gè)大擦而晒。
此文章做個(gè)筆記蝇狼,防止再找不到了。
項(xiàng)目配置中倡怎,我使用的是Portrait
appdelegate.m中
#pragma mark - 支持了豎屏和home在右側(cè)的橫屏
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeRight;
}
再需要橫豎屏切換的頁(yè)面中
//#pragma mark - 以下3個(gè)方法橫豎屏的切換迅耘,在BaseNavigationController中指定了此頁(yè)面可以橫屏
- (BOOL)shouldAutorotate
{
return YES;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight |UIInterfaceOrientationMaskPortrait;
}
如果還不能實(shí)現(xiàn)橫豎屏切換,是TabbarController和NavigationController也需要配置
注意我用的是
nav.m中
#pragma mark - 以下3個(gè)方法橫豎屏的切換 是否自動(dòng)旋轉(zhuǎn),返回YES可以自動(dòng)旋轉(zhuǎn)
- (BOOL)shouldAutorotate
{
if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)])
{
return [self.topViewController shouldAutorotate];
}
return NO;
}
//返回支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
{
return [self.topViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
//這個(gè)是返回優(yōu)先方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)])
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationPortrait;
}
tabbar.m中
#pragma mark - 以下3個(gè)方法橫豎屏的切換 是否自動(dòng)旋轉(zhuǎn),返回YES可以自動(dòng)旋轉(zhuǎn)
- (BOOL)shouldAutorotate
{
BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
if ([nav isKindOfClass:[BaseNavigationController class]])
{
return [self.selectedViewController shouldAutorotate];
}
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
if ([nav isKindOfClass:[BaseNavigationController class]])
{
return [self.selectedViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
if ([nav isKindOfClass:[BaseNavigationController class]])
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationPortrait;
}