0

我有一个 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];

}
4

2 回答 2

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;
                 }
     ];
}
于 2013-09-02T10:14:08.080 回答
1

您可以使用 Apple Animation 块来实现它。请避免采取许多变量。请在下面找到并告诉我您是否还想要其他东西

-(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) {

                                      }
                      ];

                 }
 ];

}

于 2013-09-02T10:28:31.037 回答