ios – 如何在故事板上单击UIImageView(swift)

ios – 如何在故事板上单击UIImageView(swift),第1张

概述我是新来的(和一般的 Xcode开发),我想知道如何在故事板上单击ImageView.我想要做的是使其点击时,它显示另一个视图控制器. 您可以添加tapGesture.这是代码: class ViewController: UIViewController {@IBOutlet weak var imageView: UIImageView!override func viewDidLoad 我是新来的(和一般的 Xcode开发),我想知道如何在故事板上单击ImageVIEw.我想要做的是使其点击时,它显示另一个视图控制器.解决方法 您可以添加tapGesture.这是代码:
class VIEwController: UIVIEwController {@IBOutlet weak var imageVIEw: UIImageVIEw!overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    // create tap gesture recognizer    let tapGesture = UITapGestureRecognizer(target: self,action: "imageTapped:")    // add it to the image vIEw;    imageVIEw.addGestureRecognizer(tapGesture)    // make sure imageVIEw can be interacted with by user    imageVIEw.userInteractionEnabled = true}func imageTapped(gesture: UIGestureRecognizer) {    // if the tapped vIEw is a UIImageVIEw then set it to imagevIEw    if let imageVIEw = gesture.vIEw as? UIImageVIEw {        println("Image Tapped")        //Here you can initiate your new VIEwController        }    }}

Swift 3.0

class VIEwController: UIVIEwController {    @IBOutlet weak var imageVIEw: UIImageVIEw!    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // create tap gesture recognizer        let tapGesture = UITapGestureRecognizer(target: self,action: #selector(VIEwController.imageTapped(gesture:)))        // add it to the image vIEw;        imageVIEw.addGestureRecognizer(tapGesture)        // make sure imageVIEw can be interacted with by user        imageVIEw.isUserInteractionEnabled = true    }    func imageTapped(gesture: UIGestureRecognizer) {        // if the tapped vIEw is a UIImageVIEw then set it to imagevIEw        if (gesture.vIEw as? UIImageVIEw) != nil {            print("Image Tapped")            //Here you can initiate your new VIEwController        }    }}
总结

以上是内存溢出为你收集整理的ios – 如何在故事板上单击UIImageView(swift)全部内容,希望文章能够帮你解决ios – 如何在故事板上单击UIImageView(swift)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1096691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存