不知道如果我的回答是,你在找什麼,但我看到它的方式,你必須將視圖控制器視圖的中心設置爲自定義視圖的中心。這應該發生在每個方向。
具體而言,我們假設您有一個名爲的自定義視圖testView。
最初創建時你寫:
self.testView.center = self.view.center;
,在這兩個的iOS 8和以前的版本的作品是觀察的UIDeviceOrientationDidChangeNotification通知,當設備的方向得到改變通知的實用方法。然後,您可以再次設置自定義視圖的中心,如上所示。
例如,在viewDidLoad方法讓你的類遵守了上述通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOrientationChangeWithNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
接下來,聲明無論是私下或公開的handleOrientationChangeWithNotification:方法:
@interface ViewController()
-(void)handleOrientationChangeWithNotification:(NSNotification *)notification;
@end
最後,實現它如下:
-(void)handleOrientationChangeWithNotification:(NSNotification *)notification{
self.testView.center = self.view.center;
}
現在,每次臨時如果方向改變,自定義視圖將定位到屏幕的中心。
希望能幫到你。
使用AutoLayout。 – Fogmeister 2014-12-03 10:48:12
使用自動佈局。 – Andy 2014-12-03 14:20:12