我有一个 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/