在AppDelegate.h裡面添加@property(nonatomic,assign)NSInteger allowRotation;
在AppDelegate.m文件裡面添加
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (_allowRotation == 1) {
return UIInterfaceOrientationMaskLandscapeRight;
}
else
{
return (UIInterfaceOrientationMaskPortrait);
}
}
這樣默認所以的頁面就是豎屏的,在要強制橫屏的頁面的控制器UIViewController裡面,引入#import “AppDelegate.h”
然後
(void)viewDidLoad
{
[super viewDidLoad];
AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.allowRotation = 1;
}
就可以讓個別頁面單獨橫屏了,在跳出這個橫屏頁面前修改狀態,如下
AppDelegate *delegate = [[UIApplication sharedApplication]delegate]; delegate.allowRotation = 0;
這樣既可完整的實現頁面的橫屏。
以上所述是小編給大家介紹的iOS中將個別頁面強制橫屏其他頁面豎屏,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對本站網站的支持!