gpt4 book ai didi

ios - 旋转后如何获取 super View 的框架?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:12 28 4
gpt4 key购买 nike

我想在旋转后获得 super View 的框架。在我的自定义 View 中,我收听 UIDeviceOrientationDidChangeNotification:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];

然后:

- (void)orientationDidChange:(NSNotification *)notification {
NSLog(@"superview: %@", [NSValue valueWithCGRect:self.superview.frame]);
}

但这是旋转前的帧。 super View 的框架还没有旋转。如果我在一些延迟后得到 superview 的框架,它是正确的。

旋转后获取 super View 框架的正确方法是什么?

最佳答案

有时你会在 superview 完成布局之前收到通知,基本上你可以使用通知设置一个标志,例如 BOOL didRotate; 然后在
- (void)layoutSubviews 方法(您在 View 中覆盖此方法),此方法将在旋转后立即调用并且父 View 已更改其框架。

关于ios - 旋转后如何获取 super View 的框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22149693/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com