【问题标题】:Animate UIView out scaled behaves strangelyAnimate UIView out scaled 行为异常
【发布时间】:2016-09-27 04:16:32
【问题描述】:

我以前也遇到过这个问题,但不知道是什么问题。

如果我在 Playground 中为“独立”视图设置动画,这种情况看起来不错,但现在看起来就像在提供的 GIF 中一样。

动画看起来不错,但是当我想对其进行动画处理(缩放)时,它只会变得最大尺寸然后消失。

下面是动画代码:

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()
}

【问题讨论】:

  • self.resetStyle() 在做什么?
  • 我将其添加到问题中
  • 您是否尝试过将此动画应用到视图层而不是直接应用到 UIView ?并用 3D 变换替换仿射变换?

标签: ios animation uiview core-animation


【解决方案1】:

试试这个:

    @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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2018-03-11
    • 2018-08-06
    相关资源
    最近更新 更多