Bar*_*zyk 10 uitableview ios swift uitableviewautomaticdimension
为什么UITableView在滚动时会跳转?你能帮助我吗?
对于一个谁帮助我,我开始和获奖后ANOTHER 100 :-)的赏金
如何进行一些更改UITableView
以及设置它contentOffset
?
这是我设置我的方式scrollDisplayLink
:
scrollDisplayLink = CADisplayLink(target: self, selector: Selector("scrollTable"))
scrollDisplayLink?.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
cellForCurrentIndexPath?.hidden = true
Run Code Online (Sandbox Code Playgroud)
然后在scrollTable
我做以下事情:
func scrollTable() {
var newOffset = CGPointMake(currentContentOffset.x, currentContentOffset.y + scrollRate * 10)
if currentContentSize.height < frame.size.height {
newOffset = currentContentOffset
} else if newOffset.y > currentContentSize.height - frame.size.height {
newOffset.y = currentContentSize.height - frame.size.height
} else if newOffset.y < 0 {
newOffset = CGPointZero
}
contentOffset = newOffset
if coveredIndexPath != nil && coveredIndexPath! != currentIndexPath! {
let verticalPositionInCoveredCell = longPressGestureRecognizer.locationInView(cellForRowAtIndexPath(coveredIndexPath!)).y
if direction == .Down && heightForCoveredCell - verticalPositionInCoveredCell <= heightForCurrentCell / 2 {
print("moved down")
beginUpdates() //1
moveRowAtIndexPath(currentIndexPath!, toIndexPath: coveredIndexPath!) //2
currentIndexPath = coveredIndexPath //3
endUpdates() //4
}
}
}
Run Code Online (Sandbox Code Playgroud)
滚动很好,除非1-4
注释行或禁用UITableViewAutomaticDimension
.当他们没有被评论时,表格在currentContentOffset
不0
同时跳转,然后滚动.为什么会这样?是线程还是别的问题?
注意:
UITableView
适用于UITableViewAutomaticDimension
:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Run Code Online (Sandbox Code Playgroud)
让我们从显而易见的开始:
UITableView 是 UIScrollView 的子类,我们可以使用它的一些属性。
几乎每年都有一个关于如何自定义 UIScrollviews 的精彩 WWDC 演讲。
他们建议像你在里面做的那样
// is called every frame of scrolling and zooming
override func layoutSubviews() {
...
super.layoutSubviews()
...
}
Run Code Online (Sandbox Code Playgroud)
当用户滚动时,这被称为每一帧。
我在滚动时大量使用这个地方来搞乱 currentContentOffset 以及大小和坐标系统(我对 UIScrollView 而不是 UITableView 进行了子类化)。
优点:
希望这可以帮助
聚苯乙烯
根据我的实验,UIScrollView 内滚动的视图不能高于 8000 像素左右。
因此,Apple 的 UITableView 必须实现一种称为无限滚动的策略,在有关 UIScrollViews 的 WWDC 视频之一中对此进行了描述:
简而言之:
表格的一部分被绘制一次,然后滚动而不重新绘制表格内容。当用户滚动得太远时,会绘制滚动表的不同部分,同时 UITableView 实现会更改 contentOffset。
当您在layoutSubviews() 的实现中调用super.layoutSubviews() 时,这可能会完成。
归档时间: |
|
查看次数: |
610 次 |
最近记录: |