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

向前觸摸到 UIScrollView

Forward touches to a UIScrollView(向前觸摸到 UIScrollView)
本文介紹了向前觸摸到 UIScrollView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有兩個視圖控制器.視圖控制器 A 有一個 UIScrollView 并呈現視圖控制器 B.呈現是交互式的,由 scrollView.contentOffset 控制.

I have two view controllers. View controller A has a UIScrollView and presents view controller B. The presentation is interactive and controlled by the scrollView.contentOffset.

我想集成一個交互式關閉過渡:向上平移時,應以交互方式關閉 ViewController B.交互式關閉過渡還應控制 ViewController A scrollView.

I want to integrate an interactive dismiss transition: When panning up, ViewController B should be dismissed interactively. The interactive dismiss transition should also control the ViewController A scrollView.

我的第一次嘗試是使用 UIPanGestureRecognizer 并根據平移距離設置 scrollView.contentOffset.這可行,但是當平移手勢結束時,滾動視圖偏移必須動畫到結束位置.使用 -[UIScrollView setContentOffset:animated: 不是一個好的解決方案,因為它使用線性動畫,沒有考慮當前的平移速度,也不能很好地減速.

My first attempt was using a UIPanGestureRecognizer and setting the scrollView.contentOffset according to the panned distance. This works, however when the pan gesture is ended, the scrollView offset has to be animated to the end position. Using -[UIScrollView setContentOffset:animated: is not a good solution since it uses a linear animation, doesn't take the current pan velocity into account and doesn't decelerate nicely.

所以我認為應該可以將我的平移手勢識別器中的觸摸事件輸入到滾動視圖中.這應該給我們所有漂亮的滾動視圖動畫行為.

So I thought it should be possible to feed the touch events from my pan gesture recognizer into the scroll view. This should give us all the nice scroll view animation behavior.

我嘗試在我的 UIPanGestureRecognizer 子類中覆蓋 -touchesBegan/Moved/Ended/Cancelled withEvent: 方法,如下所示:

I tried overriding the -touchesBegan/Moved/Ended/Cancelled withEvent: methods in my UIPanGestureRecognizer subclass like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [scrollView touchesBegan:touches withEvent:event];
    [scrollView.panGestureRecognizer touchesBegan:touches withEvent:event];

    [super touchesBegan:touches withEvent:event];
}

但顯然有些東西阻止了滾動視圖進入 tracking 模式.(確實是 dragging = YES 但僅此而已.)我驗證了 scrollView 是 userInteractionEnabled,沒有隱藏并添加到視圖層次結構中.

But apparently something is blocking the scroll view from entering tracking mode. (It does go to dragging = YES but that's about it.) I verified the scrollView is userInteractionEnabled, not hidden and added to the view hierarchy.

那么如何將我的觸摸事件轉發到 UIScrollView?

So how can I forward my touch events to UIScrollView?

推薦答案

讀完一個有趣的答案描述UIScrollView 的事件流,我得出的結論是,嘗試從手勢識別器遠程控制"滾動視圖可能很難實現,因為觸摸在路由到視圖和手勢識別器時會發生變化.由于 UITouch 不符合 NSCopying 我們也不能克隆觸摸事件以便稍后在未修改狀態下發送它們.

After reading an interesting answer describing UIScrollView's event flow, I came to the conclusion that trying to "remote control" a scroll view from a gesture recognizer is probably very hard to achieve because touches are mutated while being routed to views and gesture recognizers. Since UITouch doesn't conform to NSCopying we also can't clone touch events in order to send them later in unmodified state.

雖然沒有真正解決我所要求的問題,但我找到了一種解決方法來完成我所需要的.我剛剛向視圖控制器 B 添加了一個滾動視圖,并將其與 VC A 的滾動視圖同步(垂直滾動時添加到視圖層次結構中):

While not really solving the problem I asked for, I found a workaround to accomplish what I need. I just added a scroll view to view controller B and synced it with VC A's scroll view (which is added to the view hierarchy when vertically scrolling):

// delegate of VC B's scrollView
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
    scrollViewA.contentOffset = scrollView.contentOffset;
}

感謝 Friedrich Markgraf 提出這個想法.

Thanks to Friedrich Markgraf who came up with the idea.

這篇關于向前觸摸到 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 中縮放和捏合)
主站蜘蛛池模板: 自拍 亚洲 欧美 老师 丝袜 | 国产高清在线精品一区二区三区 | 九九热国产精品视频 | 国产精品69毛片高清亚洲 | 国产一区二区三区视频在线观看 | 久久精点视频 | 一区二区视频在线 | 中文字幕 在线观看 | 在线观看欧美日韩视频 | 亚洲视频免费在线看 | 欧美一级二级在线观看 | 日干夜干 | 草久久 | 精品一二三区在线观看 | 亚洲精品乱码久久久久久按摩观 | 亚洲一区二区视频在线播放 | 97视频精品 | 成人免费一区二区三区牛牛 | 武道仙尊动漫在线观看 | 黄色大片免费看 | 成人无遮挡毛片免费看 | 国产一区二区三区在线看 | 999精品视频| 亚洲女人的天堂 | 孕妇一级毛片 | 免费看a| 日韩久久久一区二区 | 成人在线视频一区 | 91精品国产综合久久久久蜜臀 | 国产精品久久久久久久久久久久冷 | 91久久久精品国产一区二区蜜臀 | 久久精品这里 | 亚洲美女在线一区 | 日韩中文字幕一区 | 九九在线精品视频 | 日日日操 | 日本精品视频在线 | 本道综合精品 | 国精产品一品二品国精在线观看 | 午夜精品久久久久久久久久久久久 | 色橹橹欧美在线观看视频高清 |