You can use Core Animation to animate the position of the views layer. If you set the animation to additive , you donβt have to worry about calculating a new absolute position, just a change (relative position).
CABasicAnimation *hover = [CABasicAnimation animationWithKeyPath:@"position"]; hover.additive = YES; // fromValue and toValue will be relative instead of absolute values hover.fromValue = [NSValue valueWithCGPoint:CGPointZero]; hover.toValue = [NSValue valueWithCGPoint:CGPointMake(0.0, -10.0)]; // y increases downwards on iOS hover.autoreverses = YES; // Animate back to normal afterwards hover.duration = 0.2; // The duration for one part of the animation (0.2 up and 0.2 down) hover.repeatCount = INFINITY; // The number of times the animation should repeat [myView.layer addAnimation:hover forKey:@"myHoverAnimation"];
Since this uses Core Animation, you need to add QuartzCore.framework and #import <QuartzCore/QuartzCore.h> to your code.
David RΓΆnnqvist
source share