嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
extension GenericState where T: BinaryInteger {
init(transitionFrom state: GenericState<T>, to targetValue: T,
delay: TimeInterval, duration: TimeInterval,
storedWithScene: Bool = false) {
self.animation = nil
self.storedWithScene = storedWithScene
guard delay > 0 || duration > 0 else {
self.value = targetValue
self.transition = nil
return
}
self.value = state.currentValue
guard state.transition != nil || state.value != targetValue else {
self.transition = nil
return
}
self.transition = Self.Transition(targetValue: targetValue,
start: Date(), delay: delay,
duration: duration)
}
init(continueTransitionFrom state: GenericState<T>, to targetValue: T,
delay: TimeInterval, duration: TimeInterval,
storedWithScene: Bool = false) {
self.animation = nil
self.storedWithScene = storedWithScene
guard delay > 0 || duration > 0 else {
self.value = targetValue
self.transition = nil
return
}
self.value = state.currentValue
guard state.transition != nil || state.value != targetValue else {
self.transition = nil
return
}
if let transition = state.transition {
self.transition = Self.Transition(targetValue: targetValue,
start: transition.start, delay: delay,
duration: duration)
} else {
self.transition = Self.Transition(targetValue: targetValue,
start: Date(), delay: delay,
duration: duration)
}
}
init(animateFrom state: GenericState<T>, to targetValue: T,
delay: TimeInterval, duration: TimeInterval,
storedWithScene: Bool = false) {
self.value = state.value
self.transition = nil
self.storedWithScene = storedWithScene
guard state.value != targetValue, duration > 0 else {
self.animation = nil
return
}
let speed = Double(targetValue) / duration
self.animation = Self.Move(start: Date(), delay: delay,
speed: T(truncatingIfNeeded: Int(speed)))
}
var currentValue: T {
if let animation = animation {
let timeDiff = animation.startTime.timeIntervalSinceNow
// Is the animation scheduled for the future?
if timeDiff >= 0 {
return value
} else {
// Otherwise, it has already started.
return T(truncatingIfNeeded: Int(Double(value) - timeDiff * Double(animation.speed)))
}
} else if let transition = transition {
let timeDiff = transition.startTime.timeIntervalSinceNow
// Is the animation scheduled for the future?
if timeDiff >= 0 {
return value
} else if transition.remainingTime == 0 {
// Has if completed?
return transition.targetValue
} else {
// Otherwise, it's in progress.
let progress = transition.remainingTime / transition.duration
let diff = Double(value) - Double(transition.targetValue)
return T(truncatingIfNeeded: Int(transition.targetValue) Int(diff * progress))
}
} else {
return value
}
}
}