4

我试图UIView在方向改变后得到我的大小。在我的视图控制器中,我实现didRotateFromInterfaceOrientation:并调用setNeedsLayout:我的视图。在我的观点中layoutSubviews,它尝试根据其新的帧大小在旋转后执行一些逻辑,但帧大小尚未更新以反映新的方向(例如,在移动到横向后它仍然是 768x1024 而不是 1024x768)。

如何获得更新的帧大小?

4

2 回答 2

4

只是要回答路易斯奥斯卡所说的话,以便问题显示为已回答。解决方案是访问“边界”属性而不是“框架”。

于 2012-06-22T05:18:55.323 回答
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);
    }
}
于 2012-06-22T05:26:04.277 回答