Question

I have 2 UIToolbar in one ViewControler.

I need to change their positin on rotating.

I add 2 outlets

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar1;
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar2;

Connect them in IB Now in viewcontroller.m i use this code

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        toolbar1.frame = CGRectMake(0, 0, 1024, 44);
        toolbar2.frame = CGRectMake(0, 374, 1024, 44);
    }
    else
    {
        toolbar1.frame = CGRectMake(0, 0, 768, 44);
        toolbar2.frame = CGRectMake(0, 502, 768, 44);
    }
}

Promblem is - nothing changes!

How can i fix it?

P.S. With webviews it works

enter image description here

enter image description here enter image description here

Was it helpful?

Solution

Make sure you Uncheck Autolayout in ViewController.xib, then this code always work. Change height to see different and comment out all setting in other method.

- (void)viewDidLayoutSubviews{
    if  (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
        toolbar1.frame = CGRectMake(0, 0, 1024, 20);
        toolbar2.frame = CGRectMake(0, 374, 1024, 20);
    } else {
        toolbar1.frame = CGRectMake(0, 0, 768, 44);
        toolbar2.frame = CGRectMake(0, 502, 768, 44);
    }
}

OTHER TIPS

I saw your code and I know what the problem is. You forgot to connect your elements in the Nib to the IBOutlets in your code.

enter image description here

After connecting the Outlets the example works. I tested it.

Hope this helps!

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top