문제

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

도움이 되었습니까?

해결책

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);
    }
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top