I am a new player for swiftui dev. And I want to write a page-down clock to study swiftui. But I stuck on how to page-down a page, which means rotate the object around x axis. And I know rotate3DEffect would generate strange result.
Here is my code:
Rectangle() // the view
.frame(width: 100, height: 100, alignment: .center)
.foregroundColor(.white)
.accessibilityAction {
let a = UIView(frame: CGRect(origin: CGPoint(x: 10,y: 10), size: CGSize(width: 1, height: 2)))
a.backgroundColor = .blue
let b = UIView(frame: CGRect(origin: CGPoint(x: 10,y: 10), size: CGSize(width: 1, height: 2)))
b.backgroundColor = .yellow
let c = UIView(frame: CGRect(origin: CGPoint(x: 10,y: 10), size: CGSize(width: -1, height: -2)))
c.backgroundColor = .red
rotation(first: a,back: b,solid: c)
}
func rotation<V>(first: V, back: V, solid: V) where V: UIView{
// rotationFront
// rotationBack
/*
| B|/C
| A|
*/
rotationFront(first: first)
rotationBack(back: back)
}
func rotationFront<V>(first: V) where V: UIView {
let animation = CABasicAnimation(keyPath: "transform.rotation.x")
animation.fromValue = (10/360)*Double.pi
animation.toValue = (355/360)*Double.pi
animation.duration = 1.0
animation.repeatCount = 0
first.layer.add(animation, forKey: "rotationBack")
}
func rotationBack<V>(back: V) where V: UIView {
let animation = CABasicAnimation(keyPath: "transform.rotation.x")
animation.fromValue = (10/360)*Double.pi
animation.toValue = (355/360)*Double.pi
animation.duration = 1.0
animation.repeatCount = 0
back.layer.add(animation, forKey: "rotationFront")
}
It does nothing. What should I do? Thanks a lot.