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

如何識別 UIScrollView 中的滑動手勢

How to recognize swipe gesture in UIScrollView(如何識別 UIScrollView 中的滑動手勢)
本文介紹了如何識別 UIScrollView 中的滑動手勢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試識別 UIScrollView 中的左/右滑動手勢.我試圖創建 UISwipeGestureRecognizers 并將它們與滾動視圖相關聯.它有效,但很少.大多數時候我沒有接到電話.為什么?

I'm trying to recognize left/right swipe gesture in a UIScrollView. I've tried to create UISwipeGestureRecognizers and associate them with the scroll view. It works but very rarely. Most of the time I do not get called. Why?

我怎樣才能可靠地向左/向右滑動來工作?我可以使用手勢識別器還是我必須自己在 touchesBegan/Ended

How can I reliably get swiping left/right to work? Can I use the gesture recognizers or do I have to somehow handle it myself in touchesBegan/Ended

謝謝

推薦答案

想通了.就我而言,我的 UIScrollView 包含一個允許縮放的 UIImage.顯然,這意味著啟用了滾動,并且 UIScrollView 無法區分旨在滾動和滑動的手勢(下一個、上一個圖像).

Figured it out. In my case, my UIScrollView contained a UIImage that I allowed zooming. Apparently that meant that scrolling is enabled and the UIScrollView had trouble distinguishing between gestures intended to scroll vs. swipe (next, previous image).

在我的例子中,關鍵是在圖像未放大時禁用滾動視圖中的滾動,并在放大時重新啟用它.這提供了預期的行為.

The key in my case, is to disable scrolling in the scroll view when the image is not zoomed in, and renabled it when it is zoomed in. This provides the expected behavior.

關鍵是在滾動視圖的委托中添加以下內容:

The critical piece is to put the following in the scroll view's delegate:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
  if (scrollView.zoomScale!=1.0) {
    // Zooming, enable scrolling
    scrollView.scrollEnabled = TRUE;
  } else {
    // Not zoomed, disable scrolling so gestures get used instead
    scrollView.scrollEnabled = FALSE;
  }
}

我還必須在禁用滾動的情況下初始化滾動視圖.要啟用縮放,只需在委托調用中提供圖像,

I also have to initialize the scroll view with scrolling disabled. To enable zooming, simply provide an image on a delegate call,

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  // Return the scroll view
  return myImage;
}

并在 viewDidLoad 中為縮放和設置手勢識別器設置一些參數

And set a few parms in viewDidLoad for the zooming and setup gesture recognizers as well

- (void)viewDidLoad {
  [super viewDidLoad];
  myScrollView.contentSize = CGSizeMake(myImage.frame.size.width, myImage.frame.size.height);
  myScrollView.maximumZoomScale = 4.0;
  myScrollView.minimumZoomScale = 1.0;
  myScrollView.clipsToBounds = YES;
  myScrollView.delegate = self;

  [myScrollView addSubview:myImage];
  [self setWantsFullScreenLayout:TRUE];

  myScrollView.scrollEnabled = FALSE; 
  UISwipeGestureRecognizer *recognizer = 
    [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
  recognizer.delaysTouchesBegan = TRUE;
  [myScrollView addGestureRecognizer:recognizer];
  [recognizer release];

  recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
  recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
  [myScrollView addGestureRecognizer:recognizer];
  [recognizer release];
  [myScrollView delaysContentTouches];
}

這篇關于如何識別 UIScrollView 中的滑動手勢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 91精品国产乱码久久久久久 | 国产精品久久久久久妇女6080 | av黄色国产| 亚洲一区二区三区四区五区中文 | 伊人网一区| 91青青草视频 | 日韩欧美福利视频 | 欧美激情一区 | 激情综合五月天 | 天天操天天射综合网 | 免费福利视频一区二区三区 | 国产精品视频一二三区 | 欧美一级视频 | 国际精品鲁一鲁一区二区小说 | 午夜天堂精品久久久久 | 在线播放国产一区二区三区 | 午夜小电影| 天天视频一区二区三区 | 奇米久久 | 久久久久久综合 | 午夜www | 伊人99 | 99久久精品免费看国产四区 | 欧美综合一区二区三区 | 国产免费观看一级国产 | 欧美一二区| 国产精品视频在线播放 | 国产精品一区在线观看 | 国产精品免费看 | 在线免费观看黄网 | 天天躁日日躁狠狠很躁 | 色综合av | 亚洲成人综合社区 | 少妇午夜一级艳片欧美精品 | 一区二区三区四区视频 | 四虎影院新网址 | 欧美日日 | 黄免费观看 | 久久精品一区 | 中文福利视频 | 中文字幕一区在线观看视频 |