我试图在方向更改后获得UIView
的大小。在我的视图控制器中,我实现didRotateFromInterfaceOrientation:
并在我的视图中调用setNeedsLayout:
。在我的视图的layoutSubviews
方法中,它尝试根据旋转后的新帧大小执行一些逻辑,但帧大小尚未更新以反映新方向(例如,在移动到之后它仍然是768x1024而不是1024x768景观)。
如何获取更新的帧大小?
答案 0 :(得分:3)
回答路易斯·奥斯卡所说的话,以便问题出现回答。 解决方案是访问“bounds”属性而不是“frame”。
答案 1 :(得分:2)
请尝试此方法。此方法将在轮换时自动调用。希望这可以帮助您。感谢。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
} else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}
}