动画不在ios游乐场工作 [英] Animations not working in ios playground

查看:124
本文介绍了动画不在ios游乐场工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my animation method (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")

    }
}

这是我的操场文件

和项目导航器中的游乐场

and playground in project navigator

Anim ations在设备上运行正常,但是当我使用游乐场动画无效时。

Animations work fine on device, but when I use playground animations not working.

推荐答案

Xcode 7,Swift 2

添加

import XCPlayground

然后使用

XCPlaygroundPage.currentPage.liveView = view

位于游乐场的底部, view 是您要呈现的视图。

at the bottom of the Playground, where view is the view you want to render.

您还必须打开助理编辑器(在查看菜单)查看当前实时视图。

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

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

这篇关于动画不在ios游乐场工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆