xcode游乐场中的动画视图未完成

时间:2017-03-28 17:05:23

标签: ios swift uiviewanimation

我正在尝试制作一个自定义活动视图,用于旋转和翻转徽标。我处于早期阶段并在xcodes游乐场中构建它。我只是希望徽标垂直翻转,然后水平翻转,然后再次垂直翻转,这样徽标就是它最初的开始。我遇到的问题是,它只是执行第一次翻转而没有别的,但我不明白为什么?

这就是我现在在操场上看到的代码:

import UIKit
import PlaygroundSupport
import QuartzCore

class LogoActivityView: UIView {

var animationLoopCount: Int = 0
var logoImageView = UIImageView()
var logoImage = UIImage()

override init(frame: CGRect) {
    super.init(frame: frame)

    setupView()
    setLogoImageView()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

func setupView() {

    self.backgroundColor = .clear
    self.isHidden = true
}

func startAnimating() {

    self.isHidden = false

    animationLoopCount
    while animationLoopCount < 2 {

        UIView.animate(withDuration: 1.0, delay: 0.1, options: .curveEaseInOut, animations: {() -> Void in

            self.logoImageView.layer.transform = CATransform3DMakeRotation(.pi, 1.0, 0.0, 0.0)

        }, completion: {(_ finished: Bool) -> Void in

            UIView.animate(withDuration: 1.0, delay: 0.0, options: .curveEaseInOut, animations: {

                self.logoImageView.layer.transform = CATransform3DMakeRotation(.pi, 0.0, 1.0, 0.0)
            }, completion: nil)
        })

        animationLoopCount += 1
    }
}

func setLogoImageView() {

    logoImageView = UIImageView(frame: self.frame)
    logoImage = UIImage(named: "MemoryBoothLogo.png")!

    logoImageView.image = logoImage
    logoImageView.contentMode = .scaleAspectFit
    logoImageView.backgroundColor = .clear

    self.addSubview(logoImageView)
}
}

let containerView = LogoActivityView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))

PlaygroundPage.current.liveView = containerView
PlaygroundPage.current.needsIndefiniteExecution = true

containerView.startAnimating()

任何帮助都会非常感谢

0 个答案:

没有答案