Basic animation in iOS
iOS animations need to import #import <QuartzCore / QuartzCore.h> framework
Trigger the animation by clicking on the screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch * touch = touches.anyObject; // get the touch object
CGPoint location = [touch locationInView:]; // Get a touch point at which the view
// panning animation to the specified point
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
[Anim setToValue: [NSValue valueWithCGPoint: point]]; // do not set because the default is the current value fromValue
When // 2) animation length
[anim setDuration: 1.0f];
[Anim setDelegate: self]; // listen for start and end of the animation
[Anim setRemovedOnCompletion: NO]; // Set view of the holding state animation
// forwards is gradually approaching the target point
[anim setFillMode: kCAFillModeForwards];
// Set the location to be modified
[anim setValue:[NSValue valueWithCGPoint:point] forKey:@"targetPoint"];
[anim setValue:@"translationTo" forKey:@"animationType"];
After // add animation to the layer, the system will be in accordance with the defined properties begin the animation, programmers usually do not interact with the animated
[self.myView.layer addAnimation: anim forKey: nil ];
The most appropriate action // end of the animation
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
* Type = NSString [Anim valueForKey: @ "animationType is"];
IF ([type as isEqualToString: @ "translationTo"]) {
// 1. Remove the target point to be moved through key
CGPoint point = [[anim valueForKey: @ "TargetPoint"] CGPointValue];
NSLog (@ "target point:% @", NSStringFromCGPoint (point ));
coordinate point myView // 2. set the
[self.myView the setCenter: point];
}
}