<i id='fBXC4'><tr id='fBXC4'><dt id='fBXC4'><q id='fBXC4'><span id='fBXC4'><b id='fBXC4'><form id='fBXC4'><ins id='fBXC4'></ins><ul id='fBXC4'></ul><sub id='fBXC4'></sub></form><legend id='fBXC4'></legend><bdo id='fBXC4'><pre id='fBXC4'><center id='fBXC4'></center></pre></bdo></b><th id='fBXC4'></th></span></q></dt></tr></i><div id='fBXC4'><tfoot id='fBXC4'></tfoot><dl id='fBXC4'><fieldset id='fBXC4'></fieldset></dl></div>

      <small id='fBXC4'></small><noframes id='fBXC4'>

        <bdo id='fBXC4'></bdo><ul id='fBXC4'></ul>
      <legend id='fBXC4'><style id='fBXC4'><dir id='fBXC4'><q id='fBXC4'></q></dir></style></legend>

      1. <tfoot id='fBXC4'></tfoot>
      2. 在 Swift 中将 UIButton 覆盖在 UIWebView 上

        时间:2023-07-06

              <small id='pn2Bq'></small><noframes id='pn2Bq'>

                • <bdo id='pn2Bq'></bdo><ul id='pn2Bq'></ul>
                • <tfoot id='pn2Bq'></tfoot>
                    <tbody id='pn2Bq'></tbody>

                  <i id='pn2Bq'><tr id='pn2Bq'><dt id='pn2Bq'><q id='pn2Bq'><span id='pn2Bq'><b id='pn2Bq'><form id='pn2Bq'><ins id='pn2Bq'></ins><ul id='pn2Bq'></ul><sub id='pn2Bq'></sub></form><legend id='pn2Bq'></legend><bdo id='pn2Bq'><pre id='pn2Bq'><center id='pn2Bq'></center></pre></bdo></b><th id='pn2Bq'></th></span></q></dt></tr></i><div id='pn2Bq'><tfoot id='pn2Bq'></tfoot><dl id='pn2Bq'><fieldset id='pn2Bq'></fieldset></dl></div>
                  <legend id='pn2Bq'><style id='pn2Bq'><dir id='pn2Bq'><q id='pn2Bq'></q></dir></style></legend>
                • 本文介绍了在 Swift 中将 UIButton 覆盖在 UIWebView 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我有一个加载 UIWebView 的视图,我想覆盖 UIButton 用户可以点击以转到另一个视图.

                  So I have a view that loads a UIWebView and I want to overlay UIButton the user can tap on to go to another view.

                  我设法将按钮放在网络视图上,但我似乎无法点击它.

                  I managed to place the button over the web view but I can't seem to be able to tap on it.

                  这是我的代码:

                  class ButtonView: UIView {
                      var button: UIButton!
                  
                      override init(frame: CGRect) {
                          super.init(frame: frame)
                  
                          button = UIButton(frame: CGRectMake(0, 0, 50, 50))
                          button.layer.zPosition = 10
                          self.addSubview(button)
                      }
                  
                      required init(coder aDecoder: NSCoder) {
                          fatalError("Init(coder:) has not been implemented")
                      }    
                  }
                  
                  class MyViewController : UIViewController, UIWebViewDelegate {
                  
                      var buttonView = ButtonView()
                      @IBOutlet weak var webView: UIWebView!
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          self.loadWebView() //This just loads a url to the web view...
                  
                          webView.layer.zPosition = 1
                          buttonView = ButtonView(frame: CGRectMake(0, 0, 100, 100))
                          buttonView.layer.zPosition = 100
                          buttonView.button.addTarget(self, action: "buttonEvent:", forControlEvents: UIControlEvents.TouchUpInside)
                          self.view.addSubview(buttonView)
                      }
                  
                      func buttonEvent(sender: AnyObject!){
                          println("Tap detected!")
                      }
                  }
                  

                  所以这会按预期在 web 视图顶部显示按钮,但我无法点击它.

                  So this displays the button on top of the web view as expected but I can't tap on it.

                  虽然如果我隐藏网页视图,我可以毫无问题地点击按钮

                  Although if I hide the web view I can tap on the button without any problems

                  这是 zPosition 问题吗?还是别的什么?

                  Is this a zPosition problem? or something else?

                  推荐答案

                  只要你更换它就可以工作:

                  It could work as it is as long as you replace:

                  self.view.addSubview(buttonView)
                  

                  与:

                  webView.addSubview(buttonView)
                  

                  所以基本上将包含按钮的视图添加到 web 视图中

                  So basically add the view containing the button to the web view instead

                  这篇关于在 Swift 中将 UIButton 覆盖在 UIWebView 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我的子视图中的 UIButton 不起作用 下一篇:Swift:UIButton textLabel.text 值在 switch 语句中不可用

                  相关文章

                  <i id='7UoxX'><tr id='7UoxX'><dt id='7UoxX'><q id='7UoxX'><span id='7UoxX'><b id='7UoxX'><form id='7UoxX'><ins id='7UoxX'></ins><ul id='7UoxX'></ul><sub id='7UoxX'></sub></form><legend id='7UoxX'></legend><bdo id='7UoxX'><pre id='7UoxX'><center id='7UoxX'></center></pre></bdo></b><th id='7UoxX'></th></span></q></dt></tr></i><div id='7UoxX'><tfoot id='7UoxX'></tfoot><dl id='7UoxX'><fieldset id='7UoxX'></fieldset></dl></div>

                    <tfoot id='7UoxX'></tfoot>

                        <bdo id='7UoxX'></bdo><ul id='7UoxX'></ul>

                    1. <small id='7UoxX'></small><noframes id='7UoxX'>

                    2. <legend id='7UoxX'><style id='7UoxX'><dir id='7UoxX'><q id='7UoxX'></q></dir></style></legend>