在UIViewcontroller中具有自定义UIView [英] having a custom UIView in a UIViewcontroller

查看:158
本文介绍了在UIViewcontroller中具有自定义UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个UIView类,并在viewcontroller内部实现了它.但是,在视图控制器中还有其他一些我想能够与之交互的东西,但是由于附加了视图,所以我无法做到这一点.

I created a UIView class and implemented it inside a viewcontroller. However, I have a some other things in the view controller that I want to be able to interact with but I cannot do that because of the attached view.

当自定义uiview存在于viewcontroller中时,我如何与基本viewcontroller交互

how do I interact with the base viewcontroller while the custom uiview is present in the viewcontroller

var tripView: TripView!

    override func viewDidLoad() {
        super.viewDidLoad()
        tripView = TripView(frame: CGRect.zero)
        self.view.addSubview(tripView)
        // AutoLayout
        tripView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets.zero)

    }

推荐答案

您可以

class TripView:UIView {

    // add this
class TransView:UIView {

    var imgV1:UIImageView!
    var imgV2:UIImageView!

    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {

        return imgV1.frame.contains(point) ||  imgV2.frame.contains(point) // or ![imgV1,imgV2].filter{$0.frame.contains(point)}.isEmpty
    }

}

这篇关于在UIViewcontroller中具有自定义UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆