簡體   English   中英

iOS-方向更改時更改視圖

[英]iOS - Change view when orientation changes

我將iOS5與情節提要板一起使用,創建了兩個ViewController,一個用於縱向,一個用於橫向。我將兩個視圖與兩個“模態選擇”連接起來,這是我使用的代碼:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
    [self performSegueWithIdentifier: @"aaaa" sender: self];
}
else if (deviceOrientation == UIDeviceOrientationPortrait)
{
    [self performSegueWithIdentifier: @"ddd" sender: self];
}    

return true;

}

如果我從縱向更改為橫向,則可以使用,但是當返回縱向視圖時,它會崩潰並顯示為“沒有標識符為'ddd'的segue”,但它存在。

謝謝。

我解決了在視圖之間設置模式選擇的問題,然后使用以下代碼將其設置到實現文件中:

- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
   if(self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){

       [self performSegueWithIdentifier: @"aaaa" sender: self];

   } else  if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft || self.interfaceOrientation == UIDeviceOrientationLandscapeRight)
   {

       [self performSegueWithIdentifier: @"ddd" sender: self];
   }
}

ViewController的課程(縱向和橫向)。

暫無
暫無

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

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