Reputation: 13286
I have implemented a slider bar type UI control, like the Unlock mechanism on the iPhone.
When the touchesEnded method gets called, I return the slider to it's starting position. Instead, I would like to animate its move back to it's starting position.
The code should be something like this, but it doesn't work. What am I doing wrong here?
Self.unlock is a UIImageView:
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"];
theAnimation.fromValue = [NSNumber numberWithFloat:BEGINX];
theAnimation.toValue = [NSNumber numberWithFloat: 0.0];
theAnimation.duration = 0.5;
[self.unlock addAnimation: theAnimation];
Sorry for the bone-headed question!
Upvotes: 0
Views: 3427
Reputation: 43452
You can probably do this in a much simpler way using implicit animation. Assuming you currently are doing something like this:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
...
myView.frame = startingFrame;
...
}
You can use the implicit animator to animate any changes you make to the view (such as its frame):
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
...
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
myView.frame = startingFrame;
[UIView commitAnimations];
...
}
Upvotes: 3