Perform a task (in iOS) after animation has finished

后端 未结 4 713
离开以前
离开以前 2021-02-04 07:11

So I have this line of code:

[tableView setContentOffset:point animated:YES];

and I want to run another piece of code after the animation ends. My a

相关标签:
4条回答
  • 2021-02-04 07:48

    For a scrollView, tableView or collectionView if you do something like this:

    [self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x+260.0,
                                                          self.collectionView.contentOffset.y)
                                     animated:YES];
    

    then you'll get back a:

    -(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
    

    when the scroll finishes.

    You do NOT get this callback if the user moves the view.

    0 讨论(0)
  • 2021-02-04 07:51

    Try to use this method:

    [UIView animateWithDuration:0.6f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         // Do your animations here.
                     }
                     completion:^(BOOL finished){
                         if (finished) {
                             // Do your method here after your animation.
                         }
                     }];
    
    0 讨论(0)
  • 2021-02-04 07:57

    You can create animations and tell them directly to perform a block after they're done.

    Here's an alternative that may play nicer with the UITableView's animations.

    [UIView beginAnimations:nil context:sender];
    [UIView setDelegate:self];
    [UIView setDidStopSelector:@selector(scrollMethod:)];
    [tableView setContentOffset:point];
    [UIView commitAnimations];
    

    And make sure to implement your scrollMethod: with this signature:

    - (void)scrollMethod:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
    

    You can use the context to know which sender you have. Read the UIView docs for more on UIView animations.

    0 讨论(0)
  • 2021-02-04 08:07

    UITableView inherits setContentOffset:animated: from its superclass, UIScrollView. Check out the scrollViewDidEndScrollingAnimation: method of UIScrollViewDelegate.

    0 讨论(0)
提交回复
热议问题