不知道如果我的回答是,你在找什么,但我看到它的方式,你必须将视图控制器视图的中心设置为自定义视图的中心。这应该发生在每个方向。
具体而言,我们假设您有一个名为的自定义视图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