【问题标题】:UIView animation shadowPath doesn't followUIView 动画 shadowPath 不跟随
【发布时间】:2018-12-26 17:08:57
【问题描述】:

我有一个 UIView 和我创建的 expand 函数。 当我调用这个函数时,UIView 保持居中,并扩展它的宽度。

问题是我的UIView 有一个shadow,还有一个shadowPath。每当我展开它时,阴影会立即展开到动画结束时视图将获得的最大宽度,而不是跟随边界。

func expand() {
    guard self.expanded == false else {
        return
    }

    let originX = self.frame.origin.x
    let originY = self.frame.origin.y
    let originWidth = self.frame.width
    let originHeight = self.frame.height
    let newWidth = self.frame.width * 2

    let newRect = CGRect(x: originX - ((newWidth - originWidth) / 2), y: originY, width: newWidth, height: originHeight)

    self.expanded = true

    UIView.animate(withDuration: 0.4, animations: {
        self.frame = newRect
        self.layoutIfNeeded()
    }) { (completed) in
    }
}


override func layoutSubviews() {
    super.layoutSubviews()
    self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.layer.cornerRadius).cgPath
}

【问题讨论】:

    标签: ios swift uiview ios-animations


    【解决方案1】:

    UIView 显式(但私下)选择其图层的哪个属性进行隐式动画处理,而shadowPath 不是其中之一。您必须自己制作动画。

    【讨论】:

    • 我怎样才能做到这一点?
    • 在您喜欢的搜索引擎中输入CABasicAnimation tutorial
    猜你喜欢
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多