1. <legend id='GkY1C'><style id='GkY1C'><dir id='GkY1C'><q id='GkY1C'></q></dir></style></legend>

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

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

        <tfoot id='GkY1C'></tfoot>

        如果按下子视图的按钮,如何取消 UIGestureRecognizer

        时间:2023-07-07
      1. <tfoot id='Lema6'></tfoot>
      2. <i id='Lema6'><tr id='Lema6'><dt id='Lema6'><q id='Lema6'><span id='Lema6'><b id='Lema6'><form id='Lema6'><ins id='Lema6'></ins><ul id='Lema6'></ul><sub id='Lema6'></sub></form><legend id='Lema6'></legend><bdo id='Lema6'><pre id='Lema6'><center id='Lema6'></center></pre></bdo></b><th id='Lema6'></th></span></q></dt></tr></i><div id='Lema6'><tfoot id='Lema6'></tfoot><dl id='Lema6'><fieldset id='Lema6'></fieldset></dl></div>

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

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

                  本文介绍了如果按下子视图的按钮,如何取消 UIGestureRecognizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在努力从手势识别器中获得我想要的行为,特别是如果其他手势被触发则取消某些手势.

                  I am struggling to get the behaviour I would like from the gesture recognisers, specifically cancelling certain gestures if others have fired.

                  我有一个 scrollView 设置为分页和每个页面中的多个子视图.如果用户点击页面的右侧或左侧,我添加了一个触摸手势识别器以滚动到下一页或上一页.

                  I have a scrollView set to paging and multiple subviews in each page. I have added a touch gesture recogniser to scroll to the next or prev page if the user taps to the right or left of the page.

                      // Add a gesture recogniser turn pages on a single tap at the edge of a page
                      UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];
                      tapGesture.cancelsTouchesInView = NO;
                      [self addGestureRecognizer:tapGesture];
                      [tapGesture release];
                  

                  还有我的手势处理程序:

                  and my gesture handler:

                  - (void) tapGestureHandler:(UIGestureRecognizer *) gestureRecognizer {
                      const CGFloat kTapMargin = 180;
                  
                      // Get the position of the point tapped in the window co-ordinate system
                      CGPoint tapPoint = [gestureRecognizer locationInView:nil];
                  
                      // If the tap point is to the left of the page then go back a page
                      if (tapPoint.x > (self.frame.size.width - kTapMargin)) [self scrollRectToVisible:pageViewRightFrame animated:YES];
                  
                      // If the tap point is to the right of the page then go forward a page
                      else if (tapPoint.x < kTapMargin) [self scrollRectToVisible:pageViewLeftFrame animated:YES];
                  }
                  

                  一切都很好,除了我在页面上有一个带有按钮的子视图.如果用户触摸 subView 上的按钮,我希望能够忽略点击翻页,但我不知道该怎么做.

                  All works well, except where I have a subview on the page that has buttons in it. I want to be able to ignore the tap to turn the page if the user touches a button on the subView and I can't figure out how to do this.

                  干杯

                  戴夫

                  推荐答案

                  最终对我来说效果最好的解决方案是使用 hitTest 来确定点击手势位置下方是否有任何按钮.如果有则忽略其余的手势代码.

                  The solution that worked the best for me in the end was to use the hitTest to determine if there were any buttons underneath the location of the tap gesture. If there are then just ignore the rest of the gesture code.

                  似乎运作良好.想知道我所做的是否有任何问题.

                  Seems to work well. Would like to know if there are any gotchas with what I have done.

                  - (void) tapGestureHandler:(UIGestureRecognizer *) gestureRecognizer {
                      const CGFloat kTapMargin = 180;
                  
                      // Get the position of the point tapped in the window co-ordinate system
                      CGPoint tapPoint = [gestureRecognizer locationInView:nil];
                  
                      // If there are no buttons beneath this tap then move to the next page if near the page edge
                      UIView *viewAtBottomOfHeirachy = [self.window hitTest:tapPoint withEvent:nil];
                      if (![viewAtBottomOfHeirachy isKindOfClass:[UIButton class]]) {
                  
                          // If the tap point is to the left of the page then go back a page
                          if (tapPoint.x > (self.bounds.size.width - kTapMargin)) [self scrollRectToVisible:pageViewRightFrame animated:YES];
                  
                          // If the tap point is to the right of the page then go forward a page
                          else if (tapPoint.x < kTapMargin) [self scrollRectToVisible:pageViewLeftFrame animated:YES];
                      }   
                  }
                  

                  这篇关于如果按下子视图的按钮,如何取消 UIGestureRecognizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何让文本适合 UIButton? 下一篇:以编程方式向 UIButton 标签添加阴影

                  相关文章

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

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

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