我正在尝试在集合视图滚动时为tableviews高度设置动画。我从scrollViewWillBeginDragging调用动画函数。然后我执行一个动画块:
SomeInterface
发生的事情是TableView动画到状态栏然后返回到其原始位置。我想让它的动画缩小到屏幕大小的一半。动画块只执行一次,因为我在调用动画函数时设置了一个布尔值。
答案 0 :(得分:0)
你说你在调用动画块时设置了一个布尔值,这是不是一次又一次地调用动画?我也没有在你的代码中看到这一点。
这应该可以正常工作。
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
let mainScreen = UIScreen.mainScreen().bounds
if (self.IBcalendarTableView.frame.origin.y != mainScreen.height / 2) {
var frame = self.IBcalendarTableView.frame
frame.origin.y = mainScreen.height / 2
frame.size.height = frame.origin.y
UIView.animateWithDuration(0.5) { () -> Void in
self.IBcalendarTableView.frame = frame
}
}
}
我设置了较低的动画速度,3秒似乎很多......我也用不同的方式构建了框架,我只是这样做,因为我觉得它更容易阅读。
如果还有什么我可以提供的帮助,请告诉我。
答案 1 :(得分:0)
问题在于自动布局。您还必须设置tableview的高度约束,以便将tableview保持在新的高度/原点。
对于可能遇到此问题的其他人:
这个答案帮助我解决了这个问题。我的固定代码如下所示:
func expandCollectionView() {
let screenSize: CGRect = UIScreen.mainScreen().bounds
var frame = self.IBcalendarTableView.frame
frame.origin.y = screenSize.height / 2
frame.size.height = frame.origin.y
UIView.animateWithDuration(0.5) { () -> Void in
self.IBcalendarTableView.frame = frame
self.IBtableViewHeightConstraint.constant = screenSize.height/2
}
}