移动视图更接近相机

时间:2016-08-05 12:07:19

标签: ios core-animation

我尝试通过更改CATransform3DMakeTranslation将UIView移近相机。我导入了QuartzCore但没有任何反应

我的代码正在关注

let pan = UIPanGestureRecognizer(target: self, action: "pan:")
dummyView.addGestureRecognizer(pan)

func pan(gesture:UIPanGestureRecognizer) {
    switch gesture.state {
    case .Changed: fallthrough
    case .Ended:
        let translation = gesture.translationInView(dummyView)
        var transform = CATransform3DMakeTranslation(0, 0, translation.x)
        dummyView.layer.transform = transform

    default: break
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要添加子图层转换以向图层添加透视。

    var initialTransform = self.layer.transform
    initialTransform.m34 = 1.0 / -500 //adjust this value for your needs
    self.layer.sublayerTransform = initialTransform

(假设self.layerdummyView.layer

的超级层