How to make UIScrollView send scrollViewDidScroll messages during animations

后端 未结 1 1575
刺人心
刺人心 2020-12-10 15:53

When the user manually scrolls through my UIScrollView, the scrollViewDidScroll method of my delegate gets called repeatedly during the animation, with newly updated values

1条回答
  •  有刺的猬
    2020-12-10 16:28

    Thanks to Fichek's hint, I have gotten this to work. Like Fichek said, you don't get any notifications of changed properties during animation. So the trick is, to make sure that anything that depends on the changed property is also animated at the same time. You need to setup their animations in the same block as the original property. If you then set the "UIViewAnimationOptionAllowUserInteraction" on the animation, then any ongoing user interaction of the same properties will still work - and surprisingly well, I have to say.

    For my concrete case - to keep a dragged view stationary, while the UIScrollView scrolls underneath - here is how I setup my animation:

    [UIView animateWithDuration:0.5 delay:0
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^{
        [theScrollView setContentOffset:offset];
        // compute newCenter from the new offset
        theDraggedView.center = newCenter;
    } completion:^(BOOL finished) {}];
    

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