gpt4 book ai didi

ios - UIView.animateKeyframesWithDuration 内的 UIView.transitionWithView 未按预期工作

转载 作者:搜寻专家 更新时间:2023-11-01 05:39:54 25 4
gpt4 key购买 nike

我想创建一些在它们之间有延迟的动画,所以我决定使用 UIView.animateKeyframesWithDuration:delay:options:animations:completion:

问题是它同时发生。这是我的代码:

animateKeyframesWithDuration:

UIView.animateKeyframesWithDuration(5, delay: 0, options: nil, animations: {
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/5, animations: {
self.flipTransition(container: self.container500, view1: self.button500, view2: self.buttonDivision)
})
UIView.addKeyframeWithRelativeStartTime(1/5, relativeDuration: 1/5, animations: {
self.flipTransition(container: self.container100, view1: self.button100, view2: self.buttonMultiplication)
})
UIView.addKeyframeWithRelativeStartTime(2/5, relativeDuration: 1/5, animations: {
self.flipTransition(container: self.container50, view1: self.button50, view2: self.buttonSubtraction)
})
UIView.addKeyframeWithRelativeStartTime(3/5, relativeDuration: 1/5, animations: {
self.flipTransition(container: self.container10, view1: self.button10, view2: self.buttonAddition)
})
UIView.addKeyframeWithRelativeStartTime(4/5, relativeDuration: 1/5, animations: {
self.flipTransitionForConvertAndEqual(container: self.containerConvert, convertView: self.buttonConvert, equalView: self.buttonEqual)
})
}, completion: { finished in
})

transitionWithView:

private func flipTransitionForConvertAndEqual(#container: UIView, convertView: UIView, equalView: UIView) {
var transitionOptions: UIViewAnimationOptions!
let duration = kAnimationDuration

// case where equal is displayed
if equalView.superview != nil {
transitionOptions = .TransitionFlipFromLeft
}
else {
transitionOptions = .TransitionFlipFromRight
}

UIView.transitionWithView(container, duration: duration, options: transitionOptions, animations: {
self.setConvertContainer(container: container, convertView: convertView, equalView: equalView)
}, completion: nil)
}

private func flipTransition(#container: UIView, view1: UIView, view2: UIView) {
var transitionOptions: UIViewAnimationOptions!
let duration = kAnimationDuration

var views : (frontView: UIView, backView: UIView)

if view1.superview != nil {
views = (frontView: view1, backView: view2)
transitionOptions = .TransitionFlipFromLeft
}
else {
views = (frontView: view2, backView: view1)
transitionOptions = .TransitionFlipFromRight
}

UIView.transitionWithView(container, duration: duration, options: transitionOptions, animations: {
self.addFrontViewToContainer(container, frontView: views.backView, backView: views.frontView)
}, completion: nil)
}

我做错了什么?想不通。

最佳答案

来自文档:

  • (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations NS_AVAILABLE_IOS(7_0);

// start time and duration are values between 0.0 and 1.0 specifying time and duration relative to the overall time of the keyframe animation

在您的情况下,您可能希望为 relativeStartTime 参数 1 * (1/5)、2 * (1/5)、3 * (1/5)1/5 表示持续时间,请记住这些是相对于您指定的总持续时间的值UIView.animateKeyframesWithDuration.. 方法

关于ios - UIView.animateKeyframesWithDuration 内的 UIView.transitionWithView 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31910417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com