iphone - 在 willRotateToInterfaceOrientation 中获取正确的框架

标签 iphone layout rotation orientation autoresize

我的 subview 在纵向和横向时具有不同的布局。 布局基于 super View 的框架,并且并不简单(无法使用自动调整大小的 Spring 和支柱来实现)。

问题是,如果我在 willRotateToInterfaceOrientation 期间更改 subview 的框架,动画是正确的,但 super View 的框架仍然是旧方向的框架。

如果我在 didRotateFromInterfaceOrientation 期间更改 subview ,则 super View 的框架确实是正确的,但框架更改仅发生在旋转动画之后,而且看起来不太好。

改变方向时改变 subview 框架的正确方法是什么?

最佳答案

此函数可以满足您的需要,因为 View 框架已因旋转而发生变化,并且不会停止自定义动画。

-(void)willAnimateRotationToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    float width = UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ? [[UIScreen mainScreen] applicationFrame].size.width : [[UIScreen mainScreen] applicationFrame].size.height;
//do something with the width now
//or you can get the height the same way
}

关于iphone - 在 willRotateToInterfaceOrientation 中获取正确的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7377171/

相关文章:

iphone - 打开通过 fbconnect 使用 sharekit 的 IOS 应用程序和/或来自 facebook 应用程序或 facebook 网站的 sharekit

ios - 如何获取 iPhone 的 UDID?

html - 将 HTML 页面分成水平部分,没有垂直滚动条

android - 测量 TextInputLayout 错误容器的高度

iphone - NS调用: object does not implement methodSignatureForSelector

iphone - Objective C 回调和通知

Android、Layout clicklistener和subview点击通过问题

opencv - 正确的空间相机方向

rotation - iOS 11 如何防止旋转?

ios - 旋转时多次调用方法 collectionview(cellForItemAtIndexPath)