gpt4 book ai didi

iphone - 从 willAnimateRotationToInterfaceOrientation 如何获取旋转后 View 的大小?

转载 作者:行者123 更新时间:2023-12-03 18:43:02 25 4
gpt4 key购买 nike

我试图在设备旋转时调整 UIView 中对象的大小,而不对宽度和高度进行硬编码。在此代码中,我如何获得 newWidthnewHeight

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
child.frame = CGRectMake(10, 10, newWidth - 20, newHeight - 20);
}

最佳答案

这大概是正确的。

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
// we grab the screen frame first off; these are always
// in portrait mode
CGRect bounds = [[UIScreen mainScreen] applicationFrame];
CGSize size = bounds.size;

// let's figure out if width/height must be swapped
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
// we're going to landscape, which means we gotta swap them
size.width = bounds.size.height;
size.height = bounds.size.width;
}
// size is now the width and height that we will have after the rotation
NSLog(@"size: w:%f h:%f", size.width, size.height);
}

关于iphone - 从 willAnimateRotationToInterfaceOrientation 如何获取旋转后 View 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2315177/

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