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

交叉方向 UIScrollViews - 我可以修改滾動行為嗎?

Cross Directional UIScrollViews - Can I Modify the Scrolling Behaviour?(交叉方向 UIScrollViews - 我可以修改滾動行為嗎?)
本文介紹了交叉方向 UIScrollViews - 我可以修改滾動行為嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

滾動視圖的工作原理如下: 一個滾動視圖在水平方向啟用分頁.此滾動視圖的每個頁面"都包含一個垂直滾動的 UITableView.如果不進行修改,這可以正常工作,但并不完美.

Here's how the scroll views work: One scroll view is paging enabled in the horizontal direction. Each 'page' of this scroll view contains a vertically scrolling UITableView. Without modification, this works OK, but not perfectly.

不正確的行為:當用戶在表格視圖上上下滾動,但又想快速翻到下一頁時,水平滑動/滑動最初不起作用 -在表格視圖靜止之前它不會起作用(即使滑動非常明顯是水平的).

The behaviour that's not right: When the user scrolls up and down on the table view, but then wants to flick over to the next page quickly, the horizontal flick/swipe will not work initially - it will not work until the table view is stationary (even if the swipe is very clearly horizontal).

它應該如何工作:如果滑動明顯是水平的,即使表格視圖仍在滾動/彈跳,我也希望頁面發生變化,因為這也是用戶所期望的.

How it should work: If the swipe is clearly horizontal, I'd like the page to change even if the table view is still scrolling/bouncing, as this is what the user will expect too.


我怎樣才能改變這種行為 - 最簡單或最好的方法是什么?


注意 由于各種原因,某些答案中所述的 UIPageViewController 將不起作用.我如何使用交叉方向 UIScrollViews 來做到這一點(/one 是一個表格視圖,但你明白了)?我已經用頭撞墻了好幾個小時了——如果你認為你能做到這一點,那么我會很樂意獎勵賞金.


NOTE For various reasons, a UIPageViewController as stated in some answers will not work. How can I do this with cross directional UIScrollViews (/one is a table view, but you get the idea)? I've been banging my head against a wall for hours - if you think you can do this then I'll more than happily award a bounty.

推薦答案

根據我對問題的理解,只有在 tableView 滾動時,我們才想更改默認行為.所有其他行為都將相同.

According to my understanding of the question, it is only while the tableView is scrolling we want to change the default behaviour. All the other behaviour will be the same.

子類 UITableView.UITableViewUIScrollView 的子類.在 UITableView 子類上實現一個 UIScrollViewUIGestureRecognizer 的委托方法

SubClass UITableView. UITableViews are subClass of UIScrollViews. On the UITableView subClass implement one UIScrollView's UIGestureRecognizer's delegate method

- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer
{
    //Edit 1
    //return self.isDecelerating;
    //return self.isDecelerating | self.bounces; //If we want to simultaneous gesture on bounce and scrolling
    //Edit 2
    return self.isDecelerating || self.contentOffset.y < 0 || self.contentOffset.y > MAX(0, self.contentSize.height - self.bounds.size.height); // @Jordan edited - we don't need to always enable simultaneous gesture for bounce enabled tableViews
}

因為我們只想在 tableView 減速時更改默認手勢行為.

As we only want to change the default gesture behaviour while the tableView is decelerating.

現在將所有 'UITableView 的類更改為您新創建的 tableViewSubClass 并運行項目,當 tableView 滾動時滑動應該可以工作.:]

Now change all 'UITableView's class to your newly created tableViewSubClass and run the project, swipe should work while tableView is scrolling. :]

但是當 tableView 滾動時,滑動看起來有點太敏感了.讓我們對滑動進行一些限制.

But the swipe looks a little too sensitive while tableView is scrolling. Let's make the swipe a little restrictive.

子類 UIScrollView.在 UIScrollView 子類上實現另一個 UIGestureRecognizer 的委托方法 gestureRecognizerShouldBegin:

SubClass UIScrollView. On the UIScrollView subclass implement another UIGestureRecognizer's delegate method gestureRecognizerShouldBegin:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 
{
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];
        if (abs(velocity.y) * 2 < abs(velocity.x)) {
            return YES;
        }
    }
    return NO;
}

我們想讓滑動清晰地水平".上面的代碼僅在 x 軸上的手勢速度是 y 軸上的兩倍時才允許手勢開始.[如果您愿意,請隨意增加硬編碼值2".值越高,滑動需要越水平.]

We want to make the "swipe is clearly horizontal". Above code only permits gesture begin if the gesture velocity on x axis is double than on y axis. [Feel free to increase the hard coded value "2" if your like. The higher the value the swipe needs to be more horizontal.]

現在將UiScrollView"類(具有多個 TableView)更改為您的 ScrollViewSubClass.運行項目.:]

Now change the `UiScrollView' class (which has multiple TableViews) to your ScrollViewSubClass. Run the project. :]

我在 gitHub 上做了一個項目https://github.com/rishi420/SwipeWhileScroll

I've made a project on gitHub https://github.com/rishi420/SwipeWhileScroll

這篇關于交叉方向 UIScrollViews - 我可以修改滾動行為嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
iOS/Swift - Hide/Show UITabBarController when scrolling down/up(iOS/Swift - 向下/向上滾動時隱藏/顯示 UITabBarController)
Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources(以編程方式強制 UIScrollView 停止滾動,以便與多個數據源共享表格視圖) - IT屋-程序員軟件開發技術分享
主站蜘蛛池模板: 91视频大全| 精品免费视频 | 欧美一区中文字幕 | 不卡一区二区三区四区 | 日本成人中文字幕 | 黄色片在线网站 | 国产91中文| 国产精品精品视频一区二区三区 | 黑人精品 | 久久青| 久久中文字幕在线 | 九九导航 | 色婷婷综合久久久久中文一区二区 | 亚洲中午字幕 | 国产精品呻吟久久av凹凸 | 国产精品免费观看 | 999久久久 | 天堂中文在线播放 | 99精品国产一区二区青青牛奶 | 精品在线一区二区 | 久久久精品一区二区 | 人人叉 | 久久成人一区二区三区 | 在线看av网址 | 日本免费黄色 | 一区二区中文字幕 | 亚洲精品在 | 欧美精品中文字幕久久二区 | 亚洲色在线视频 | 干干干操操操 | 亚洲欧美在线视频 | av免费网站在线 | 一区二区三区av | 久久久久久久久久毛片 | 成年人免费看的视频 | 亚洲精品视频在线看 | 欧美精品乱码久久久久久按摩 | 久久av一区 | 区一区二区三在线观看 | 作爱视频免费看 | 国产在线a视频 |