好久沒有寫過簡書了呢,今天就來記錄一下項(xiàng)目中遇到的一個小問題:個別頁面只支持橫屏或是豎屏,其他頁面支持橫豎屏菲嘴。
參考博客:http://www.cnblogs.com/lear/p/5051818.html
我這邊是帶導(dǎo)航欄的,實(shí)現(xiàn)也挺簡單的,直接上代碼吧
創(chuàng)建導(dǎo)航欄的類目,并在.m文件實(shí)現(xiàn)下面的方法
//是否允許轉(zhuǎn)屏
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
//viewController所支持的全部旋轉(zhuǎn)方向
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
//viewController初始顯示的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
下面在需要只支持豎屏的頁面再重寫一遍上面的方法就行了赶舆,如下:
- (BOOL)shouldAutorotate{
//不允許轉(zhuǎn)屏
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//viewController所支持的全部旋轉(zhuǎn)方向
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//viewController初始顯示的方向
return UIInterfaceOrientationPortrait;
}
這樣的話就實(shí)現(xiàn)其余頁面支持橫豎屏,需要只支持豎屏的頁面只支持豎屏了祭饭,是不是很簡單芜茵!