Raon
Raon

Reputation: 1286

Two succesive animations on uiimageview...one after another

I have an UIImageView _winTextImage... I want to perform ro succesive animations on the view as go from left to right end of screen then from right end back to the left...but my code only shows the right to left (2nd) animation only....how can i get two animations one after another .. HERE IS MY CODE

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

}

Upvotes: 0

Views: 828

Answers (2)

Pratyusha Terli
Pratyusha Terli

Reputation: 2343

-(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;
                 }
     ];
}

Upvotes: 2

Karam
Karam

Reputation: 29

You can achieve it with Apple Animation block. Please avoid to take to many variables. please find below & let me know if you want anything else

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

                                      }
                      ];

                 }
 ];

}

Upvotes: 1

Related Questions