提问人:Doston Rustamov 提问时间:6/11/2022 更新时间:6/11/2022 访问量:152
我需要使用平移手势在屏幕中的点周围移动和旋转视图
I need to move and rotate view around point in the screen with pan gesture
问:
我想使视图旋转并围绕屏幕中心移动。
这是我想要实现的目标的视觉表示。图像
而我目前的解决方案:
@objc func circleMoved(_ gesture: UIPanGestureRecognizer) {
switch gesture.state {
case .changed:
let translation = gesture.translation(in: view)
circle.layer.zPosition = 200
let spread = view.width
let angle: CGFloat = 100
let angleMoveX = angle * translation.x / spread
let angleMoveY = angle * translation.y / spread
let angleMoveXRadians = angleMoveX * CGFloat.pi/180
let angleMoveYRadians = angleMoveY * CGFloat.pi/180
var move = CATransform3DIdentity
move = CATransform3DRotate(move, angleMoveXRadians, 0, 1, 0)
move = CATransform3DRotate(move, -angleMoveYRadians, 1, 0, 0)
move = CATransform3DTranslate(move, translation.x, translation.y, 0)
circle.layer.transform = CATransform3DConcat(circle.layer.transform, move)
gesture.setTranslation(.zero, in: view) } }
但问题是它的旋转比我想要的要多。(最大 60 度)
答: 暂无答案
评论