39

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

nutsmuggler
  • 1,707
  • 5
  • 21
  • 27

4 Answers4

35

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
  • 32,196
  • 6
  • 66
  • 89
  • 17
    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. – Lily Ballard Jan 10 '09 at 12:15
  • 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 Jan 11 '09 at 03:54
  • you never know which app Apple might reject and why! Why, they let some big companies to use private APIs too! – lostInTransit Jan 11 '09 at 07:44
  • 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 Jan 12 '09 at 18:59
  • Any other way to achieve it without using the private APIs? – Raj Pawan Gumdal May 12 '10 at 05:42
  • 2
    I had this on my Apps, and AppStore approve it to be on Sale. may be this is not the private API. :-) – Jirapong Jun 17 '10 at 03:27
  • 1
    Worth noting nothing is private but the string `@"suckEffect"`. I'm not sure if specifying undocumented strings can be considered private API use. Certainly I wouldn't personally expect the private API detector tool Apple use to detect this. – mxcl Dec 03 '10 at 11:41
  • 4
    this is really cool animation. i want to ask how did you know about undocumented features of iphone sdk...... – Nirmit Patel Jan 18 '11 at 10:37
12

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
  • 510,854
  • 105
  • 1,084
  • 1,005
10

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
  • 170,088
  • 45
  • 397
  • 571
  • 1
    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 Jan 10 '09 at 10:22
  • 4
    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 Jan 11 '09 at 13:50
  • 1
    That is true (maybe a very late response) .. most apps end up in the store one way or the other. – Jake Jul 03 '09 at 08:11
5

I'm not sure if this is an answer but here is lib that do "genie effect" so it's quite similar to what you want achieve.

CGRect endRect = CGRectMake(30, 40, 50, 60);
[view genieInTransitionWithDuration:0.7 
                    destinationRect:endRect 
                    destinationEdge:BCRectEdgeTop 
                         completion:^{
                            NSLog(@"I'm done!");
                          }];

Genie IN

janisz
  • 6,292
  • 4
  • 37
  • 70