pJosh
pJosh

Reputation:

iphone: resizing the view when the device is rotated

I am trying to develop an application which is geo-sensitive. So, I have written -

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    // return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}

I have put different images on that screen and I have to resize it when the view is changing, So,what can I do?

Upvotes: 0

Views: 1206

Answers (3)

Aakil Ladhani
Aakil Ladhani

Reputation: 982

You can resize your view in - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration method for example:

  • (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {

    } else {

    }

}

Upvotes: 1

Ashish Chauhan
Ashish Chauhan

Reputation: 1376

imageViewObject.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | 
                                   UIViewAutoresizingFlexibleRightMargin | 
                                   UIViewAutoresizingFlexibleTopMargin | 
                                   UIViewAutoresizingFlexibleBottomMargin |
                                   UIViewAutoresizingFlexibleHeight |
                                   UIViewAutoresizingFlexibleWidth;

Upvotes: 1

hatfinch
hatfinch

Reputation: 3095

-shouldAutorotateToInterfaceOrientation: is a method on UIViewController which will cause its view to be resized when the orientation of the device changes.

You have two main approaches to resizing the subviews of that view:

1) You can set the autoresizingMask of that view's subviews so that they change size when their superview changes size. If you're adding the subviews using Interface Builder, you can set these masks visually from the Size panel.

2) You can override -layoutSubviews in that view and resize them manually in that method.

Upvotes: 1

Related Questions