簡體   English   中英

iphone:在導航時強制改變從縱向到橫向的方向

[英]iphone: Forcefully change orientation from portrait to landscape on navigation

我們有什么方法可以在導航時強制將應用方向從縱向更改為橫向?

我要求將控制器從A推到B.B應該是橫向的,但我的A控制器是縱向的。

在ViewController-B中,在viewDidLoad中添加以下代碼行:

  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

  float   angle = M_PI/2;  //rotate 180°, or 1 π radians
  self.view.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);

如果您使用導航控制器從A移動到B,此代碼工作正常。

我用過這個。

希望這會幫助你。

享受編碼:)

- (void)viewWillAppear:(BOOL)animated說:

    //this is to force the application to re-evaluate device orientation
    //comment the last lines and see
    //cannot use [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
    //as "setOrientation" is a private method, and we risk to be kicked out by Apple
    UIViewController *c = [[[UIViewController alloc]init] autorelease];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];

...但首先,在你的xib中,將視圖的方向設置為所需的方向

根據我在最后一個應用程序中的經驗,我嘗試做同樣的事情,我發現Stack溢出的答案告訴他們不要強行改變基於導航的應用程序中的方向。

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
else
    return YES;
}

此功能可讓您以所需的方向使用視圖控制器,在這種情況下,我將其設置為橫向,並禁止在縱向模式下旋轉。

您將面臨B視圖控制器首先在A視圖控制器上的方向上加載的問題。 所以我將應用程序的完整方向更改為橫向。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM