自定义动画的UIScrollView [英] Custom UIScrollView Animation

查看:167
本文介绍了自定义动画的UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用制成看起来很像一个UIPickerView按钮列表一个UIScrollView。我刚刚实施换血洗牌,其中在检测到震动,我设置了内容的UIScrollView偏移使用以下的的randomShuffle的位置。

I am using a UIScrollView with a list of buttons made to look much like a UIPickerView. I have just implemented shake to shuffle, where upon detection of a shake I set the content offset of the UIScrollView to the position of the randomShuffle using the following.

[Singlescroll setContentOffset:CGPointMake(jumpX, jumpY+randShuffle*sepValue) animated:YES];

而不仅仅是移动内容偏移到相匹配的按钮,我想实现一个洗牌的动画,其视图几乎'旋转'像老虎机,然后在randomShuffle按钮位置结束了随机位置的。

Instead of just moving the content offset to the random position that matches a button I would like to implement a shuffle animation where the view almost 'spins' like a slot machine and then ends up on the randomShuffle button position.

我试图通过简单的动画之前要回randomShuffle位置(一个接一个)的偏移量的UIScrollView的顶部,然后再次下跌做到这一点,但是这并没有工作,它只是直奔randomShuffle位置。我意识到,我没有用定时器试试这个所以动画不延迟,但是我想避免运行如果可能的计时器。

I tried to do this by simply animating the offset to the top of the UIScrollView then back down again before going back to the randomShuffle position (one after another), however this didn't work and it just went straight to the randomShuffle position. I realise that I didn't try this with a timer so the animations were not delayed however I would like to avoid running a timer if possible.

有没有办法,可以处理这个问题的任何内在的动画?如果没有请你可以建议我怎么可能用定时器之前解决这个?谢谢你。

Is there any inbuilt animations that can handle this? and if not please can you suggest how I might approach this before using timers? thank you.

推荐答案

而不是仅仅使用动画的:是,你有没有尝试把它变成是这样的:

Instead of just using animated:YES, did you try putting it into something like:

[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    [Singlescroll setContentOffset:maximumOffsetPoint]; //spin all the way up?
}completion:^(BOOL finished){
    if (finished)
        //kick off another animation, to spin it back down:
        [UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
            [Singlescroll setContentOffset:CGPointMake(jumpX, jumpY+randShuffle*sepValue)];
        }completion:nil];
    }
}];

我不知道这是否回答你的问题,但在完成块是超级方便,可能是你所需要的。在完成块,第二个动画将只被调用的第一个动画的结尾。

I don't know if this answers your question, but completion blocks are super handy and might be what you need. Within the completion block, the second animation will only get called at the end of the first animation.

此外,还有几个animateWithDuration:在UIView的方法,但在我的经验,这一个是动画,例如滚动意见contentOffset和zoomToRect性能更加可靠。

Also, there are several animateWithDuration: methods on UIView, but in my experience this one is more reliable for animating properties such as contentOffset and zoomToRect of scroll views.

这篇关于自定义动画的UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆