Search code examples
iosxcodeipaduitoolbar

UIToolbar on top and interfaceOrientation out of sync in rotations using iPad..bug?


Looking for confirmation or a correction on the following behaviour...

When problematically changing width of a fixed space uibarbuttonitem in UItoolbar via willAnimateRotationToInterfaceOrientation method, the display lags behind showing landscape when in portrait and vice versa after a few rotations. Like it goes one step out of sync.

As isolated test I:

  • Created new view based project in iPad
  • In IB designer added a uitoolbar to top of view
  • and the following uibarbutton items to it:

    left button|--Fixed space--|middle button<--flexible space-->right button
    
  • Assign UIBarButtonItemFixedSpace as IBOutlet to "|--Fixed space--|" button

  • Add following method to *.m

    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { 
        if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            UIBarButtonItemFixedSpace.width = 100;
        }else{
            UIBarButtonItemFixedSpace.width = 500;   
        }
    } 
    

Even thought the if statement does fire correctly in respective orientation after a few 90 degree rotations, the display lags one 90 degree rotation behind. Seen in both simulator and iPad iOS 4.3 & Xcode 4

Am I missing something?


Solution

  • Although this does look like a bug, I have moved away from bar buttons and gone with popovers instead...in other words a re-think and re-design in the UI.