0

スタイルを使用して、古いスタイルのアニメーションをブロックに変換しようとしています。次のコードは正常に動作します。

[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
...
4

3 に答える 3

0

XCode の新しいバージョンをインストールすると、問題が解決しました。現在のバージョンの XCode をインストールする前に、sudo を使用して削除しました。

于 2012-10-18T14:10:26.133 に答える
0

NSTimeInterval は float ではありません。そのダブル。これが、元のコードが機能した理由です。

于 2012-10-17T09:54:50.043 に答える
0

iOS 4.1 をサポートしなくなるため、最近 xcode 4.5 にアップグレードしましたか。

他に考えられる唯一のことは、使用している変数をブロックで使用するのは安全ではないということです。それらを安全にするには、変数を初期化するときに __block を追加するだけです。奇妙に思えます!

于 2012-10-17T09:31:24.567 に答える