久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UIScrollView子視圖中UILabels上的UITapGestureRecognizer不

UITapGestureRecognizer on UILabels in subview of UIScrollView not working(UIScrollView子視圖中UILabels上的UITapGestureRecognizer不起作用)
本文介紹了UIScrollView子視圖中UILabels上的UITapGestureRecognizer不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的 UIScrollView 的內容視圖中的 UITapGestureRecognizer 上的 UITapGestureRecognizer 沒有調用它的方法.

I have a problem where my UITapGestureRecognizer on my UILabels in a content view in my UIScrollView is not calling it's methods.

視圖層次結構如下:

  • 滾動視圖(UIScrollView)
    • 內容視圖(UIView)
      • testLabel (UILabel) - 這里是 UITapGestureRecognizer 的附加位置

      我已將代碼提煉成一個示例來突出問題

      I have distilled the code down to an example to highlight the problem

      // Set scrollview size - Added in Storyboad
      [scrollView setContentSize:CGSizeMake([arrayOfVerbs count]*self.view.frame.size.width, scrollView.contentSize.height)];
      [scrollView setCanCancelContentTouches:YES]; // Tried both yes and no
      [scrollView setPagingEnabled:YES];
      
      // Add content view
      UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)];
      [scrollView addSubview:contentView];
      
      // Add test UILabel
      UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
      [testLabel setBackgroundColor:[UIColor redColor]];
      [testLabel setText:@"Test touch"];
      [testLabel setUserInteractionEnabled:YES];
      [contentView addSubview:testLabel];
      
      // Add gesture recogniser
      UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playSound:)];
      singleTap.numberOfTapsRequired = 1;
      [testLabel addGestureRecognizer:singleTap];
      

      這是點擊手勢識別器應該調用的方法

      And this is the method that the tap gesture recogniser should call

      - (void)playSound:(UITapGestureRecognizer *)sender {
      
          NSLog(@"play sound");
      
          if(sender.state == UIGestureRecognizerStateEnded)
          {
              int pronounNumber = [sender.view tag];
              int exampleNumber = (int)sender.view.frame.origin.x%(int)self.view.frame.size.width;
      
              NSLog(@"Pronoun is %i and example is %i", pronounNumber, exampleNumber);
          }
      }
      

      當我嘗試觸摸 UILabel 時,從未調用此方法.

      This method is never called when I tried to touch on the UILabel.

      我已嘗試按照此 線程,但它仍然無法正常工作.

      I have tried setting the property canCancelContentTouches to both YES and NO on the scroll view as suggested by this thread, but it's still not working.

      奇怪的是,如果我在 scrollView 之外添加一個 UILabel,那么手勢識別器就會起作用!所以問題只出現在我的 contentView 中,它是我的 scrollView 的子視圖.

      The strange thing is, if I add a UILabel outside of the scrollView, then the gesture recogniser works! So the problem only occurs in my contentView which is a subview of my scrollView.

      我正在使用自動布局,如果這有什么不同嗎?

      I am using auto-layout, if that might be any difference?

      謝謝!

      推薦答案

      滾動視圖也有手勢識別器.默認情況下,任何時候只有 1 個手勢識別器可以處理觸摸.您需要讓自己成為手勢的代表,然后實現 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 以返回 YES.這將允許它與滾動視圖同時工作.

      The scroll view also has a gesture recogniser. By default, only 1 gesture recognizer can be handling touches at any one time. You need to make yourself the delegate of your gesture and then implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: to return YES. This will allow it to work at the same time as the scroll view.

      這篇關于UIScrollView子視圖中UILabels上的UITapGestureRecognizer不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 精品一区二区三区在线视频 | 国产在线资源 | 精品国产欧美 | 青草青草久热精品视频在线观看 | 国产精品永久免费观看 | 日本特黄a级高清免费大片 成年人黄色小视频 | 久久乐国产精品 | 噜啊噜在线 | 国产aaaaav久久久一区二区 | 国产日韩精品在线 | 欧美精品一区二区在线观看 | 国产伦精品一区二区三区视频金莲 | www精品美女久久久tv | 精品伦精品一区二区三区视频 | 一级aaaaaa毛片免费同男同女 | 国产成人久久av免费高清密臂 | www.五月婷婷.com | 欧美日韩久久精品 | 久草在线在线精品观看 | 黄色网页在线观看 | 欧美日韩专区 | 罗宾被扒开腿做同人网站 | 亚洲成人av在线播放 | 女人夜夜春 | 91人人在线| 中文av在线播放 | 在线免费国产视频 | 国产高清亚洲 | 国产精品污www在线观看 | 欧美日韩电影一区二区 | 欧美日韩一 | 国产在线观看 | 国产精品视频久久久 | 欧美日本久久 | 欧美日韩国产在线观看 | 午夜国产 | 国产久 | 蜜桃视频在线观看免费视频网站www | 五月天婷婷激情 | 亚洲国产一区二区视频 | 亚洲欧美在线视频 |