[英]Differnet orientations for various view controllers?
所有應用程序都應以縱向顯示。 但是某些視圖控制器應處於橫向模式-我想允許用戶以“全屏模式”顯示圖形。
如何實現呢? 另一個困難是,當我按下視圖控制器並彈出它時,都需要在兩種情況下都設置方向。
如果您使用的是導航控制器,則如果您的應用程序處於縱向模式,則需要affine transform
viewController。對於全屏和旋轉,您可以使用
-(void)setRotationInLandscapeMode:(BOOL)status
{
if(status)
{
[[UIApplication sharedApplication] setStatusBarHidden:status];
self.navigationController.navigationBar.frame = CGRectOffset(self.navigationController.navigationBar.frame, 0.0, -20.0);
self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));
self.view.frame = CGRectMake(0,0, 320,568 );
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:status];
self.view.transform = CGAffineTransformMakeRotation((0));
self.view.frame = CGRectMake(0,0, 320,568 );
}
}
並更改viewWillAppear
的方向
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self setRotationInLandscapeMode:YES];
}
再次更改為人像viewWillDisappear
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];
}
如果您的viewController不在navigationController堆棧中,則也可以考慮supportedInterfaceOrientations
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
可以在XCode中的“目標”>“您的目標”>“常規”>“部署信息”>“設備方向”下配置此密鑰。
必須選擇“ 橫向左”和“ 橫向右” 。
AppDelegate中有一個代碼,該代碼針對屏幕上出現的每個視圖控制器進行調用。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
}
只需在PORTRAIT模式下在viewcontorllers中編寫此代碼
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
在只需要橫向模式的viewcontorllers中編寫此方法
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.