开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜