我当时在看这个仓库

https://github.com/mmohsin991/gestures/blob/master/gestures/ViewController.swift

这个例子

http://www.raywenderlich.com/50398/opengl-es-transformations-gestures

我有以下代码

      @IBOutlet var pinchProperty: UIPinchGestureRecognizer!
      @IBAction func pinchAction(sender: UIPinchGestureRecognizer) {
        if(dbg){println("scale \(pinchProperty.scale)")}
        let pinch: CGFloat = pinchProperty.scale
        switch pinchProperty.state{
        case .Began:
          println("pinch started")
        case .Changed:
          geometryNodeMain.scale = SCNVector3(x:Float(pinch),y:Float(pinch),z:Float(pinch))
        case .Ended:
          println("pinch ended")
        case .Cancelled:
          break
        case .Failed:
          break
        case .Possible:
          break
        default:
          break
        }
      }

最初,捏会起作用,并会放大和缩小,但是比例会重置为1。转换openGL代码http://www.raywenderlich.com/50398/opengl-es-transformations-gestures很麻烦。

有人可以帮忙转换此代码吗?

最佳答案

这可行。

在某处初始化变量。

  var scaleStart:CGFloat = 1.0
  var scaleEnd:CGFloat = 1.0

然后像这样
 @IBOutlet var pinchProperty: UIPinchGestureRecognizer!
  @IBAction func pinchAction(sender: UIPinchGestureRecognizer) {

    if(dbg){println("scale \(pinchProperty.scale)")}

    let pinch: CGFloat = pinchProperty.scale

    switch pinchProperty.state{
    case .Began:
      scaleStart = scaleEnd*pinch
      if(dbg){println("pinch started \(scaleStart)")}
    case .Changed:
      scaleStart = scaleEnd*pinch
      geometryNodeMain.scale = SCNVector3(
        x:Float(scaleStart),
        y:Float(scaleStart),
        z:Float(scaleStart)
      )
    case .Ended:
      scaleEnd = scaleStart
      if(dbg){println("pinch ended \(scaleEnd)")}
    case .Cancelled:
      break
    case .Failed:
      break
    case .Possible:
      break
    default:
      break
    }
  }

09-07 04:58