1

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

  • 添加一个新的子视图
  • 滚动到带有动画的新子视图
  • 动画完成后删除旧的子视图。

为此,我执行以下操作:

[mCubeView setContentOffset:tOffset animated:YES];    
[tActualSide removeFromSuperview];

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

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

我怎样才能做到这一点?

4

2 回答 2

5

监听委托回调:

- (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
于 2012-07-30T14:51:40.353 回答
3
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[mCubeView setContentOffset:tOffset];
[UIView commitAnimations];
[self performSelector:@selector(remove) withObject:nil afterDelay:0.5f];


- (void)remove
{
    [tActualSide removeFromSuperview];
}
于 2012-07-30T14:47:36.263 回答