我试图在旋转设备时调整UIView中的对象,而不对硬编码宽度和高度进行硬编码.在这段代码中,我如何得到newWidth和newHeight?
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
child.frame = CGRectMake(10, 10, newWidth - 20, newHeight - 20);
}
Run Code Online (Sandbox Code Playgroud)
Kal*_*lle 10
这是正确的.
- (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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7345 次 |
| 最近记录: |