I am trying to resize the objects in a UIView when the device is rotated without hard coding the width and height. In this code how would I get the newWidth and newHeight?
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    child.frame = CGRectMake(10, 10, newWidth - 20, newHeight - 20);
}
This would be about right.
- (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);
}
If possible, you're better either:
UIView and doing the layout you need inside -(void)layoutSubviews, or;autoresizingMask to automatically layout your views.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With