I am porting an iPhone application on Mac OS X. This code has been used successfully on an iPhone:
- (void) moveTiles:(NSArray*)tilesToMove { [UIView beginAnimations:@"tileMovement" context:nil]; [UIView setAnimationDuration:0.1]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(tilesStoppedMoving:finished:context:)]; for( NSNumber* aNumber in tilesToMove ) { int tileNumber = [aNumber intValue]; UIView* aView = [self viewWithTag:tileNumber]; aView.frame = [self makeRectForTile:tileNumber]; } [UIView commitAnimations]; }
The Mac version uses CATransaction to group animations, for example:
- (void) moveTiles:(NSArray*)tilesToMove { [CATransaction begin]; [CATransaction setAnimationDuration:0.1]; [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [CATransaction setCompletionBlock:^{ [gameDelegate tilesMoved]; }]; for( NSNumber* aNumber in tilesToMove ) { int tileNumber = [aNumber intValue]; NSView* aView = [self viewWithTag:tileNumber]; [[aView animator] setFrame:[self makeRectForTile:tileNumber]]; } [CATransaction commit]; }
The animation is excellent, except that the duration is 1.0 seconds. I can change setAnimationDuration: to call something or completely lower it, and the animation lasts 1.0 seconds. I also don't think that setAnimationTimingFunction: call does anything. However, setCompletionBlock: works because this block is executed when the animation completes.
What am I doing wrong here?
source share