第一步
在 AppDelegate.h
里增加一個(gè)屬性
@property (nonatomic, assign) NSInteger allowRotation;
用來(lái)區(qū)分哪個(gè)界面可以橫屏
哪個(gè)界面不可以
第二步
在 AppDelegate.m
里增加一個(gè)方法
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.allowRotation==1)
{
return UIInterfaceOrientationMaskAll;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
第三步
在需要橫屏的界面調(diào)用以下代碼即可
AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.allowRotation = 1;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIDeviceOrientationLandscapeRight] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortraitUpsideDown] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
Demo地址:https://github.com/YouZhiZheShiJingCheng/revolve/tree/master