本文介绍了捏手势比例重置为1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在看这个仓库
https://github.com/mmohsin991/gestures/blob/master/gestures/ViewController.swift
和本例
http://www.raywenderlich.com/50398/opengl-es-转换手势
我有以下代码
@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 杂乱无章.
Initially, the pinch works and zooms in and out but then the scale resets to 1. Converting the openGL code http://www.raywenderlich.com/50398/opengl-es-transformations-gestures is messy.
有人可以帮助转换此代码吗?
Can someone help convert this code?
推荐答案
这有效.
在某处初始化变量.
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
}
}
这篇关于捏手势比例重置为1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!