gpt4 book ai didi

ios - 动画在 ios Playground 中不起作用

转载 作者:行者123 更新时间:2023-11-30 13:21:00 25 4
gpt4 key购买 nike

这是我的动画方法(PreloaderView.swift)

public func performAction(action: PreloaderAction)
{
let highOpacity = CABasicAnimation.init(keyPath: "opacity")
let middleOpacity = CABasicAnimation.init(keyPath: "opacity")
let lowOpacity = CABasicAnimation.init(keyPath: "opacity")

if action == .PreloaderActionNone {
self.thirdShape.removeAllAnimations()
self.firstShape.opacity = 0.3;
self.secondShape.opacity = 0.5
self.thirdShape.opacity = 1.0
} else if action == .PreloaderActionFailure {
UIView.animateWithDuration(2, animations: {
self.thirdShape.strokeColor = UIColor.redColor().CGColor
}) {(completed : Bool) in
self.thirdShape.strokeColor = self.ringColor.CGColor
}

}

if action == .PreloaderActionStart {

highOpacity.fromValue = 0.0
highOpacity.toValue = 1.0
highOpacity.duration = animationDuration
highOpacity.autoreverses = true
highOpacity.repeatCount = .infinity
self.secondShape.addAnimation(highOpacity, forKey: "highOpacity")

middleOpacity.fromValue = 0.0
middleOpacity.toValue = 1.0
middleOpacity.duration = animationDuration
middleOpacity.autoreverses = true
middleOpacity.repeatCount = .infinity
middleOpacity.beginTime = CACurrentMediaTime() + 0.33
self.firstShape.addAnimation(middleOpacity, forKey: "middleOpacity")

lowOpacity.fromValue = 0.0
lowOpacity.toValue = 1.0
lowOpacity.duration = animationDuration
lowOpacity.autoreverses = true
lowOpacity.beginTime = CACurrentMediaTime() + 0.66
lowOpacity.repeatCount = .infinity
self.thirdShape.addAnimation(lowOpacity, forKey: "lowOpacity")

}
}

这是我的 Playground 文件

项目导航器中的 Playground

动画在设备上工作正常,但当我使用 Playground 动画时不起作用。

最佳答案

Xcode 7、Swift 2

添加

import XCPlayground

在 Playground 顶部,然后使用

XCPlaygroundPage.currentPage.liveView = view

位于 Playground 底部,其中 view 是您要渲染的 View 。

您还必须打开“助理编辑器”(位于“ View ”菜单中)才能查看当前的实时 View 。

此外,如果您使用异步操作,则必须包含

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

以便在 Playground 中使用它们。

Xcode 8、Swift 3

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = view

关于ios - 动画在 ios Playground 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37769647/

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