Animate UIView out scaled表现得很奇怪

时间:2016-05-29 06:29:15

标签: ios animation uiview core-animation

我之前遇到过这个问题,但无法弄清楚它是什么。

如果我在Playground中为“独立”视图制作动画,这种事情看起来很好,但现在看起来就像提供的GIF一样。

让它看起来很好看,但是当我想要将它设置为动画(缩放)时,它只会达到最大值,然后消失。

enter image description here

以下是动画的代码:

self.circleView.transform = CGAffineTransformIdentity
UIView.animateWithDuration(0.5, delay: 0, options: [], animations: {
    self.circleView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
}, completion: {
    finished in
    if finished {
        self.resetStyle()
        self.circleView.hidden = true
        self.circleView.transform = CGAffineTransformIdentity
    }
})

func resetStyle() {
    self.circleView.transform = CGAffineTransformIdentity
    self.circleView.backgroundColor = nil
    self.textLabel.textColor = UIColor.blackColor()
}

1 个答案:

答案 0 :(得分:0)

试试这个:

    @IBOutlet weak var circleView: UIView!

@IBAction func leftAction(sender: AnyObject) {
    self.circleView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1)
    UIView.animateWithDuration(0.5) {
        self.circleView.layer.transform = CATransform3DIdentity
    }
}

@IBAction func rightAction(sender: AnyObject) {
    circleView.layer.transform = CATransform3DIdentity
    UIView.animateWithDuration(0.5) {
        self.circleView.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1)
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    circleView.backgroundColor = .blueColor()
    circleView.layer.cornerRadius = CGRectGetMidY(circleView.bounds)
}

enter image description here