久久久久久久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 中縮放和捏合)
主站蜘蛛池模板: 日韩欧美在线视频 | 国产视频二区在线观看 | 成人免费视频在线观看 | 亚洲视频在线观看免费 | aa级毛片毛片免费观看久 | 一区二区三区在线看 | 国产精品视频久久 | 亚洲成人久久久 | 久久精品国产一区二区电影 | 欧美精品一区三区 | 婷婷一级片 | 草久久免费视频 | 成人夜晚看av | 日韩国产专区 | 欧美一级黄色片免费观看 | 久久精品欧美一区二区三区不卡 | 欧美日韩亚洲一区二区 | 91视频一88av| 一级毛片在线播放 | 国产成人精品一区二 | 精品九九在线 | 精品日韩一区二区三区 | 精品一级| 国产一区二区三区在线 | 国产精品视频一 | 欧美一区二区三区久久精品 | 亚洲免费在线 | 一区在线观看 | av三级在线观看 | 午夜视频一区 | 男人的天堂一级片 | 亚洲一区视频在线 | 午夜影院普通用户体验区 | 精品久久久久久久久久久久久久久久久 | 中文字幕日韩一区 | 欧美一级二级视频 | 999www视频免费观看 | 成人影院午夜 | 伊人中文字幕 | 精精国产xxxx视频在线播放7 | 在线免费观看毛片 |