mysho
mysho

Reputation: 353

iPhone Fall Down button (Animation)

Is it possible do something like this ?

When I click on the button I need the following animation: button to set some alpha filter and starts to fall down as indicated by the arrow, it will disappear on tab.

Can you tell me how to do this ? Thanks a lot ...

Here is image url: http://img534.imageshack.us/img534/8149/screenqx.jpg

Upvotes: 0

Views: 480

Answers (2)

Owen Hartnett
Owen Hartnett

Reputation: 5935

You can't really move it from view to view, as your views could clip and then you'd get frames with only a partial image. Probably the best thing to do is to create a view on the fly which covers the whole screen, copy the button image into the view at the original point, remove the button from the original view, then animate that image to where you want it to go, then add the button to the final destination.

Upvotes: 0

Kevin Low
Kevin Low

Reputation: 2682

It's definitely possible, but there are some issues you have to overcome. One is that UIBarButtonItem isn't a UIView. One way is to loop through the subviews of the UIToolbar or UINavigationBar. Another way is to figure out the position of the button. Another is to get the view using private api if you're not submitting to the AppStore.

Once you have the view, you can move it to the superview of the UIToolbar or UINavigationBar or you can create a view on top of that (and hide the real UIBarButtonItem since you're done with that). The latter is more difficult because mimicking the look of the default bordered UIBarButtonItem isn't easy.

Now you need to get the center of the UITabBarItem somehow. You can either use private api or you can loop through the subviews.

Create a CGPath using Quartz functions or using UIBezierPath. The start point will be the center of the button and the end point will be the center of the UITabBarItem.

Create a CAKeyFrameAnimation and attach said CGPath.

Create a CABasicAnimation to animate the opacity.

Add both to a CAAnimationGroup.

Attach the animation group to your button view's CALayer.

Make sure to also set the position and the alpha in order to prevent the view from jumping back to its original position after the animation.

Once you attach the animation group, the animation should start, so make sure you're doing all of this in the button's selector method.

Upvotes: 1

Related Questions