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

        <bdo id='Mlblw'></bdo><ul id='Mlblw'></ul>

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

      <tfoot id='Mlblw'></tfoot>

        奇怪的 UIButton 行为:这正常吗?

        时间:2023-07-06
        <tfoot id='gFUfl'></tfoot>

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

            <tbody id='gFUfl'></tbody>

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

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

                1. 本文介绍了奇怪的 UIButton 行为:这正常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个简单的 UIButton,想要在用户触摸它时做某事,但随后将手指移到按钮外并未触摸屏幕.所以看来我需要监听 UIControlEventTouchUpOutside 事件.

                  I have a simple UIButton and want to do something when the user touches it, but then moves the finger outside the button and untouches the screen. So that seems like I need to listen for the UIControlEventTouchUpOutside event.

                  在我的视图控制器中,我这样做了:

                  In my view controller, I did this:

                  UIButton *bt = [[UIButton alloc] initWithFrame:rect];
                  [bt setBackgroundColor:[UIColor whiteColor]];
                  [bt addTarget:self action:@selector(onTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside];
                  [self.view addSubview:bt];
                  

                  以及对应的动作方法:

                  - (void)onTouchUpOutside {
                      NSLog(@"touchUpOutside");
                  }
                  

                  现在猜猜是什么?我触摸按钮,然后将手指拖到按钮外面,取消触摸屏幕并且没有记录任何消息.事实上,它会记录我发生了 UIControlEventTouchUpInside 事件,即使我的手指并没有真正位于按钮上方.似乎我可以在触摸时将手指围绕该按钮移动大约 150% 的宽度和高度,当我不触摸时它会告诉我手指在按钮中.但是当我把它移得很远(=足够远)时,我确实收到了touchUpOutside"日志消息.那么这只是苹果的另一个疯狂,比如延迟 -touchesMoved 和类似的东西吗?还是我做错了什么?

                  now guess what? I touch the button, then drag the finger outside of it, untouch the screen and no message is logged. Indeed it would log me that an UIControlEventTouchUpInside event has happened, even if my finger is not really above the button. It seems like I can move the finger about 150% of the width and hight around that button while touching, and it will tell me that the finger was in the button when I untouch. But when I move it very far away (= far away enough), I do get that "touchUpOutside" log message. So is that just another madness from apple, like the delay in -touchesMoved and stuff like that? Or did I do something wrong?

                  推荐答案

                  touchUpInside 会在您将手指移到按钮外一点时触发,因为人们的手指很大且不精确.

                  touchUpInside is fired when you move your finger a bit outside the button, because people have big, imprecise fingers.

                  如果您真的想覆盖此行为,请在 touchUpInside 处理程序中检查触摸的位置,然后如果在按钮之外触摸它,则直接调用 touchUpOutside 处理程序界限.

                  If you really want to override this behaviour, in a touchUpInside handler check the location of the touch, then call the touchUpOutside handler directly if the touch it outside the button's bounds.

                  这篇关于奇怪的 UIButton 行为:这正常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带标签的按钮 下一篇:如何在单击 UIButton 时添加 UITextfield 并使其可编辑

                  相关文章

                  <legend id='lBhIK'><style id='lBhIK'><dir id='lBhIK'><q id='lBhIK'></q></dir></style></legend>
                2. <tfoot id='lBhIK'></tfoot>
                3. <small id='lBhIK'></small><noframes id='lBhIK'>

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