根据背景点击

时间:2017-06-29 21:05:58

标签: ios swift

我有一个UIView

var transparentBackground = UIView()

单击按钮时,视图会显示一些属性

 @IBAction func UserViewImage(_ sender: UIButton) -> Void {

        self.transparentBackground = UIView(frame: UIScreen.main.bounds)
        self.transparentBackground.backgroundColor = UIColor(white: 0.0, alpha: 0.4)
        UIApplication.shared.keyWindow!.addSubview(self.transparentBackground)
        self.opaqueView = self.setupOpaqueView()
        self.transparentBackground.addSubview(opaqueView)
        UIApplication.shared.keyWindow!.bringSubview(toFront: self.transparentBackground)
        self.view.bringSubview(toFront: transparentBackground)

    }

当单击另一个按钮时,视图完全被解除,并带有一个名为removeAnimate的函数。

func handleOKButtonTapped(_ sender: UIButton){
    removeAnimate()

}

但是,我希望在单击背景(视图)时视图完全被解除,就像单击按钮时一样,所以我这样做了:

 override func viewDidLoad() {
        super.viewDidLoad()

            let gestureRecognizer = UITapGestureRecognizer(target: self, action:  #selector(removeAnimate))
            self.transparentBackground.addGestureRecognizer(gestureRecognizer)
}

但它不起作用,我不确定我做错了什么。不透明的blueBackground视图中有一个子视图。

 self.transparentBackground.addSubview(opaqueView)

1 个答案:

答案 0 :(得分:0)

这是我实现这个的方式:

val m = l.filter(_._3 != 0).map(a => a._2.split('.')(0) -> a._3)