我嘗試翻轉具有圓角(邊框)的視圖。帶圓角的翻轉UIView
視圖的圓角與實施:
private extension UIView {
func round(corners: UIRectCorner, radius: CGFloat, borderColor: UIColor, borderWidth: CGFloat) {
let mask = _round(corners: corners, radius: radius)
addBorder(mask: mask, borderColor: borderColor, borderWidth: borderWidth)
}
@discardableResult func _round(corners: UIRectCorner, radius: CGFloat) -> CAShapeLayer {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
return mask
}
func addBorder(mask: CAShapeLayer, borderColor: UIColor, borderWidth: CGFloat) {
let borderLayer = CAShapeLayer()
borderLayer.path = mask.path
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.strokeColor = borderColor.cgColor
borderLayer.lineWidth = borderWidth
borderLayer.frame = bounds
layer.addSublayer(borderLayer)
}
}
當翻蓋上運行的翻蓋與
UIView.transition(with: self, duration: 0.5, options: [.transitionFlipFromRight], animations: {}, completion: {_ in })
實施,寄宿生都不會再四捨五入而過渡正在運行。
任何人有一個想法如何做翻蓋,沒有鬆動的圓角?
更新
如果我去this的做法,我有幾個問題。
翻蓋現在已經實現這樣的:
let flipAnimation = CABasicAnimation(keyPath: "transform")
flipAnimation.fromValue = NSValue(caTransform3D: CATransform3DIdentity)
flipAnimation.toValue = NSValue(caTransform3D: CATransform3DMakeRotation(.pi, 0,1,0))
flipAnimation.fillMode = kCAFillModeBoth
self.layer.add(flipAnimation, forKey: "flip")
self.layer.zPosition = -1000
CATransaction.commit()
問題
- 動畫不說,光滑如UIView.transition
- 的影響反映在視圖上的內容 - - >我不需要(下圖)
- 旋轉不完全結束,所以視圖在某個時候放錯了位置S(下圖)
更新:溶液 我加入一個容器視圖與周圍的圓角着色視圖和翻轉所述容器代替的着色圖。然後一切正常!
可能的重複[你如何翻轉非圓全角UIView的超視圖?](https://stackoverflow.com/questions/10727356/how-do-you-flip-non-fullscreen-uiviews- in-a-superview-rounded-corners) – agibson007
我更新了問題,thx爲你的提示。 – sialcasa
你想如何看待它被旋轉後的視圖? – agibson007