简体   繁体   English

iOS中的快速滚动设计模式

[英]Quick Scrolling Design Pattern in iOS

I have a very long list in my app. 我的应用程序列表很长。 Each cell has multiple lines of text and a large picture, making scrolling through this list of 200+ items very tedious. 每个单元格都有多行文本和一张大图片,因此滚动浏览此200多个项目非常繁琐。

I wanted to implement a solution that would make scrolling easier, without implementing alphabetical scrolling as shown in the contacts app (since this would prevent me from allowing fast scrolling). 我想实现一个解决方案,使滚动更容易,而无需实现联系人应用程序中所示的按字母顺序滚动(因为这将阻止我允许快速滚动)。

I wanted to implement a solution where, if you scrolling on the right side (to the point where your finger is hovering over the scroll bar on the right), than it would work the same as if you were clicking and dragging on the scroll bar on a desktop (meaning you could drag the scroll bar to the top or bottom very very quickly). 我想实现一个解决方案,如果您在右侧滚动(手指悬停在右侧滚动条上的位置),则其效果与单击并拖动滚动条相同在桌面上(这意味着您可以非常快速地将滚动条拖动到顶部或底部)。

Is this a viable design for iOS? 这是iOS可行的设计吗? If so, what would be the best way to go about implementing it? 如果是这样,实现它的最佳方法是什么?

You could use a UISlider for that purpose. 您可以为此使用UISlider。 Here I created an example of a small tableview with 1000 rows and a slider to scroll across them: example 在这里,我创建了一个具有1000行的小型tableview的示例,并带有一个滚动它们的滑块: example

You can customize the UISlider to make it smaller, vertical, or whatever you want. 您可以自定义UISlider以使其更小,更垂直或任何您想要的形状。 Here's the viewControllers code, in case the file goes offline: 如果文件离线,这是viewControllers代码:

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var tableView: UITableView!
    private let numberOfRows = 1000

    override func viewDidLoad() {
        super.viewDidLoad()
        slider.maximumValue = Float(numberOfRows - 1) //due to rows goes from 0 to 999
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return numberOfRows
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier") as! UITableViewCell
        cell.textLabel?.text = "\(indexPath.row)"
        return cell;
    }

    @IBAction func sliderValueChanged(sender: UISlider) {
        let positionToScroll = sender.value
        tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: Int(positionToScroll), inSection: 0), atScrollPosition: UITableViewScrollPosition.None, animated: false)
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM