在项目的时候需要个别页面旋转,之前在禁止屏幕旋转的时候使用的三个办法是
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
但是!后来在使用一些第三方框架的时候这个方法就没那么好用的
现在给大家介绍一种不一样的方法
@property(nonatomic,assign)BOOL allowRotation;
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
在appdelegate加上面的方法,在需要的地方写上下面这句话就OK~了AppDelegate *app= (AppDelegate *)[UIApplication sharedApplication].delegate;
[app setAllowRotation:YES];
不需要旋转就赋值NO