user717452
user717452

Reputation: 111

Not Behaving As Expected When iPhone Rotated

My app has 3 buttons and 1 image view on each view. Due to the size of the buttons and images, along with navigation bar and tab bar controller, a resize was needed to make everything smaller in landscape mode. I put the following code in:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    viewofimage.frame = CGRectMake(130, 45, 220, 115);
    share.frame = CGRectMake(205, 161, 70, 70);
    invite.frame = CGRectMake(8, 161, 70, 70);
    contact.frame = CGRectMake(402, 161, 70, 70);
    invitation.frame = CGRectMake(3, 227, 81, 21);
    sharing.frame = CGRectMake(200, 227, 81, 21);
    contacting.frame = CGRectMake(397, 227, 81, 21);
}
else
{
    viewofimage.frame = CGRectMake(20, 64, 280, 206);
    invite.frame = CGRectMake(8, 285, 70, 70);
    share.frame = CGRectMake(125, 285, 70, 70);
    contact.frame = CGRectMake(242, 285, 70, 70);
    invitation.frame = CGRectMake(3, 358, 81, 21);
    sharing.frame = CGRectMake(120, 358, 81, 21);
    contacting.frame = CGRectMake(237, 358, 81, 21);
}

return YES; 
}

In simulator, this behaves perfect, imageview is resized and everything is visible. On devices, it merely shifts everything up and over to the right. Any thoughts on where the error is in code?

Upvotes: 1

Views: 131

Answers (1)

wattson12
wattson12

Reputation: 11174

Don;t hardcode values like this, you should be using autoresizing masks to handle resizing on events like rotations

one issue might be that shouldAutoRotate is cached and not called every time the device is rotated, maybe try moving this code to the will/did rotate methods

another is that this method would be called before any rotation happens, so your frames get changed, then the device is rotated, and any default autoresizing means that the frames arent what you would expect

Upvotes: 1

Related Questions