2015-07-21 28 views
0

我想爲我的應用添加動畫。我有一張卡,我想將它移動到中心位置,然後卡從右側翻轉。我用這個代碼;從右拖倒

[self.scrollView bringSubviewToFront:self.image1]; 
    CATransition *animation = [CATransition animation]; 
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    animation.type = kCATransitionFade; 
    animation.duration = 0.75; 
    [self.image1.layer addAnimation:animation forKey:@"kCATransitionFade"]; 
    [UIView animateWithDuration:0.5 animations:^{ 
     self.image1.frame = CGRectMake(90,self.scrollView.frame.origin.y+40, 140, 250); 
    }]; 
    self.image1.transform = CGAffineTransformMakeScale(0.1,0.1); 

    [self.view bringSubviewToFront:self.image1]; 
    [UIView beginAnimations:@"fadeInNewView" context:NULL]; 
    [UIView setAnimationDuration:1.0]; 
    self.image1.transform = CGAffineTransformMakeScale(2,2); 
    self.image1.alpha = 1.0f; 
    [UIView commitAnimations]; 
    UIImage *imageTest=[UIImage imageNamed:@"home.png"]; 


    [UIView transitionWithView:self.image1 duration:1 
         options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ 
          self.image1.image = imageTest; 
         } completion:nil]; 

但卡之前翻轉到新的框架。任何ideea我該如何解決這個問題>

+0

只需通過編寫animateWithDuration嘗試:塊內transitionWithView:塊 –

回答

0

你必須製作一個動畫序列。最簡單的方法是將翻轉動畫放在幀更改動畫的完成塊中。

實施例:

[UIView animateWithDuration:0.5 
       animations:^{ 
        self.image1.frame = CGRectMake(90,self.scrollView.frame.origin.y+40, 140, 250); 
       } 
       completion:^(BOOL finished){ 
        //your flip animation goes here 
       }]; 
0

使用此代碼。可能會幫助你從右側翻轉動畫。

[UIView transitionFromView:appDelegate.window.rootViewController.view 
          toView:appDelegate.navigationController.view 
          duration:0.5 
          options:UIViewAnimationOptionTransitionFlipFromRight 
         completion:^(BOOL finished) 
     { 
      [appDelegate.window setRootViewController:appDelegate.navigationController]; 
     }];