Floating image in IOS
I'm trying to create a floating effect using this code over a UIImageView:
[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
self.imageView.transform = CGAffineTransformMakeTranslation(10开发者_运维百科, 0);
}
completion:^(BOOL end){
}];
This code create a simple effect, moving repeatedly image from left to right by 10 px.
The problem is that moving so slowly, the image has a strange effect and the animation isn't smooth.
Is there some tricks (or settings) to avoid this problem and to obtain a smooth animation ??
You should animate the center of your view:
[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
self.imageView.center = CGPointMake(self.imageView.center.x + 10,
self.imageView.center.y);
}
completion:NULL];
精彩评论