IOS scrollView setContentOffset synchronization problem

I initialize a UIScrollView with a preview. After the button action, I want:

  • add new subview
  • go to the new animation preview
  • delete the old subtitle when the animation is over.

for this i do the following:

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

The problem is that immediately after the start of the animation, "tActualSide" is instantly deleted, and it will also be removed from the animation.

I would like to synchronize it so that tActualSide will only be deleted after the animation is complete.

How can i do this?

+1
source share
2 answers
[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];
}
+3
source

Listen to the delegate callback:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

and when you receive this message

[tActualSide removeFromSuperview];

Apple ( setContentOffset: :):

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
+5

All Articles