swift UITapgestureRecognitor过程参数

swift UITapgestureRecognitor过程参数,swift,uitapgesturerecognizer,Swift,Uitapgesturerecognizer,我有许多以编程方式创建的按钮,可以随时更改。我的轻拍手势: let apriVideoGesture = UITapGestureRecognizer(target: self, action: #selector(PrincipaleController.apriVideo(_:))) cont.addGestureRecognizer(apriVideoGesture) func apriVideo(sender : UITapGestureRecognizer){ } 如何传递参数?

我有许多以编程方式创建的按钮,可以随时更改。我的轻拍手势:

let apriVideoGesture = UITapGestureRecognizer(target: self, action: #selector(PrincipaleController.apriVideo(_:)))
cont.addGestureRecognizer(apriVideoGesture)

func apriVideo(sender : UITapGestureRecognizer){

}
如何传递参数?像这样的事情:

let apriVideoGesture = UITapGestureRecognizer(target: self, action: #selector(PrincipaleController.apriVideo(stringa : "ciao")))
cont.addGestureRecognizer(apriVideoGesture)

func apriVideo(sender : UITapGestureRecognizer, stringa : String){

}

对不起,我的英语不好,我是意大利人。首先,如果您使用的是按钮,那么为什么要添加点击手势?您可以将目标添加到它,如下所示

btn.addTarget(self, action: #selector(self.btnPressed(_:)), forControlEvents: .TouchDragInside)
但您仍然可以使用轻触手势实现您的目标

如你所坚持的那样使用UIView

class ViewController: UIViewController {

let arrayOfSongsURL : [String] = [String]()
let startingTag = 100
override func viewDidLoad() {
    super.viewDidLoad()
    let height : CGFloat = 100
    let width : CGFloat = 100
    (arrayOfSongsURL as NSArray).enumerateObjectsUsingBlock { (url, index, finished) -> Void in

        let v = UIView(frame: CGRectMake(0, CGFloat(index) * height, width, height))
        v.tag = self.startingTag + index

        v.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTapGesture(_:))))
        self.view.addSubview(v)
    }
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func handleTapGesture(gesture : UITapGestureRecognizer)
{
    let v = gesture.view!
    let tag = v.tag
    let songURL = arrayOfSongsURL[tag - startingTag]

    //Do what you want to do with songURL
}

}

不,你不能,但请告诉我传递这些信息的目的,这样我就可以告诉你一些替代方法。我需要传递一个带有URL的字符串。该页面是在服务器收到的一些文章的基础上创建的,我需要在容器的基础上打开特定的页面。请按Lex让我到家,我会为您做到这一点的。谢谢,我很抱歉,请告诉我您想要创建什么类型的视图,这就是我如何获得想法的方法。我也可以使用UIVIew来实现它?是的,您可以使用UIVIew和TapPassive来实现,您不能将目标添加到UIVIew,因为我已经向您展示了您不了解的内容。如果没有按钮的“添加目标”,我如何实现它。因为我只使用UIViewYou可以对视图进行子类化,并创建一个变量来存储url并访问相同的url