Reputation: 4124
I have a UIImageView added as a subview. I am trying to animate it using transform. The animation doesn't, however the imageview is Scaled properly, it's just not auto reversing. Am I doing something wrong?
UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
iv_tap.center = point;
iv_tap.tag = 779;
iv_tap.hidden = true;
[UIView animateWithDuration:2.0
delay:.05
options: UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^{
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);
}
completion:NULL];
[self addSubview:iv_tap];
Upvotes: 1
Views: 755
Reputation: 11201
You need to do the animation after you add the imageView
into the view
. If you do the animation before the addSubView
where at point, the image view is not in the view heirarchy and you can't see any animation.
UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self.view addSubview:iv_tap]; //this could be self in your case
iv_tap.tag = 779;
[UIView animateWithDuration:2.0 delay:0.05 options:UIViewAnimationOptionCurveEaseOut animations:^{
iv_tap.center=self.view.center;
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);
[self.view layoutIfNeeded]; //this could be self in your case
} completion:^(BOOL finished) {
//do your stuff when animation is done
}];
If you are subclassing a UIView, then you can even put this in the drawRect method:
UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self addSubview:iv_tap];
iv_tap.tag = 779;
[UIView animateWithDuration:2.0 delay:0.05 options:UIViewAnimationOptionCurveEaseOut animations:^{
iv_tap.center=self.center;
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);
[self layoutIfNeeded];
} completion:^(BOOL finished) {
//do your stuff when animation is done
}];
Upvotes: 1