开发者

How to keep an object in view of a scrollview while animation moves the object offscreen

Good day all;

I have an UIImageView that I animate around a large UIView. The UIView is contained within a UIScrollView.

Now, with small movement animations of the UIImageView within the UIView, if it passes a certain thresh hold (gets close开发者_JAVA技巧 to the edge of the screen), I will manually scroll the UIScrollView to re-center the UIImageView. The code is synchronous in that I animate the UIImageView and then scroll to point in the UIScrollView.

Where I am having an issue is when there is a really long movement animation, the entire scrolling process struggles and I get a lot of skipped frames. I am not certain bit I think it is due to my synchronous code and I believe I need a way to execute the scrolling and the animation at the same time but I have no idea how to do it.

Is there a way to make the scrollview listen to where the UIImageView is at all times and center it when it passes a thresh hold even when in the middle of executing an animation?

By the way, I have disabled the user from scrolling the UIScrollView.

Thanks in advance.


Sorry I have left this for so long, I actually solved this a long time ago but forgot to post my solution.

Basically, pass the UIScrollview to the animated object (a layer or view). The animated object will have itself as a delegate for the animation and implement the methond "animationDidStart:(CAAnimation *)theAnimation".

If you persist the destination location in the animated object and the UIScrollView, then you can compute where to move the scrollview in the "animationDidStart" method.

Beware that the content offset and you destination location in the scrollview must be scaled if your scollview has been scaled. (Trap for young players)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜