久久久久久久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)
主站蜘蛛池模板: 久久久久一区 | 国产一区 日韩 | 一区二区三区在线观看视频 | 女人夜夜春 | 日韩欧美国产精品 | 欧美成人高清视频 | 国产精品国产三级国产a | 国产精品夜色一区二区三区 | 国产精品久久久久影院色老大 | 国产视频一二三区 | www视频在线观看 | 免费黄色a视频 | 97精品超碰一区二区三区 | 精品免费国产一区二区三区 | 亚洲精品一区二区三区四区高清 | 日韩在线一区二区三区 | 亚洲久草| 五月天婷婷综合 | 亚洲欧美精品在线 | av中文字幕网 | 精品国产欧美 | av在线免费看网址 | 天堂av中文 | 天堂网avav| 性精品| 国产成人精品一区二区三区在线 | 国产美女精品 | 成人精品一区二区 | 欧美日韩a | 国产免费一区二区 | 国产一区免费 | 亚洲精品视频一区 | 欧美日韩在线综合 | 日韩中文在线观看 | 成人在线观看免费观看 | 日韩成人在线视频 | 精品国产一区二区国模嫣然 | 国产精品国产三级国产aⅴ无密码 | 色站综合| 精品乱码一区二区 | 日本国产精品视频 |