Ios 在Swift中,是否有人知道哪个物体被刷过?
我想将发送者Ios 在Swift中,是否有人知道哪个物体被刷过?,ios,swift,Ios,Swift,我想将发送者redBox传递给函数leftSwipeFunc。我不知道如何传递一个不是uisweegestureerecognizer的参数。如果你知道答案,请帮助我 let swipeLeft = UISwipeGestureRecognizer(target: self, action: Selector("leftSwipeFunc:")) swipeLeft.direction = UISwipeGestureRecognizerDirection.Left redBox.addGes
redBox
传递给函数leftSwipeFunc
。我不知道如何传递一个不是uisweegestureerecognizer
的参数。如果你知道答案,请帮助我
let swipeLeft = UISwipeGestureRecognizer(target: self, action: Selector("leftSwipeFunc:"))
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
redBox.addGestureRecognizer(swipeLeft)
func leftSwipeFunc(gesture:UISwipeGestureRecognizer){ }
您可以使用
locationInView
在视图中找到刷卡的位置
在您的leftSwipeFunc
中,找到触摸屏的CGPoint
,并检查它是否在所需视图中
let location = gesture.locationInView(self.view)
if CGRectContainsPoint(redBox, location) {
// redBox was swiped, do something
}
手势识别器有一个名为
view
的属性,该属性是它们附加到的UIView
。因此,您可以使用leftSwipeFunc
的内部来获取视图:
func leftSwipeFunc(gesture: UISwipeGestureRecognizer) {
let swipedView = gesture.view
// Assuming redBox is a property of your view controller
if swipedView == redBox {
println("the redBox was swiped")
} else {
println("some other view was swiped")
}
}