关于uiimageview的两个成功的动画......一个接一个

时间:2013-09-02 10:07:35

标签: ios animation uiview uiimageview uiviewanimation

我有一个UIImageView _winTextImage ... 我想在视图上执行ro成功动画,从屏幕的左到右,然后从右端返回到左边...但我的代码只显示从右到左(第2)动画....如何我一个接一个地获得两个动画.. 这是我的代码

-(void)animateWin
{
    CGRect temp=CGRectMake(0,self.view.frame.size.height/2-_winImageView.frame.size.height/2, _winImageView.frame.size.width, _winImageView.frame.size.height);

    _winImageView.frame=temp;

    [UIView beginAnimations : @"Display notif" context:nil];       //ANIMATION 1
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
     temp.origin.x+=self.view.frame.size.width-_winImageView.frame.size.width;
    _winImageView.frame=temp;
    [UIView commitAnimations];

    [UIView beginAnimations : @"Display notif" context:(__bridge void *)    (_winImageView)];               //ANIMATION 2
    [UIView setAnimationDuration:0.5 ];
    temp.origin.x=0;
    _winImageView.frame=temp;
    [UIView commitAnimations];

}

2 个答案:

答案 0 :(得分:2)

-(void)animateWin {    
     CGRect temp  = CGRectMake(0,(self.view.frame.size.height/2 -_winImageView.frame.size.height/2), _winImageView.frame.size.width, _winImageView.frame.size.height);
_winImageView.frame = temp;
     [UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     _winImageView.frame = CGRectMake((self.view.frame.size.width - _winImageView.frame.size.width), _winImageView.frame.origin.y, _winImageView.frame.size.width , _winImageView.frame.size.height);
                 }
                 completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.5
                                           delay:0.0
                                         options:UIViewAnimationOptionBeginFromCurrentState
                                      animations:^{
                                          _winImageView.frame = CGRectMake(0, _winImageView.frame.origin.y, _winImageView.frame.size.width , _winImageView.frame.size.height);
                                      }
                                      completion:^(BOOL finished) {
                                          [self animateWin];
                                      }
                      ];
                     //temp.origin.x = 0;
                 }
     ];
}

答案 1 :(得分:1)

您可以使用Apple动画块来实现它。 请避免采取多种变量。 请在下面找到&如果你想要别的什么,请告诉我

-(void)ImgFrom_L2R_AND_R2L {
animateImg.frame=CGRectMake(320,animateImg.frame.origin.y, animateImg.frame.size.width, animateImg.frame.size.height);
[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     nimateImg.frame=CGRectMake(-320,animateImg.frame.origin.y, animateImg.frame.size.width, animateImg.frame.size.height);
                 }
                 completion:^(BOOL finished) {

                     [UIView animateWithDuration:0.5
                                           delay:0.0
                                         options:UIViewAnimationOptionCurveEaseInOut
                                      animations:^{
                                          nimateImg.frame=CGRectMake(320,animateImg.frame.origin.y, animateImg.frame.size.width, animateImg.frame.size.height);
                                      }
                                      completion:^(BOOL finished) {

                                      }
                      ];

                 }
 ];

}