Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I do this iOS animation on OSX?

Tags:

I have a very simple animation in iOS that fades a view, resizes a container to fit another view, then fades that other view back in. It's quite easy to do and very straightforward.

I've been trying to do something pretty much exactly like this on OSX, but I haven't been able to figure out how to do it. The animation stuff on OSX feels so clunky and difficult compared to iOS.

Any help would be much appreciated!!

Thanks! :)

// Fade out viewOne, resize frame to fit viewTwo, fade in viewTwo [UIView animateWithDuration: 0.15         animations: ^{             [viewOne setAlpha:0.0];         }         completion: ^(BOOL finished) {             [UIView animateWithDuration: 0.2                     animations: ^{                         [self setFrame: [viewTwo frame]];                     }                     completion: ^(BOOL finished) {                         [viewTwo setAlpha: 0.0];                         [self addSubview: viewTwo];                         [UIView animateWithDuration: 0.15                                 animations: ^{                                     [viewTwo setAlpha:1.0];                                 }];                     }];          }]; 
like image 776
Tyler Avatar asked Oct 17 '11 03:10

Tyler


People also ask

What is iOS animation?

Animation is a critical part of your iOS user interfaces, giving apps the ability to draw user attention to particular areas. Using the right animation will not only improve user experience, but can also add a ton of fun and polish to your app.

Does Apple have animation software?

MotionSimply special effects. Motion is the powerful motion graphics tool that makes it easy to create cinematic 2D, 3D, and 360° titles, fluid transitions, and realistic effects in real time.


2 Answers

I've written a small class that uses blocks to accomplish essentially the same thing as above when using the animator proxy on OSX.

Please note, this class is not thread safe and hasn't undergone any specific or stressful tests.

//Interface @interface MZAnimator : NSObject{}  + (void)animateWithDuration:(NSTimeInterval)duration                    animation:(void (^)(void))animationBlock; + (void)animateWithDuration:(NSTimeInterval)duration                    animation:(void (^)(void))animationBlock                  completion:(void (^)(void))completionBlock; @end   //Implementation @interface MZAnimator () + (void)runEndBlock:(void (^)(void))completionBlock; @end  @implementation MZAnimator  + (void)animateWithDuration:(NSTimeInterval)duration                    animation:(void (^)(void))animationBlock {   [self animateWithDuration:duration animation:animationBlock completion:nil]; } + (void)animateWithDuration:(NSTimeInterval)duration                    animation:(void (^)(void))animationBlock                  completion:(void (^)(void))completionBlock {   [NSAnimationContext beginGrouping];   [[NSAnimationContext currentContext] setDuration:duration];   animationBlock();   [NSAnimationContext endGrouping];    if(completionBlock)   {     id completionBlockCopy = [[completionBlock copy] autorelease];     [self performSelector:@selector(runEndBlock:) withObject:completionBlockCopy afterDelay:duration];   } }  + (void)runEndBlock:(void (^)(void))completionBlock {   completionBlock(); } @end 
like image 187
Tyler Avatar answered Sep 20 '22 02:09

Tyler


You can use:

  [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {     [context setDuration:2.0];     //Animation code   } completionHandler:^{     //Completion Code     NSLog(@"Completed");   }]; 
like image 21
jcgamestoy Avatar answered Sep 18 '22 02:09

jcgamestoy