views:

4767

answers:

5

In my iPhone app, I have put a UIBarBUtton of type UIBarButtonSystemItemTrash in my UIToolBar. When pressed, I'd like to replicate the animation of Mail.app: the bin opens, the UIView folds and flies into it.
Is there a way to access this animation ithrough the iPhone SDK?

Presently I am using a custom made animation, but there are some limits; for example, I cannot animate the bin itself. Do you have any suggestion? Code samples?

Cheers,
Davide

+3  A: 

Unfortunately, I think this is going to need to be an entirely custom animation. The UIView folding can be approximated using Core Animation, perhaps by adding perspective to the CATransform3D of the UIView's underlying layer to distort the UIView into a trapezoid which gets sucked into the trash can.

As far as the trash can, you can create a UIBarButtonItem using initWithCustomView:, which might let you insert a custom UIView that has an animatable trashcan. It looks like the trash can has two elements, the can base and the lid, which are rotated independently to open and close the can. Draw PNGs for both, make UIImageViews for them, and make them subviews of the UIBarButtonItem custom view. For opening and closing, apply rotational transforms to them to animate the subviews.

Brad Larson
I was afraid I'd get this answer :)One thing I'm worried about is that replicating the Apple's apps beahviour too closely one might get his app rejected for accusation of using a private API. Also, I am not confortable grabbing Apple's own bin and retouching it, but maybe I'm just a scaredy cat.
nutsmuggler
You have nothing to fear if you are creating your own implementation from published interfaces. You might get an initial rejection, but they will listen to your response and end up approving it. Frankly, the reports about complete rejection are way overblown.
Brad Larson
That is true (maybe a very late response) .. most apps end up in the store one way or the other.
MiRAGe
+10  A: 

Use the suckEffect type on an animation. Also: spewEffect, genieEffect, unGenieEffect, twist, tubey, swirl, cameraIris, cameraIrisHollowClose, cameraIrisHollowOpen, rippleEffect, charminUltra, zoomyIn, and zoomyOut. Doesn't work in the simulator.

CATransition *animation = [CATransition animation];
animation.type = @"suckEffect";
animation.duration = 2.0f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
view.opacity = 1.0f;
[view.layer addAnimation:animation forKey:@"transitionViewAnimation"];

Note: Code snippet was pulled from a larger codebase. I hope it works :)

rpetrich
This is using private API. Don't be surprised if Apple rejects your app for including those effects, and especially don't be surprised if your app starts behaving strangely after an OS update. I strongly recommend you stay away from this.
Kevin Ballard
Yup, it's very much a private API and is completely unsupported. The fallback for unknown animation types is a fade effect though so it's safe to use for in-house or open toolchain development. App Store approval is a mixed bag regarding private APIs but I doubt they'd reject this usage.
rpetrich
you never know which app Apple might reject and why! Why, they let some big companies to use private APIs too!
lostInTransit
Thanks. I am probably going to stay on the safe side and implement my own animation, but this was surely the answer I was looking for.
nutsmuggler
Any other way to achieve it without using the private APIs?
Raj
I had this on my Apps, and AppStore approve it to be on Sale. may be this is not the private API. :-)
Jirapong
A: 

this is really cool animation. i want to ask how did you know about undocumented features of iphone sdk......

Nirmit Patel
+3  A: 

Just to add some info:

  1. You can use "suckEffect" with the standard +[UIView setAnimationTransition:forView:cache:]. Just pass the number 103 to the animationTransition variable. This won't avoid your app being rejected by Apple though :p
  2. "spewEffect", "genieEffect", "unGenieEffect", etc. no longer exist on iPhoneOS 3.x. The only undocumented transition left are "cube" (--), "rippleEffect" (110), the three "cameraIris" effects (105,106,107) and "suckEffect" (103).

See http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState for detail.

Also, to animate the bin (with private API): http://www.iphonedevwiki.net/index.php?title=UIToolbar#Animating_the_trash_can_icon.

KennyTM
Thanks, very nice suggestion!
nutsmuggler
A: 

Hi nutsmuggler

if am trying same animation i am not getting how to fold curve while moving ......
if possible tell how to do that

jeeva