0
votes

I'm trying to convert old styled animation to blocks using style. The following code work fine:

[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];

But this converted wont work:

[UIView animateWithDuration:.3f
     animations:^{
         selected_view.frame = targetSlot.frame;
         selected_view.center = targetSlot.center;
     }
 ];

It says:

 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'

I'm using ios 4.1 with iPad simulator. It compiles ok but always crashes. Can't figure out whats wrong. Even simple example from apple dev:

[UIView animateWithDuration:0.2
     animations:^{view.alpha = 0.0;}
     completion:^(BOOL finished){ [view removeFromSuperview]; }];

works the same way - it just crashes with the same message (with only "completion:" adding). Whats wrong with argument? Which argument at all? Do I need to import something to add support of blocks? But it compiles fine... I can even see in the 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
...
3
Can you double-check the version of the simulator? - Thilo
seems you need remove xcode and install latest xcode again. - xhan
iOS Deployment target = iOS 4.1, Base SDK = iOS simulator 4.1, running on iPad emu version 4.1 (225). - Stan
Did you clean your project and rebuild? - borrrden
I did Clean/Clean all targets and even threw the "build" subfolder of my project to trash. no luck. - Stan

3 Answers

0
votes

Have you recently upgraded to xcode 4.5 as this no longer will support ios 4.1.

The only other thing I can think of is the variables you're using are not safe to use in blocks. To make them safe simply add __block when initialising the variable. Does seem a strange one!

0
votes

NSTimeInterval is not a float. Its a double. Which is why your original code worked.

0
votes

Installing a newer version of XCode resolved the issue. Before installing my current version of XCode was removed using sudo.