简体   繁体   中英

Nested UIVIew animateWithDuration not respecting completion

I want to do some graphical elements to dissapear, move the background image and new ones will appear. The problem is when background moves new ones appear before background movement animation has completed. I have not seen a good answer in related questions so I'll appreciate any help. Pseudocode:

-(void)method1 {
[UIView animateWithDuration:0.6
                      delay:0.0 options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     self.setThisOne.hidden = YES;
                     self.setThisAnother.hidden = YES;
                 }completion:^(BOOL finished) {
                     [UIView animateWithDuration:0.6
                                           delay:0.3
                                         options: UIViewAnimationOptionCurveEaseIn
                                      animations:^{ self.background.frame = myFrame; //Move background image
                                      } completion:^(BOOL finished){
                                          if (finished) {
                                              [self method2];
                                          }
                                      }
                      ];
                 }];

}

-(void)method2 {
    [UIView animateWithDuration:0.2
                      delay:0.3
                    options: UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     self.aButtonsAppear.hidden = NO;
                     self.moreElementsApeear.hidden = NO
                 } completion:nil];

}

.hidden may not be animate-able, but .alpha is. Use .alpha in animations to control visibility.

You probably found a solution by now but here is a little problem I had with completion blocks. I used -animateWithDuration:animations:completion: method but completion was not getting called because I think I was performing another action that interrupted the flow of the animation. In my case calling the same animation over and over again. Be careful with completion blocks. I still don't fully rely on them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM