【发布时间】:2015-11-29 14:59:20
【问题描述】:
我试图在滚动时隐藏UITableView 的索引栏。
因此,当我开始滚动和完成时,我会重新加载部分索引标题。返回一个空数组隐藏栏。
我的代码是:
var showSectionIndexTitles = true
override func scrollViewWillBeginDragging(scrollView: UIScrollView) {
showSectionIndexTitles = false
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.tableView.reloadSectionIndexTitles()
})
}
override func scrollViewWillBeginDecelerating(scrollView: UIScrollView) {
showSectionIndexTitles = true
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.tableView.reloadSectionIndexTitles()
})
}
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! {
if showSectionIndexTitles {
return uniq([UITableViewIndexSearch] + AlphabetUppercase + datamanager.categoryIndexTitles)
} else {
return nil
}
}
这在不使用动画时有效,但我想使用动画。 我更喜欢一个动画,其中当栏隐藏时整个栏向右移动,当栏可见时从右侧移动
我尝试使用UIView:animateWithDuration 来测试动画是否可行。
我注意到的:
- 此基本动画从左上角移动/缩放 可见
- 隐藏栏时它会立即消失
我的问题:
- 实现索引栏可见性动画的最佳方法是什么?
- 实现我前面提到的特定动画的最佳方法是什么?
提前谢谢你!
编辑 1:
我只记得之前在哪里看到过这个效果:iOS 8.4 Music App
当你滚动到你只能看到标题列表时,Apple 也会这样做(UITableView)
编辑 2:
我向苹果提交了一份错误报告,建议使用animated 参数更改索引栏可见性的功能。我会在收到回复后立即通知您。
尽管@matt 已经在他的answer 中提出了一个可能的解决方案,但如果其他人知道解决此问题的不同便捷方法或过去也遇到过此类功能,我很高兴收到您的来信!
【问题讨论】:
标签: ios objective-c swift cocoa-touch core-animation