我想要一个带有width=480and的 UIView height=640,位于我的主视图中间。
我希望在横向和纵向都发生这种情况,但是现在如果我将其设计为纵向,当我将设备转为横向时,我的 UIView 具有width=640和height=480.
我的 UIView 有什么解决方案可以在两种方向类型中保持其大小?
我想要一个带有width=480and的 UIView height=640,位于我的主视图中间。
我希望在横向和纵向都发生这种情况,但是现在如果我将其设计为纵向,当我将设备转为横向时,我的 UIView 具有width=640和height=480.
我的 UIView 有什么解决方案可以在两种方向类型中保持其大小?
您可以实现viewDidLayoutSubviews(in UIViewController) 或layoutSubviews(in UIView) 来重新定位视图。
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.myCustomView.bounds = CGRectMake(0, 0, 480, 640); // update size
self.myCustomView.center = self.view.center; // update center
}