如何在imageView上调用uianimation看起来像Circle

时间:2011-11-24 14:53:19

标签: xcode uiimage uianimation

我想创建圈子uiimageview动画。当uiimage在self.left结束时,会立即从uiimageview.right之后再次调用。我想调用动画看起来像我的动画很糟糕。因为当它完成self.left时,它开始self.right。 :(但我想看起来像图像:

[ ----(end of image)---------       --------(start of image)]

Me. I did it.
[ -----(end of image)----------      ] 

当完成图像结束后,它就会出现。

我的代码如下:

 //for start 
    [UIView beginAnimations:nil context:nil];

    imageView.left = - imageView.width;
    // imageView2.left = - imageView.width;


    [UIView setAnimationDuration:140.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(moveToLeft:finished:context:)];
    [UIView commitAnimations];




-(void)moveToLeft:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
     imageView.left = self.right;
     imageView2.left = self.right + 3600;




     [UIView beginAnimations:nil context:nil];
     [UIView setAnimationDuration:140.0];
     [UIView setAnimationDelegate:self];
     imageView.left = -imageView.right;

     imageView2.left = -imageView2.right;





    //  imageView.left = - imageView.width;
    [UIView setAnimationDidStopSelector:@selector(moveToLeft:finished:context:)];
    [UIView commitAnimations];



   // imageView.frame.origin.x = imageView.left - self.right

 }

我该怎么办?感谢

1 个答案:

答案 0 :(得分:0)

现在建议使用基于块的方法(在iOS4及更高版本上可用),而不是使用beginAnimations。

[UIVIew animateWithDuration:140.0 delay:0.0
                    options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
                 animations:^(void) {
                     imageView.frame = CGRectMake( *Add Final position here* );
                 }
                 completion:^(BOOL finished) {}];

选项:UIViewAnimationOptionAutoreverse选项将确保动画前后移动。 UIViewAnimationOptionRepeat选项将保持动画。

在块中,将动画代码添加到视图应移动的位置。然后它会向前和向后移动到那一点。