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

    2. <small id='UbxZT'></small><noframes id='UbxZT'>

      UIButton TouchUpInside 触摸位置

      时间:2023-07-07
        <bdo id='zWLRk'></bdo><ul id='zWLRk'></ul>
          <tbody id='zWLRk'></tbody>
      • <small id='zWLRk'></small><noframes id='zWLRk'>

      • <tfoot id='zWLRk'></tfoot>

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

                问题描述

                所以我有一个大的UIButton,它是一个UIButtonTypeCustom,按钮目标是为UIControlEventTouchUpInside 调用的.我的问题是如何确定触摸发生在 UIButton 的哪个位置.我想要这个信息,这样我就可以从触摸位置显示一个弹出窗口.这是我尝试过的:

                So I have a large UIButton, it is a UIButtonTypeCustom, and the button target is called for UIControlEventTouchUpInside. My question is how can I determine where in the UIButton the touch occured. I want this info so I can display a popup from the touch location. Here is what I've tried:

                UITouch *theTouch = [touches anyObject];
                CGPoint where = [theTouch locationInView:self];
                NSLog(@" touch at (%3.2f, %3.2f)", where.x, where.y);
                

                和其他各种迭代.按钮的目标方法通过 sender 从中获取信息:

                and various other iterations. The button's target method get info from it via the sender:

                    UIButton *button = sender;
                

                那么有什么方法可以使用类似:button.touchUpLocation?

                So is there any way I could use something like: button.touchUpLocation?

                我在网上查了一下,没有找到类似的东西,所以提前谢谢.

                I looked online and couldn't find anything similar to this so thanks in advance.

                推荐答案

                UITouch *theTouch = [touches anyObject];
                CGPoint where = [theTouch locationInView:self];
                NSLog(@" touch at (%3.2f, %3.2f)", where.x, where.y);
                

                这是正确的想法,只是这段代码可能在视图控制器的动作中,对吧?如果是这样,那么 self 指的是视图控制器而不是按钮.您应该将指向按钮的指针传递到 -locationInView:.

                That's the right idea, except that this code is probably inside an action in your view controller, right? If so, then self refers to the view controller and not the button. You should be passing a pointer to the button into -locationInView:.

                这是您可以在视图控制器中尝试的经过测试的操作:

                Here's a tested action that you can try in your view controller:

                - (IBAction)buttonPressed:(id)sender forEvent:(UIEvent*)event
                {
                    UIView *button = (UIView *)sender;
                    UITouch *touch = [[event touchesForView:button] anyObject];
                    CGPoint location = [touch locationInView:button];
                    NSLog(@"Location in button: %f, %f", location.x, location.y);
                }
                

                这篇关于UIButton TouchUpInside 触摸位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在分段控制按钮中永久取消选择分段,直到再次单击它 下一篇:在 UIButton 中使用 UIBarButtonItem 图标

                相关文章

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

                1. <small id='oRUNC'></small><noframes id='oRUNC'>

                    <tfoot id='oRUNC'></tfoot>