我有UIViewController
,其中我添加了UIView
。在那UIView
中,我通过编程添加了一些UIImageView
。我需要的是当我点击它在新的UIViewController
中显示的图像时。
ViewController : UIViewController {
myUIview[[imageview] [ ] [ ] [ ] [ ] ]
}
答案 0 :(得分:0)
如果我理解正确,当用户按下UIImageView时,你想要转到另一个ViewController。所以这是我使用UITapGestureRecognizer的解决方案(将此代码放在viewDidLoad中):
yourImageView.isUserInteractionEnabled = true
let yourImageTapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.test(_ :)))
yourImageTapGesture.delegate = self
yourImageTapGesture.numberOfTapsRequired = 1
yourImageView.addGestureRecognizer(yourImageTapGesture)
然后在你的ViewController中你必须进行功能测试,当有人点击你的UIImageView时会触发它:
func test(_ sender: AnyObject) {
self.performSegue(withIdentifier: "YourSegueName",sender: self)
}
重要提示:“YourSegueName”是故事板中您的Segue的标识符。你可以点击你的Segue:
来设置它请记住,您的ViewController需要从另一个类继承:
class ViewController: UIViewController, UIGestureRecognizerDelegate {...}