UITableView - 保持最底部的单元格滚动到顶部? [英] UITableView - Keep bottom-most cell scrolled to the top?

查看:32
本文介绍了UITableView - 保持最底部的单元格滚动到顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于音乐的应用程序.播放列表屏幕是一个 UITableView.它有 3 个部分:上一首曲目、正在播放的曲目、下一首曲目.它们的顺序如下:

Im creating a music based app. The playlist screen is a UITableView. It has 3 sections: Previous Tracks, Now Playing, Next Tracks. They are in order as follows:

-- PREVIOUS TRACKS SECTION --
   Track Z
   Track Y
   Track X
-- NOW PLAYING SECTION --
   Track A
-- NEXT TRACKS --
   Track B
   Track C
   Track D

我总是希望将正在播放"部分滚动到表格视图的顶部.如果出现以下情况,这不是问题:A) 以前的曲目部分中没有项目或B) Next Tracks 部分有足够的轨道可以越过 UITableView 的底部.

I always want the 'Now Playing' section to be scrolled to the top of the table view. This is not a problem if: A) There are no items in the Previous tracks section or B) There are enough tracks in the Next Tracks section to pass beyond the bottom of the UITableView.

但是,例如,如果上一曲目部分有 10 首曲目,当前播放中的一首曲目和下一曲目部分中的 2 首曲目,那么当我告诉表格视图滚动时,正在播放的部分位于顶部在视图中,它只是弹回,因此距离视图底部有 3 个项目(2 个下一曲目"项目加上当前播放的项目).

However, if there are, for example 10 tracks in the Previous Tracks section, one in the Currently Playing and 2 in the Next Track section, then when I tell the table view to scroll so the Now Playing section is at the top of the view, it just springs back so it is 3 items from the bottom of the view (the 2 'Next Track' items plus the Currently Playing).

换句话说,看看你的 iPod 库或 iPhone 上的任何 TableView.我想要实现的是将列表中的最后一首曲目滚动到屏幕顶部,并在下方留下空白区域.

To put it another way, look at your iPod library or any TableView on the iPhone. What im trying to acheive is to scroll the last track in the list to the top of the screen and leave blank white space underneath.

在这种情况下,有没有办法告诉 TableView 不要弹回原位?我曾尝试在那里播放大高度单元格,但在重新排列 TableView 中的单元格时会出现问题.

Is there any way of telling the TableView not to spring back into place in this scenario? I have tried playing a large height cell there, but its hacky and causes problems when re-arranging cells in the TableView.

从技术上讲这是 Monotouch,但我用 Objective C 没问题,所以任何语言都可以.

Technically this is Monotouch, but im fine with Objective C, so whatever language is fine.

推荐答案

contentInset 表视图继承的属性.您必须设置底部插图,以便最底部的单元格可见.

Look at the contentInset property which the table view inherits. You will have to set the bottom inset just so that the bottom most cell is visible.

示例:

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, self.tableView.frame.size.height - 88, 0);

这篇关于UITableView - 保持最底部的单元格滚动到顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆