Search code examples
iphonetransition

Changing leftBarButtonItem with flip transition?


In my code I programmatically change leftBarButtonItem with a UIButton to a UIActivityIndicatorView, I would like to know how to perform a flip transition when changing, any idea ?

Thanks a lot.


Solution

  • I have a feeling that to do a flip transition, you need to have a UIView.

    So.. you could make a custom barButtonItem and add to it a flipView:

    UIView *flipView = [[UIView alloc] init....];
    BarButtonItem *barbutton = [[BarButtonItem alloc] initWithCustomView:flipView];
    

    then add your original view to the flipView, this can contain whatever you like...

    [flipView addSubview:<original view>];
    

    Then to flip this into a UIActivityIndicatorView, I think you need to do something like this:

    [UIView beginAnimations:@"flip" context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:flipView cache:YES];
    
    [<original view> removeFromSuperView];
    [flipView addSubview:<activityIndicatorView>];
        
    [UIView commitAnimations];
    

    You'll probably have to keep a reference to your flipView somewhere so you can bring back a reference to it when you want to perform the flip.