2017-04-15 161 views
0

我已經成功地在我的UILabel上添加捏手勢,我可以增加和減小大小。 UILabel也有一個平移和旋轉手勢識別器,並且都在工作,但我希望捏手勢不僅在兩個手指都在對象中工作,而且如果只有一個手指在對象上而另一個在外面(在如果物體太小而無法用2個手指按壓)。 如果我試圖做到這一點,它會觸發平移手勢,而不是捏。捏手勢一個手指ios

這裏是我的功能設置識別到我的UILabel:

func setGestures(object: UIView){ 
     // recognizer for the dragging move 
     let panGesture = UIPanGestureRecognizer(target: self, action: #selector(self.wasDragged(gesture:))) 
     let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selector(self.wasRotated(gesture:))) 
     var pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(self.wasPinched(gesture:))) 

     // set gestures for the text label 
     object.addGestureRecognizer(panGesture) 
     object.addGestureRecognizer(pinchGesture) 
     object.addGestureRecognizer(rotateGesture) 
     object.isUserInteractionEnabled = true 
     object.isMultipleTouchEnabled = true 
} 

誰能幫助?謝謝。

回答

0

將捏合手勢識別器添加到UIView的超級視圖。如果您有多個視圖必須對捏合作出反應,您需要確定手指所處的哪兩個視圖,並決定哪個視圖會發生變化。