それで、ブロックを使った遷移アニメーションを学びたいと思いました。そこで、Apple のドキュメントにアクセスして、古い方法 (ブロックなし)を使用したアニメーションの例を取り上げました。コード スニペット (わずかな変更) を取得し、これをテストしました。それは完璧に動作します
[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 でこれをテストしています。ただし、アニメーション化されていないようで、その理由がわかりません。ビューを変更しますが、アニメーション化はしません。助けてください。