gpt4 book ai didi

ios - 基于indexPath.row的UIView上下滑动动画

转载 作者:行者123 更新时间:2023-11-29 02:38:03 29 4
gpt4 key购买 nike

现在我正在尝试根据 UITableView 中的向上或向下滚动来上下移动 UIView。因此,如果我 ScrollView ,这意味着 indexPath.row 将保持递增; View 将出现向下滑动,直到某个位置并停止。然后当我向下滚动 TableView 时,这意味着indexPath.row递减;通过向上滑动到显示 View 之外, View 将消失。

有人知道我需要编写什么代码吗?现在我只能隐藏和取消隐藏 View 。我需要为其上下滑动设置动画的代码。

   mark=indexPath.row;
flag=flag+1;
if (flag-mark>1) {
postBox.hidden=NO;
flag=indexPath.row;
}
else
postBox.hidden=YES;

在此先感谢您的帮助^^

最佳答案

如果您想根据 UITableView 的移动移动 View ,您可以计算 UITableView 的内容偏移量并将其应用到您移动的 View 。声明一个名为 lastOffset 的 CGFloat 类型的 ivar。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat distance = scrollView.contentOffset.y - lastOffset;
lastOffset = scrollView.contentOffset.y;

[UIView animateWithDuration:0.2 animations:^{
self.movingView.frame = CGRectOffset(self.movingView.frame, 0.0f, distance);
}];
}

关于ios - 基于indexPath.row的UIView上下滑动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26133530/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com