简体   繁体   English

动画在iOS Play场中不起作用

[英]Animations not working in ios playground

This is my animation method (PreloaderView.swift) 这是我的动画方法(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")

    }
}

This is my playground file 这是我的游乐场档案

and playground in project navigator 和项目导航器中的游乐场

Animations work fine on device, but when I use playground animations not working. 动画在设备上可以正常工作,但是当我使用运动场动画时无法正常工作。

Xcode 7, Swift 2 Xcode 7,Swift 2

Add

import XCPlayground

at the top of the Playground, then use 在游乐场的顶部,然后使用

XCPlaygroundPage.currentPage.liveView = view

at the bottom of the Playground, where view is the view you want to render. 在Playground的底部,其中view是要渲染的视图。

You also have to open the "Assistant Editor" (in the "View" menu) to see the current live view. 您还必须打开“助手编辑器”(在“视图”菜单中)以查看当前的实时视图。

Also, if you're using asynchronous operations, you have to include 另外,如果您使用异步操作,则必须包含

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

in order to use them in a Playground. 为了在操场上使用它们。

Xcode 8, Swift 3 Xcode 8,Swift 3

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM