pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

交叉方向 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屋-程序員軟件開發技術分享
主站蜘蛛池模板: NBA直播_NBA直播免费观看直播在线_NBA直播免费高清无插件在线观看-24直播网 | 工业CT-无锡璟能智能仪器有限公司 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 | 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | 雷冲击高压发生器-水内冷直流高压发生器-串联谐振分压器-武汉特高压电力科技有限公司 | 泰国试管婴儿_泰国第三代试管婴儿_泰国试管婴儿费用/多少钱_孕泰来 | 石膏基自流平砂浆厂家-高强石膏基保温隔声自流平-轻质抹灰石膏粉砂浆批发-永康市汇利建设有限公司 | 雄松华章(广州华章MBA)官网-专注MBA/MPA/MPAcc/MEM辅导培训 | 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 喷播机厂家_二手喷播机租赁_水泥浆洒布机-河南青山绿水机电设备有限公司 | 密度电子天平-内校-外校电子天平-沈阳龙腾电子有限公司 | 南京蜂窝纸箱_南京木托盘_南京纸托盘-南京博恒包装有限公司 | 高效节能电机_伺服主轴电机_铜转子电机_交流感应伺服电机_图片_型号_江苏智马科技有限公司 | 制氮设备-变压吸附制氮设备-制氧设备-杭州聚贤气体设备制造有限公司 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 海南在线 海南一家 | 无轨电动平车_轨道平车_蓄电池电动平车★尽在新乡百特智能转运设备有限公司 | 布袋除尘器-单机除尘器-脉冲除尘器-泊头市兴天环保设备有限公司 布袋除尘器|除尘器设备|除尘布袋|除尘设备_诺和环保设备 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 | 上海地磅秤|电子地上衡|防爆地磅_上海地磅秤厂家–越衡称重 | 三板富 | 专注于新三板的第一垂直服务平台 | 石栏杆_青石栏杆_汉白玉栏杆_花岗岩栏杆 - 【石雕之乡】点石石雕石材厂 | 自动售货机_无人售货机_专业的自动售货机运营商_免费投放售货机-广州富宏主官网 | 西安耀程造价培训机构_工程预算实训_广联达实作实操培训 | 耐酸碱胶管_耐腐蚀软管总成_化学品输送软管_漯河利通液压科技耐油耐磨喷砂软管|耐腐蚀化学软管 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 超声波清洗机_超声波清洗机设备_超声波清洗机厂家_鼎泰恒胜 | 经济师考试_2025中级经济师报名时间_报名入口_考试时间_华课网校经济师培训网站 | 章丘丰源机械有限公司 - 三叶罗茨风机,罗茨鼓风机,罗茨风机 | 精雕机-火花机-精雕机 cnc-高速精雕机-电火花机-广东鼎拓机械科技有限公司 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | 澳洁干洗店加盟-洗衣店干洗连锁「澳洁干洗免费一对一贴心服务」 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 威实软件_软件定制开发_OA_OA办公系统_OA系统_办公自动化软件 | 低压载波电能表-单相导轨式电能表-华邦电力科技股份有限公司-智能物联网综合管理平台 | 纸箱网 -纸箱机械|设备|包装纸盒|包装印刷行业门户网站 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 泉州陶瓷pc砖_园林景观砖厂家_石英砖地铺石价格 _福建暴风石英砖 | 耐火浇注料价格-高强高铝-刚玉碳化硅耐磨浇注料厂家【直销】 |