在Swift中,无论如何都知道要刷哪个对象? [英] In Swift is there anyway to know which object was swiped?
本文介绍了在Swift中,无论如何都知道要刷哪个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将发送方redBox
传递给功能leftSwipeFunc
.我不知道如何传递不是UISwipeGestureREcognizer
的参数.如果您知道答案,请帮助我.
I want to pass the sender redBox
to the function leftSwipeFunc
. I don't know how to pass a parameter that's not UISwipeGestureREcognizer
. Please help me if you know the answer.
let swipeLeft = UISwipeGestureRecognizer(target: self, action: Selector("leftSwipeFunc:"))
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
redBox.addGestureRecognizer(swipeLeft)
func leftSwipeFunc(gesture:UISwipeGestureRecognizer){ }
推荐答案
手势识别器具有一个称为view
的属性,该属性是它们所附加的UIView
.因此,您可以在leftSwipeFunc
内部使用该视图来获取视图:
Gesture recognizers have a property called view
that is the UIView
that they are attached to. So, you can use that inside of leftSwipeFunc
to get the view:
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")
}
}
这篇关于在Swift中,无论如何都知道要刷哪个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文