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

UIScrollView 只能用一根手指滾動

UIScrollView scrolling only with one finger(UIScrollView 只能用一根手指滾動)
本文介紹了UIScrollView 只能用一根手指滾動的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

iOS7 &iOS8

iOS7 & iOS8

我需要在 UIScrollview 中禁用兩指或三指滾動.

I need to disable 2 or three fingers scrolling in UIScrollview.

我試過了:

[self.scrollView.panGestureRecognizer setMaximumNumberOfTouches:1];
[self.scrollView.panGestureRecognizer setMinimumNumberOfTouches:1];

但它沒有效果.仍然可以用兩根手指滾動.

But it has no effect. It is still possible to scroll with 2 fingers.

如果我嘗試將 max 和 min 設置為 2.一個手指滾動被禁用但 3 個手指滾動可能:(

If i tried to set max and min to 2. One finger scrolling was disabled but 3 fingers scrolling possible :(

我也試過了,但沒有成功:

I tried this too, but without success:

for (UIGestureRecognizer* pan in self.scrollView.gestureRecognizers) {
        OTTNSLog(@"touches: %ld", (unsigned long)pan.numberOfTouches);
        if ([pan isKindOfClass:[UIPanGestureRecognizer class]])
        {
            UIPanGestureRecognizer *mpanGR = (UIPanGestureRecognizer *) pan;
            mpanGR.minimumNumberOfTouches = 1;
            mpanGR.maximumNumberOfTouches = 1;

        }

        if ([pan isKindOfClass:[UISwipeGestureRecognizer class]])
        {
            UISwipeGestureRecognizer *mswipeGR = (UISwipeGestureRecognizer *) pan;
            mswipeGR.numberOfTouchesRequired = 1;
        }

    }

有人知道,它是如何解決這個問題的嗎?

Does anybody know, how it solve this ?

謝謝.

推薦答案

問題:

UIPanGestureRecognizerUIScrollView 的底層時 - 不幸的是,這也會影響 UIPageViewController - maximumNumberOfTouches 未按預期運行,minimumNumberOfTouches 但是總是正確地限制下限.

When the UIPanGestureRecognizer is underlying a UIScrollView - which unfortunately does also effect UIPageViewController - the maximumNumberOfTouches is not behaving as expected, the minimumNumberOfTouches however always limits the lower end correctly.

在監控這些參數時,它們會報告正確的值——它們似乎在做自己的工作——只是 UIScrollView 本身不尊重它們并忽略它們的設置!

When monitoring these parameters they report back correct values - they seem to do their job - it's just that UIScrollView itself doesn't honor them and ignores their settings!

解決方案:

minimumNumberOfTouches 設置為所需的值,例如1 和 - 非常重要 - maximumNumberOfTouches 到 2 !!!

Set the minimumNumberOfTouches to the desired value e.g. 1 and - very importantly - the maximumNumberOfTouches to 2 !!!

myScrollView.panGestureRecognizer.minimumNumberOfTouches = 1;
myScrollView.panGestureRecognizer.maximumNumberOfTouches = 2;

在滾動視圖的@interface 聲明中符合 UIGestureRecognizerDelegate 協議.您不必為 UIScrollView 設置 panGestureRecognizer.delegate !!!委托已經設置,因為 UIScrollView 需要是它自己的 pan/pinchGestureRecognizer 的委托.

Conform to the UIGestureRecognizerDelegate protocol in your scrollView's @interface declaration. You don't have to set the panGestureRecognizer.delegate for a UIScrollView!!! The delegate is already set because UIScrollView requires to be the delegate of its own pan/pinchGestureRecognizer.

然后實現UIGestureRecognizer委托方法:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    NSLog(@"%d", gestureRecognizer.numberOfTouches);
    NSLog(@"%@", gestureRecognizer.description);

        if (gestureRecognizer == self.panGestureRecognizer) {
            if (gestureRecognizer.numberOfTouches > 1) {
                return NO;
            } else {
                return YES;
            }
        } else {
            return YES;
        }
    }
}

<小時>

更安全的版本:

如果您有一個自定義的 scrollView 類并且想要非常安全,您還可以再添加一行代碼來消除與其他 scrollView 的歧義:

If you have a custom scrollView class and wanna be on the VERY safe side you can also add one more line of code to disambiguate against other scrollViews:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    NSLog(@"%d", gestureRecognizer.numberOfTouches);
    NSLog(@"%@", gestureRecognizer.description);

    if ([gestureRecognizer.view isMemberOfClass:[MY_CustomcrollView class]]) {
        if (gestureRecognizer == self.panGestureRecognizer) {
            if (gestureRecognizer.numberOfTouches > 1) {
                return NO;
            } else {
                return YES;
            }
        } else {
            return YES;
        }
    } else {
        return YES;
    }
}

<小時>

附加信息:

NSLog 告訴您觸摸的次數.如果您將 minmax 設置為相同的值(如上例中的 1),if-loop 永遠不會被觸發... ;-)

The NSLogs tell you the number of touches. If you set both the min and max to the same value (like 1 in the example above) the if-loop would never be triggered... ;-)

這就是為什么 maximumNumberOfTouches 必須至少為 minimumNumberOfTouches + 1

That is why maximumNumberOfTouches has to be at least minimumNumberOfTouches + 1

panGestureRecognizer.minimumNumberOfTouches = 1;
panGestureRecognizer.maximumNumberOfTouches = minimumNumberOfTouches + 1;

<小時>

極客部分:

for (UIView *view in self.view.subviews) {
    if ([view isKindOfClass:[UIScrollView class]]) {
        NSLog(@"myPageViewController - SCROLLVIEW GESTURE RECOGNIZERS: %@", view.gestureRecognizers.description);
        ((UIPanGestureRecognizer *)view.gestureRecognizers[1]).minimumNumberOfTouches = 1;
        ((UIPanGestureRecognizer *)view.gestureRecognizers[1]).maximumNumberOfTouches = 2;
    }
}

這是訪問負責 UIPageViewController 分頁的底層滾動視圖的方法.將此代碼放在例如UIPageViewController(自身)的viewDidLoad:.

如果您根本無法訪問滾動視圖 - 就像動態 UITableViewCell 中的 UIPageViewController 在運行時發生創建和單元重用并且沒有插座可以在其 contentViews 上設置 - 在 UIScrollView 上放置一個類別并在那里覆蓋委托方法.不過要小心!這會影響您的應用程序中的每個滾動視圖 - 所以要像上面的更安全"示例中那樣進行適當的自省(類檢查)...... ;-)

If you don't have access to the scrollView at all - like for a UIPageViewController in a dynamic UITableViewCell where creation and cell reuse happens at runtime and no outlets can be set on its contentViews - put a category on UIScrollView and override the delegate method there. But be careful! This effects every scrollView in your application - so do proper introspection (class-checking) like in my 'EVEN SAFER' example above... ;-)

旁注:

不幸的是,同樣的技巧不適用于 UIScrollView 上的 pinchGestureRecognizer 因為它不公開 min/maxNumberOfTouches 屬性.當被監控時,它總是報告 2 次觸摸(你顯然需要捏) - 所以它的內部 min/maxNumberOfTouches 似乎都設置為2 - 即使 UIScrollView 不遵守其自己的設置并繼續愉快地用任意數量的手指(超過 2 個)捏合.所以沒有辦法將捏合限制在有限數量的手指上......

Unfortunately the same trick doesn't work with the pinchGestureRecognizer on UIScrollView because it doesn't expose a min/maxNumberOfTouches property. When monitored it always reports 2 touches (which you obviously need to pinch) - so its internal min/maxNumberOfTouches seem to have been set both to 2 - even if UIScrollView isn't honoring its own settings and keeps happily pinching with any numbers of fingers (more than 2). So there is no way to restrict pinching to a limited amount of fingers...

這篇關于UIScrollView 只能用一根手指滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 可縮放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
主站蜘蛛池模板: 激情网五月天 | 久久国产精彩视频 | 黄片毛片免费观看 | 国产一区欧美 | 亚洲va中文字幕 | 中文字幕电影在线观看 | 日本久久精品视频 | 午夜国产羞羞视频免费网站 | www.日日干| 成人网视频| 狠狠操电影 | 日韩美女一区二区三区在线观看 | 久久国产精品精品国产色婷婷 | 日本一道本 | 午夜电影合集 | 欧美精品久久久 | 国产精品久久久久久亚洲调教 | 国产精品污www一区二区三区 | 美女三区 | 日本在线播放一区二区 | 国产精品欧美精品 | 婷婷丁香在线视频 | www.一级片| 国产精品久久性 | 狠狠涩| 在线一区二区三区 | 99日韩| 国产日韩欧美91 | 久久99精品久久久久久狂牛 | 亚洲精品一区二区三区免 | 日日干干 | 日韩在线国产精品 | 日本一道本| 亚洲精品自拍视频 | 久在线视频播放免费视频 | 日韩一| 自拍偷拍小视频 | 蜜臀久久 | 国产福利在线视频 | 麻豆亚洲 | 精品视频久久久久久 |