iOS scrollView setContentOffset同步问题

Zol*_*adi 1 uiscrollview ios

我使用子视图初始化UIScrollView.按钮操作后,我想:

  • 添加新的子视图
  • 使用动画滚动到新的子视图
  • 动画结束后删除旧的子视图.

为此,我做了以下事情:

[mCubeView setContentOffset:tOffset animated:YES];    
[tActualSide removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)

问题是,在动画开始后,"tActualSide"立即被删除,它也将从动画中删除.

我想同步它,只有在动画结束时才会删除tActualSide.

我怎样才能做到这一点?

Dav*_*d H 5

听取代表回调:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Run Code Online (Sandbox Code Playgroud)

当你收到那条消息时

[tActualSide removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)

引用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
Run Code Online (Sandbox Code Playgroud)