2017-02-27 40 views
0

我在Xcode 8上運行,之前有一個按鈕,如下所示: w:任何h:任何,您可以更改界面,添加對象,你想在界面上顯示,那麼它只會出現,如果該界面被選中(即,不會出現在肖像,但會出現在景觀)。在Xcode 8中,沒有那個拉動網格的按鈕,但是有一個「Vary for Traits」按鈕,但它看起來並沒有以同樣的方式工作,任何人都沒有任何關於此主題的建議或幫助?如何將對象設置爲僅在某些界面上可見

謝謝

回答

0

您必須聆聽設備方向更改並相應地隱藏/顯示按鈕。

在viewDidLoad中添加此:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self configureYourButtonForOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

然後做你想做的當前狀態欄方向。請注意,您

- (void)orientationChanged:(NSNotification *)notification{ 
    [self configureYourButtonForOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 
} 

- (void)configureYourButtonForOrientation:(UIInterfaceOrientation)orientation{ 
    switch (orientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
      break; 

     case UIInterfaceOrientationPortrait: 
     case UIInterfaceOrientationPortraitUpsideDown: 
      break; 

     default: 
      break; 
    } 
} 
相關問題