久久久久久久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)
主站蜘蛛池模板: 国产精品一区在线 | 日韩在线视频一区二区三区 | 九九热在线视频 | 国产98色在线 | 日韩 | 中文字幕视频在线看5 | 国产精品久久 | 伊人精品 | 亚洲欧美在线一区 | 日韩成人免费av | 欧美性影院 | 第一区在线观看免费国语入口 | 欧美成人一区二区三区 | 激情av在线 | 国产黄色大片网站 | 欧美成ee人免费视频 | 中文字幕第5页 | 最新免费黄色网址 | 日韩视频一区二区三区 | 亚洲欧美在线免费观看 | 一级做a爰片性色毛片16 | 男女羞羞免费网站 | 日韩在线一区二区三区 | 日韩精品一区二区三区四区 | 日韩欧美一区二区三区在线播放 | 韩日一区 | 成人福利在线 | 日韩中文字幕在线观看 | 黄a免费网络 | 伊人精品一区二区三区 | 久久精品亚洲 | 日韩不卡一区二区 | www.精品国产 | 久久久成人免费一区二区 | 交专区videossex农村 | 国产高清精品在线 | 国产成人精品一区二区三 | 亚洲天堂男人的天堂 | 日韩高清一区 | 国产福利资源 | zzzwww在线看片免费 | 国产精品久久久久久吹潮日韩动画 |