久久久久久久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 中縮放和捏合)
主站蜘蛛池模板: 久久久久综合 | 中国大陆高清aⅴ毛片 | 亚洲成人黄色 | 91偷拍精品一区二区三区 | 91国在线高清视频 | 精彩视频一区二区三区 | 国产精品一区在线 | av官网在线 | 日本久久黄色 | 琪琪午夜伦伦电影福利片 | 在线观看第一区 | 人人天天操| 国产日韩欧美 | 九七午夜剧场福利写真 | 午夜小电影| 婷婷五月色综合 | a黄在线观看 | 日韩激情免费 | 在线色网| 日韩欧美国产一区二区 | 另类专区亚洲 | 欧美视频精品 | 九九久久国产 | 精品一二区 | 中文字幕影院 | 色综合视频 | 欧美一级www片免费观看 | 噜噜噜噜狠狠狠7777视频 | 亚洲精品字幕 | 自拍视频网站 | 亚洲一区二区免费 | 日本精品久久久一区二区三区 | а天堂中文最新一区二区三区 | 国产免费一区二区三区 | 波多野结衣中文字幕一区二区三区 | 久久com | 久久精品一级 | 在线观看精品视频网站 | 免费毛片网站在线观看 | 久久久久国产一区二区三区 | 国产重口老太伦 |