Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run code after UIView transitionWithView?

I want to run a block of code after an animation is completed but the compiler shows the following error : "Incompatible block pointer types sending 'void (^)(void)' to parameter of type 'void (^)(BOOL)'"

Here is my code, I am not sure what I am doing wrong, please help, thanks.

[UIView transitionWithView:self.view duration:1.5
                   options:UIViewAnimationOptionTransitionFlipFromBottom //change to whatever animation you like
                animations:^ {
                    [self.view addSubview:myImageView1];
                    [self.view addSubview:myImageView2];
                }
                completion:^ {
                    NSLog(@"Animations completed.");
                    // do something...
                }];
like image 640
Fellow GEEK Avatar asked Jan 18 '13 19:01

Fellow GEEK


1 Answers

You just have the wrong block type :) It needs a block like below. The key being ^(BOOL finished) {...}

[UIView transitionWithView:self.view duration:1.5
                   options:UIViewAnimationOptionTransitionFlipFromBottom //change to whatever animation you like
                animations:^ {
                    [self.view addSubview:myImageView1];
                    [self.view addSubview:myImageView2];
                }
                completion:^(BOOL finished){
                    if (finished) {
                        // Successful
                    }
                    NSLog(@"Animations completed.");
                    // do something...
                }];
like image 170
Ryan Poolos Avatar answered Oct 24 '22 09:10

Ryan Poolos