2011-12-26 6 views
0

私はブロックを使ってトランジションアニメーションを学びたかったのです。そこで私はアップルのドキュメンテーションに行き、old method (without blocks)を使ってアニメーションの例を取っ​​た。私はコードスニペット(わずかな変更)を取り、これをテストしました。それは UIView transistionWithAnimationが機能しない

[UIView setAnimationDelegate:nil]; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:kTransitionDuration]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
           forView:self.view 
           cache:YES]; 

if ([self.instructionsView superview]) { 
    [self.instructionsView removeFromSuperview]; 
    [self.view addSubview:contentView]; 
} else { 
    [self.contentView removeFromSuperview]; 
    [self.view addSubview:instructionsView]; 
} 

[UIView commitAnimations]; 

// adjust our done/info buttons accordingly 
if ([instructionsView superview]) { 
    self.navigationItem.rightBarButtonItem = doneButton; 
} else { 
    self.navigationItem.rightBarButtonItem = flipButton; 
} 

今すぐ下記のコードは、ブロック以下のコードは動作しなければならないことは何か私は理解することができますから、

[UIView transitionWithView:self.view duration:kTransitionDuration options:UIViewAnimationTransitionFlipFromRight animations:^{ 
     if ([self.instructionsView superview]) { 
      [self.instructionsView removeFromSuperview]; 
      [self.view addSubview:contentView]; 
     } else { 
      [self.contentView removeFromSuperview]; 
      [self.view addSubview:instructionsView]; 
     } 
} completion:^(BOOL finished){ 

     if ([instructionsView superview]) { 
      self.navigationItem.rightBarButtonItem = doneButton; 
     } else { 
      self.navigationItem.rightBarButtonItem = flipButton; 
     } 
}]; 

でコードに上のコードを変換する私の試みで完璧に動作します。ブロックをサポートするiOS 4.2でこれをテストしています。しかし、それはアニメートしていないようで、私はそれがなぜ理解できません。それはビューを変更し、アニメーション化しません。助けてください。

答えて

0

transitionToViewにtransitionWithViewを置き換えてください。fromView

関連する問題