Note that there are some explanatory texts on larger screens.

plurals
  1. POAutoscroll UIScrollView, allow user to interrupt animation
    primarykey
    data
    text
    <p>I'm trying to animate a bunch of images in a UIScrollView. The images should start scrolling when the screen shows, which I can do. At the moment I'm using UIView animations as follows:</p> <pre><code> [Export("ScrollToRight")] private void ScrollRight() { if (!imagesShouldScroll) return; UIView.BeginAnimations("ScrollRight"); UIView.SetAnimationCurve(UIViewAnimationCurve.Linear); UIView.SetAnimationDuration(test.Count * 10); scrlImages.ContentOffset = new PointF(((scrlImages.Frame.Height + 2) * test.Count) - scrlImages.Frame.Width, 0); UIView.SetAnimationDelegate(this); UIView.SetAnimationDidStopSelector(new Selector("ScrollToLeft")); UIView.CommitAnimations(); } [Export("ScrollToLeft")] private void ScrollLeft() { if (!imagesShouldScroll) return; UIView.BeginAnimations("ScrollLeft"); UIView.SetAnimationCurve(UIViewAnimationCurve.Linear); UIView.SetAnimationDuration(test.Count * 10); scrlImages.ContentOffset = new PointF(0, 0); UIView.SetAnimationDelegate(this); UIView.SetAnimationDidStopSelector(new Selector("ScrollToRight")); UIView.CommitAnimations(); } </code></pre> <p>This works perfectly to scroll back and forth in the UIScrollView. What I need to be able to do is let the user interrupt the animation by swiping on the ScrollView as they would normally scroll through the list. So I have attached a listener to the ScrollView as follows:</p> <pre><code> scrlImages.DraggingStarted += (sender, e) =&gt; { if (imagesShouldScroll) { scrlImages.Layer.RemoveAllAnimations(); imagesShouldScroll = false; } }; </code></pre> <p>This works to stop the animations as expected. The problem is that the ContentOffset has already been set to the edge where it's busy animating to. So when the user swipes the ScrollView it suddenly jumps to the end of the list. I'd like the user to be able to stop the animation where it is and take over the scrolling manually. I'm thinking there should be a way to use the animation's start time and the current graphics time to determine how long the animation has been running to determine where the ContentOffset would have been at that time, then jumping back there. That sounds very hacky to me though, less than ideal.</p> <p>Note: I know I could just have used UIView.Animate with UIViewAnimationOptions.Autoreverse, I just didn't know about that at the time. I've also been able to implement the behaviour I want using a timer to set the ContentOffset periodically. It's CPU bound though, so it's not very smooth.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload