iOS scrollView setContentOffset 同步问题

标签 ios uiscrollview

我用 subview 初始化 UIScrollView。按钮操作后,我想:

  • 添加新的 subview
  • 滚动到带有动画的新 subview
  • 动画完成后删除旧的 subview 。

  • 为此,我执行以下操作:
    [mCubeView setContentOffset:tOffset animated:YES];    
    [tActualSide removeFromSuperview];
    

    问题是,在动画开始后,“tActualSide”会立即被删除,它也会从动画中删除。

    我想同步它, tActualSide 只会在动画结束时被删除。

    我怎样才能做到这一点?

    最佳答案

    监听委托(delegate)回调:

    - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
    

    当您收到该消息时
    [tActualSide removeFromSuperview];
    

    引用 Apple 文档(注意“setContentOffset:animated:”引用):
    scrollViewDidEndScrollingAnimation:
    Tells the delegate when a scrolling animation in the scroll view concludes.
    
    - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
    Parameters
    scrollView
    The scroll-view object that is performing the scrolling animation.
    Discussion
    The scroll view calls this method at the end of its implementations of the UIScrollView and setContentOffset:animated: and scrollRectToVisible:animated: methods, but only if animations are requested.
    
    Availability
    Available in iOS 2.0 and later.
    Declared In
    UIScrollView.h
    

    关于iOS scrollView setContentOffset 同步问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11723594/

    相关文章:

    ios - UINavigationControllerDelegate 和 UIViewControllerAnimatedTransitioning 的问题

    ios - 当 ViewController 已经有委托(delegate)时如何设置委托(delegate)?

    ios - 我需要监听 UIScrollView 的更改,但无法快速设置委托(delegate)

    ios - UIScrollView 1D 弹跳但 2D 滚动

    iOS OpenGL ES 绘制网格线框

    ios - 从 ALAsset 获取实际的 NSData(每次我得到更大的图像尺寸)

    ios - 跟随 UICollectionView 指示器的 UIView

    iphone - UIScrollView - 启用分页后,我可以将页面宽度设置为 "change"吗?

    iphone - UIScrollView指示器总是显示?

    ios - 如何在 iOS swift 中将 .opus 文件转换为 .mp3/.m4a/.aac?