ios - UIView 动画 shadowPath 不遵循

标签 ios swift uiview ios-animations

我有一个 UIView,它带有我制作的 expand 功能。 当我调用此函数时,UIView 保持居中,并且我扩展了它的宽度。

问题是我的 UIView 有一个 shadow 和一个 shadowPath。每当我展开它时,阴影都会立即展开到 View 将在动画结束时达到的最大宽度,而不是沿着边界。

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
}

最佳答案

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

关于ios - UIView 动画 shadowPath 不遵循,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51407790/

相关文章:

ios - objective-c : Need suggestion for my way of having protected method?

ios - 如何在应用程序未运行时下载数据(应用程序被杀死)

ios - 检查 Swift 2 中的空字符串

objective-c - UIScrollview 中的 iOS 点击手势

ios - 如何判断 ViewController View 是否可见

ios - 根据区域设置格式化部分日期

java - Appium 检查器错误,找不到要启动的设备错误

ios - 在用户选择时动态删除自定义 UIView/在 ios swift 中突出显示

ios - View 层次结构没有为约束准备?

ios - 过渡到其他 ViewController 的正确方法