スタイルを使用して、古いスタイルのアニメーションをブロックに変換しようとしています。次のコードは正常に動作します。
[UIView beginAnimations:@"ResizeAndMove" context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationDelay:0];
[UIView setAnimationBeginsFromCurrentState:YES];
selected_view.frame = targetSlot.frame;
selected_view.center = targetSlot.center;
[UIView commitAnimations];
しかし、この変換は機能しません:
[UIView animateWithDuration:.3f
animations:^{
selected_view.frame = targetSlot.frame;
selected_view.center = targetSlot.center;
}
];
それは言います:
2012-10-17 12:32:50.256 myapp[311:207] *** +[UIView
animateWithDuration:animations:]: unrecognized selector sent to class
0x21b989c 2012-10-17 12:32:50.259 myapp[311:207] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason: '***
+[UIView animateWithDuration:animations:]: unrecognized selector sent to class 0x21b989c'
iPadシミュレーターでios 4.1を使用しています。正常にコンパイルされますが、常にクラッシュします。何が悪いのか理解できません。Apple dev の簡単な例:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
同じように動作します-同じメッセージでクラッシュするだけです(「完了:」のみが追加されます)。議論の何が問題なのですか?一体どの議論?ブロックのサポートを追加するために何かをインポートする必要がありますか? しかし、それはうまくコンパイルされます...UIKit/UIViewでも見ることができます:
...
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0, completion = NULL
...