久久久久久久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 設(shè)置為 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 未按預(yù)期運行,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.

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

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 設(shè)置為所需的值,例如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 協(xié)議.您不必為 UIScrollView 設(shè)置 panGestureRecognizer.delegate !!!委托已經(jīng)設(shè)置,因為 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.

然后實現(xiàn)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 告訴您觸摸的次數(shù).如果您將 minmax 設(shè)置為相同的值(如上例中的 1),if-loop 永遠不會被觸發(fā)... ;-)

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:.

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

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 屬性.當被監(jiān)控時,它總是報告 2 次觸摸(你顯然需要捏) - 所以它的內(nèi)部 min/maxNumberOfTouches 似乎都設(shè)置為2 - 即使 UIScrollView 不遵守其自己的設(shè)置并繼續(xù)愉快地用任意數(shù)量的手指(超過 2 個)捏合.所以沒有辦法將捏合限制在有限數(shù)量的手指上......

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...

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

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

相關(guān)文檔推薦

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 構(gòu)建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
主站蜘蛛池模板: 久久久久成人网 | 国产精品美女在线观看 | 国产日韩免费 | 伊人网在线| 日本亚洲天堂 | 一级片在线播放 | 亚洲日本中文字幕 | 国产免费小视频 | 91激情视频 | 中文字幕综合网 | 秋霞午夜鲁丝一区二区老狼 | 黄色一级免费看 | 精品国产aⅴ麻豆 | 欧美女同视频 | 亚洲 欧美 激情 另类 校园 | 免费观看av网站 | 中文一级片 | 午夜精品影院 | 日韩天天操 | www.97超碰| 日本免费视频 | 在线欧美 | 天天天天操 | 中文字幕一级片 | 欧美日韩一本 | 欧美一区二区视频在线观看 | 国产成人免费视频 | 午夜视频免费 | 欧美亚洲一区二区三区 | 欧美国产日韩视频 | 免费一级黄色 | 男同在线观看 | 国产一区二区视频在线 | 久久精品国产一区二区 | 天堂中文资源在线 | 亚洲在线观看视频 | 亚洲久久久久久 | 成人在线小视频 | 久草精品视频 | 欧美一区二区三区免费 | 麻豆av在线免费观看 |