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

如何使 ScrollView 中的 TableView 的滾動行為自然

How to Make the scroll of a TableView inside ScrollView behave naturally(如何使 ScrollView 中的 TableView 的滾動行為自然)
本文介紹了如何使 ScrollView 中的 TableView 的滾動行為自然的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要做這個配置奇怪的應用程序.

I need to do this app that has a weird configuration.

如下圖所示,主視圖是一個 UIScrollView.那么里面應該有一個UIPageView,而PageView的每一頁都應該有一個UITableView.

As shown in the next image, the main view is a UIScrollView. Then inside it should have a UIPageView, and each page of the PageView should have a UITableView.

到目前為止,我已經完成了這一切.但我的問題是我希望滾動表現 自然.

I've done all this so far. But my problem is that I want the scrolling to behave naturally.

接下來是我的意思自然.目前,當我在其中一個 UITableViews 上滾動時,它會滾動表格視圖(而不是滾動視圖).但我希望它滾動 ScrollView,除非滾動視圖無法滾動,因為它到達了頂部或底部(在這種情況下,我希望它滾動 tableview).

The next is what I mean naturally. Currently when I scroll on one of the UITableViews, it scrolls the tableview (not the scrollview). But I want it to scroll the ScrollView unless the scrollview cannot scroll cause it got to its top or bottom (In that case I'd like it to scroll the tableview).

例如,假設我的滾動視圖當前滾動到頂部.然后我將手指放在(正在顯示的當前頁面的)tableview 上并開始滾動向下.在這種情況下,我希望滾動視圖滾動(沒有表格視圖).如果我繼續向下滾動滾動視圖并到達底部,如果我將手指從顯示屏上移開并將其放回 tebleview 上并再次向下滾動,我希望我的 tableview 現在向下滾動,因為滾動視圖到達了底部并且不是可以繼續滾動.

For example, let's say my scrollview is currently scrolled to the top. Then I put my finger over the tableview (of the current page being shown) and start scrolling down. I this case, I want the scrollview to scroll (no the tableview). If I keep scrolling down my scrollview and it reaches the bottom, if I remove my finger from the display and put it back over the tebleview and scroll down again, I want my tableview to scroll down now because the scrollview reached its bottom and it's not able to keep scrolling.

你們知道如何實現這種滾動嗎?

Do you guys have any idea about how to implement this scrolling?

我真的很迷茫.任何幫助將不勝感激:(

I'm REALLY lost with this. Any help will be greatly appreciate it :(

謝謝!

推薦答案

同時處理滾動視圖和表格視圖的解決方案圍繞UIScrollViewDelegate展開.因此,讓您的視圖控制器符合該協議:

The solution to simultaneously handling the scroll view and the table view revolves around the UIScrollViewDelegate. Therefore, have your view controller conform to that protocol:

class ViewController: UIViewController, UIScrollViewDelegate {

我將滾動視圖和表格視圖表示為插座:

I’ll represent the scroll view and table view as outlets:

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var tableView: UITableView!

我們還需要跟蹤滾動視圖內容的高度以及屏幕高度.稍后你會明白為什么.

We’ll also need to track the height of the scroll view content as well as the screen height. You’ll see why later.

let screenHeight = UIScreen.mainScreen().bounds.height
let scrollViewContentHeight = 1200 as CGFloat

viewDidLoad::

override func viewDidLoad() {
    super.viewDidLoad()

    scrollView.contentSize = CGSizeMake(scrollViewContentWidth, scrollViewContentHeight)
    scrollView.delegate = self
    tableView.delegate = self 
    scrollView.bounces = false
    tableView.bounces = false
    tableView.scrollEnabled = false
}

我已關閉彈跳以保持簡單.關鍵設置是滾動視圖和表格視圖的委托,并且首先關閉表格視圖滾動.

where I’ve turned off bouncing to keep things simple. The key settings are the delegates for the scroll view and the table view and having the table view scrolling being turned off at first.

這些是必要的,以便 scrollViewDidScroll: 委托方法可以處理到達滾動視圖的底部和到達表格視圖的頂部.這是那個方法:

These are necessary so that the scrollViewDidScroll: delegate method can handle reaching the bottom of the scroll view and reaching the top of the table view. Here is that method:

func scrollViewDidScroll(scrollView: UIScrollView) {
    let yOffset = scrollView.contentOffset.y

    if scrollView == self.scrollView {
        if yOffset >= scrollViewContentHeight - screenHeight {
            scrollView.scrollEnabled = false
            tableView.scrollEnabled = true
        }
    }

    if scrollView == self.tableView {
        if yOffset <= 0 {
            self.scrollView.scrollEnabled = true
            self.tableView.scrollEnabled = false
        }
    }
}

委托方法所做的是檢測滾動視圖何時到達底部.當這種情況發生時,表格視圖可以滾動.它還會檢測表格視圖何時到達重新啟用滾動視圖的頂部.

What the delegate method is doing is detecting when the scroll view has reached its bottom. When that has happened the table view can be scrolled. It is also detecting when the table view reaches the top where the scroll view is re-enabled.

我創建了一個 GIF 來展示結果:

I created a GIF to demonstrate the results:

這篇關于如何使 ScrollView 中的 TableView 的滾動行為自然的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 日韩快播电影网 | 精品欧美乱码久久久久久1区2区 | 波多野结衣精品在线 | 成人免费视频网址 | 亚洲综合在 | 一级做a爰片性色毛片视频停止 | 欧美日韩在线免费观看 | 一区二区三区亚洲 | 奇米超碰在线 | 亚洲精品成人 | 午夜精品久久久久久不卡欧美一级 | 久久综合狠狠综合久久综合88 | 欧美色综合一区二区三区 | 毛片1| 国产精品视频久久 | 国产午夜精品一区二区三区嫩草 | 欧美在线观看一区 | 中文字幕亚洲区 | 香蕉久久久久久 | 亚洲va欧美va人人爽午夜 | 欧美激情综合 | 亚洲精品在线观 | 成人国产精品久久久 | av在线播放不卡 | 精品欧美一区二区在线观看 | 国产一区二区 | 青青草中文字幕 | 国产一二三视频在线观看 | v片网站 | 国产精品欧美一区二区 | 亚洲精品在线视频 | 正在播放国产精品 | 欧美激情视频一区二区三区在线播放 | 丝袜 亚洲 欧美 日韩 综合 | 久久综合久色欧美综合狠狠 | 狠狠婷婷综合久久久久久妖精 | 日韩免 | 美国黄色毛片 | 午夜久久久 | 天天插天天操 | 人人干人人草 |