0

I am using:

 if (UIInterfaceOrientationLandscapeLeft | 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);
}

to set buttons and labels in certain places when rotated. The only issue is that when I leave that view controller and go to a different controller, with the same code in place, it does not move the buttons and labels to defined CGRECTMAKE values. It only moves them when the selected viewcontroller is rotated. How can I get the other view controllers to detect what orientation it is in, and have it resized properly when getting to them?

user717452
  • 33
  • 14
  • 73
  • 149

2 Answers2

0

View Controller's have this method called every time it detects a rotation. I assume that's where you currently have this code

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == 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);
    }
}

-=-=-=-=-=-=-=-=-

If you want to detect orientation and place objects accordingly when moving to a different viewController...Then you can detect for what orientation you're in like this:

-(void)viewWillAppear:(BOOL)animated
{
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == 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);
    }
}

-=-=-=-=-=-=-=-=-

For further reference:

How to programmatically determine iPhone interface orientation?

Community
  • 1
  • 1
Highrule
  • 1,915
  • 3
  • 19
  • 23
0

Set UIView's autoMaskSubView to false Using this method:

 - (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; 
}
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • This is working, but I ran into an issue. Each tab is a navigation controller and I set the Navigation Bar to hidden. Some of the buttons push a table view with its own xib that needs to have the navigation bar present, so when those appear, I unhide the navigation bar. This causes the UIButtons to slide down the height of the navigation bar, but not the ImageView. Any ideas on how to keep that from happening? – user717452 Jun 12 '12 at 17:38