-2
的底部你如何保持一個影子在旋轉/動畫UI視圖的底部陰影留在旋轉的UIView迅速3
我的陰影代碼如下
extension UIView {
func dropShadow(cornerRadius : CGFloat, heightOffset : Int) {
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 1
self.layer.shadowOffset = CGSize(width: 0, height: heightOffset)
self.layer.shadowRadius = 5
//remove bezier to enable corner radius
// self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
self.layer.cornerRadius = cornerRadius
self.layer.shouldRasterize = true
}
}
然後在我的視圖控制器我稱之爲一個UIView動畫的方法
隱藏
UIView.animate(withDuration: 0.5, animations: {
for views in self.menuView.subviews {
views.alpha = 0
}
self.view.layoutIfNeeded()
self.moreButton.transform = tr
self.moreButton.dropShadow(cornerRadius: self.moreButton.layer.cornerRadius, heightOffset: 5)
}
顯示
UIView.animate(withDuration: 0.5, animations: {
self.moreButton.dropShadow(cornerRadius: self.moreButton.layer.cornerRadius, heightOffset: -5)
// menuV.center = self.menuView.center
menuV.center.y = -30
menuV.alpha = 1
self.view.layoutIfNeeded()
self.moreButton.transform = tr
}, completion: { (complete) in
})
結果是陰影跳到頂部或底部,然後旋轉。
我基本上需要它在動畫期間始終保持在圖層的底部。
可以請人幫忙,並說明什麼,我可能做錯了
問候
托馬斯