是你可以通過將波紋管的方法在你的appDelegate使特定的viewController作爲風景。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskAll;
}
再取一個布爾值屬性在你的appDelegate
@property (nonatomic) BOOL restrictRotation;
,然後在視圖控制器要改變方向創建的appDelegate共享實例,並允許限制來改變像波紋管方法
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
現在從您的視圖控制器調用此方法,並根據需要更改方向。
[self restrictRotation:NO];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
和最重要的事情是要改變方向爲縱向時,您的視圖會消失,否則所有其他的viewController也成爲一道風景模式。
-(void)viewWillDisappear:(BOOL)animated
{
NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
[self restrictRotation:YES];
}
我希望這會幫助你。