- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的 UICollectionView 创建自定义分页。我希望底部的一些单元格卡在屏幕边缘,但是,通过常规分页,滚动到下一页意味着如果页面底部的一半单元格显示,它只会显示另一半在下一页。我想让单元格卡在最后,但停止分页,以便卡在屏幕上的单元格清晰可见。
所以,为了做到这一点,我覆盖了函数 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
如果我拖动一两秒钟,它会按预期工作,但是,我试图模拟在启用分页时效果很好的“轻弹”。当我轻弹 UICollectionView 时,它会跳转到 targetContentOffset,而不是为其设置动画。
我如何防止这种情况?
这是我的代码:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if(targetContentOffset->y < 400) {
targetContentOffset->y = 0;
return;
}
int baseCheck = 400;
while(baseCheck <= 10000) {
if(targetContentOffset->y > baseCheck && targetContentOffset->y < baseCheck + 800) {
targetContentOffset->y = (baseCheck + 340);
return;
}
baseCheck += 800;
}
targetContentOffset->y = 0;
}
最佳答案
我遇到了同样的问题并设法解决了它。就我而言,我正在模拟一个分页的 scrollView(实际上是一个 UICollectionView),其中页面大小小于 collectionView 本身的大小。我注意到滚动的“跳跃”发生在一组特定条件下:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGFloat pageWidth; // defined somewhere else
NSInteger numberOfPages; // depends on your dataSource
CGFloat proposedOffset = targetContentOffset->x;
NSInteger currentPage = roundf(self.collectionView.contentOffset.x / pageWidth);
NSInteger proposedPage = roundf(proposedOffset / pageWidth);
// what follows is a fix for a weird case where the scroll 'jumps' into place with no animation
if(currentPage == proposedPage) {
if((currentPage == 0 && velocity.x > 0) ||
(currentPage == (numberOfPages - 1) && velocity.x < 0) ||
(currentPage > 0 && currentPage < (numberOfPages - 1) && fabs(velocity.x) > 0)
) {
// this forces the scrolling animation to stop in its current place
[self.collectionView setContentOffset:self.collectionView.contentOffset animated:NO];
[UIView animateWithDuration:.3
delay:0.
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.collectionView setContentOffset:CGPointMake(currentPage * pageWidth, 0)];
}
completion:NULL];
}
}
targetContentOffset->x = (pageWidth * proposedPage);
}
关于ipad - UICollectionView 在覆盖 scrollViewWillEndDragging 时并不总是动画减速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15233845/
我正在用 C++ 编写一个粒子模拟器。 我通过在每个时间步将它们的速度添加到它们的位置来移动粒子。 时间步的值是当前帧的百分比。所以全帧时间步长为1,半帧时间步长为0.5,四分之一帧时间步长为0.25
Linux下“减速”查看日志的方法 需求场景 今天查看日志,有个需求,需要按照指定“速率”输出日志信息到终端屏幕上,方便查看。 这个需求日常应该也经常会碰到,比如以下两种情况:
有没有办法取消 UIScrollView 的减速? 我想允许用户滚动 Canvas ,但我不希望用户抬起手指后 Canvas 继续滚动。 最佳答案 这可以通过利用 UIScrollView 委托(de
我在我的 c 应用程序中遇到大量 sqlite 减速问题,并且 不知道这是意料之中还是我没有正确使用 sqlite。 数据库使用滚动日志,如 http://dt.deviantart.com/jour
有没有办法取消 UIScrollView 的减速? 我想允许用户滚动 Canvas ,但我不希望用户抬起手指后 Canvas 继续滚动。 最佳答案 这可以通过利用 UIScrollView 委托(de
我有一个可以用手指拖动的 UIView,这是我使用 UIPanGestureRecognizer 实现的。这允许我水平拖动 View ;向左或向右。 我在从 UIPanGestureRecognize
我正在向 Redis 中插入大量文本以逐行存储频率。但是,jedis/redis 会变慢,并且在执行一定数量的操作后需要花费大量时间e 操作并且程序以错误结束:java.lang.OutOfMemor
我有一个 UIPanGestureRecognize,我用它来更改 View 的框架。当手势状态为 UIGestureRecognizerStateEnded 时,有没有办法模拟 UIScrollVi
我正在尝试在 MKMapView 上捕获平移和“滚动结束”。使用手势识别器可以轻松实现平移。然而,MKMapView 似乎没有在 iOS 6 中实现 UIScrollViewDelegate。这使得解
我正在尝试学习如何实现多处理来计算蒙特卡洛模拟。我从 this simple tutorial 复制了代码目的是计算积分。我还将它与 answer from WolframAlpha 进行了比较并计算
基本上破坏我的 node js express 服务器的代码是这样的: resultArr = []; resultArr["test"] = []; resultArr["test"][201507
我有一个服务,每秒向 S3 发送 10k PUT 请求。 S3 能够在几分钟内处理这些负载,但在那之后开始抛出 SlowDown 异常。它使我的服务速度减慢到无法接受的速度。 我已阅读 this并实现
SO上有足够多的类似问题和答案。然而很少提到前缀。 首先,不再需要前缀的随机化,参见 here This S3 request rate performance increase removes an
我正在创建以下画廊: gallery 我相信 prettyPhoto.css 在悬停时应用了边框颜色,但我似乎无法使用 Dom Inspector 找到它。 谁能帮我找到 css 来编辑鼠标悬停时的边
我有一个基于 paste.httpserver 的网络服务器作为 HTTP 和 WSGI 之间的适配器。当我使用 httperf 进行性能测量时,如果每次使用 --num-conn 启动一个新请求,我
我是一名优秀的程序员,十分优秀!