簡體   English   中英

動畫在iOS Play場中不起作用

[英]Animations not working in ios playground

這是我的動畫方法(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")

    }
}

這是我的游樂場檔案

和項目導航器中的游樂場

動畫在設備上可以正常工作,但是當我使用運動場動畫時無法正常工作。

Xcode 7,Swift 2

import XCPlayground

在游樂場的頂部,然后使用

XCPlaygroundPage.currentPage.liveView = view

在Playground的底部,其中view是要渲染的視圖。

您還必須打開“助手編輯器”(在“視圖”菜單中)以查看當前的實時視圖。

另外,如果您使用異步操作,則必須包含

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

為了在操場上使用它們。

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