Changing leftBarButtonItem with flip transition?

2019-04-10 16:32发布

问题:

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.

回答1:

Hmm.. 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.

Hope this helps!

Nick.



回答2:

Take a look at the Elements sample. They are doing a flip in a toolbar there.