动画队列滑动一系列的uilabel使用Facebook POP和Swift的看法



我想"排队"一个动画序列,它将按顺序将一系列标签滑出视图,每次滑出之间略有延迟。从最上面的开始,到最后一个结束。目前我有以下函数,我在点击按钮时调用:

func slideLabelsOut(labelArguments: UILabel...) {
    var labelAnimation = POPDecayAnimation();
    labelAnimation.property = POPAnimatableProperty.propertyWithName(kPOPLayerPositionX) as POPAnimatableProperty;
    labelAnimation.velocity = -720;
    for label in labelArguments {
        var layer = label.layer;
        layer.pop_addAnimation(labelAnimation, forKey: "Slide");
    }
}

所以…我试着在for循环中使用ussleep(),但是当我发现它阻塞了主线程,这对我来说是绝对无用的…那么Pop中有什么内置的解决方案吗?或者我应该使用其他的框架吗?也……如果没有一个内置的解决方案,我应该如何处理排队动画在未来(我认为我会做很多)?

这个答案是针对Facebook POP框架的。

每个POP动画都是具有beginTime属性的POPAnimation类的子类。

/**
 @abstract The beginTime of the animation in media time.
 @discussion Defaults to 0 and starts immediately.
 */
@property (assign, nonatomic) CFTimeInterval beginTime;

你可以用它来错开动画的开始时间

我也有类似的需求。我正在制作一个风向计动画,作为天气应用程序的一部分。当它重播当天的天气时,仪表上的指针将围绕罗盘点移动-就像风向标一样。我在Objective C中有这个工作,作为我添加连续动画的队列,然后我从队列中播放动画。我还为温度计制作了一个类似的动画,显示一天中汞的水平是如何上升和下降的。

基本上我有一个函数getNextAnimation从队列中获取动画并运行它。当动画完成时,它调用getNextAnimation。所以这些动画是相互连接的。一旦我把动画排队,我调用getNextAnimation来开始序列。

我正在将这个应用程序移植到Swift,昨天开始制作动画。我想我会用同样的方法:

我的队列和getNetxAnimation函数:

typealias animationBlock = ()->Void
var animationBlocks:Array<animationBlock> = Array()
func getNextAnimation() -> animationBlock?
{
    var block:animationBlock?
    if animationBlocks.count > 0 { block = animationBlocks.removeAtIndex(0) }
    return block;
}
我的动画是用这样的代码添加的(曲线和实际的动画是特定于我的应用程序的):
var aBlock:animationBlock = { () in
    UIView.animateWithDuration(self.secondsPerAnimation,
        delay: 0.0,
        options: UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.BeginFromCurrentState,
        animations: {
            self.windDirectionPointer!.transform = CGAffineTransformMakeRotation(degreesToRadians(degrees))
        },
        completion: { (value: Bool) -> Void in
            var block:animationBlock? = getNextAnimation()
            if (block) { block!() }
        })
}
animationBlocks.append(aBlock)

我用:

引导动画
getNextAnimation()!()  // This assumes that getNextAnimation doesn't return nil!

最新更新