- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我找遍了所有地方,但找不到答案。所以,开始吧。我创建了一个长 ScrollView ,里面有 568 像素(全屏) View 。当用户向下滚动时,我希望 ScrollView 捕捉到特定位置。这是我的代码:
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (aboutScroller.contentOffset.y >= 468 && aboutScroller.contentOffset.y <= 668) {
targetContentOffset->y = 568;
} else if (aboutScroller.contentOffset.y >= 1036 && aboutScroller.contentOffset.y <= 1236) {
targetContentOffset->y = 1136;
} else if (aboutScroller.contentOffset.y >= 1604 && aboutScroller.contentOffset.y <= 1804) {
targetContentOffset->y = 1704;
}
}
问题是它没有惯性地捕捉(当我抬起手指时),但是当我滑动滚动时,它不会捕捉。我猜我可以使用 velocity 来处理这个问题,但我不知道该怎么做。任何帮助让它快速滑动的帮助都将不胜感激!
最佳答案
对于需要解决此问题的任何其他人,Daniel 已在上面进行了更正,但我只想说出我自己的话。
首先,如果用户不随惯性滚动,则添加设置 contentOffset 的方法:
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (_aboutScroller.contentOffset.y >= 468 && _aboutScroller.contentOffset.y <= 668) {
targetContentOffset->y = 568;
} else if (_aboutScroller.contentOffset.y >= 1036 && _aboutScroller.contentOffset.y <= 1236) {
targetContentOffset->y = 1136;
} else if (_aboutScroller.contentOffset.y >= 1604 && _aboutScroller.contentOffset.y <= 1804) {
targetContentOffset->y = 1704;
} else if (_aboutScroller.contentOffset.y >= 2172 && _aboutScroller.contentOffset.y <= 2372) {
targetContentOffset->y = 2272;
}
}
接下来,如果用户确实以惯性滚动,则添加设置 contentOffset 的方法:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (_aboutScroller.contentOffset.y >= 468 && _aboutScroller.contentOffset.y <= 668) {
[_aboutScroller setContentOffset:CGPointMake(0, 568) animated:YES];
} else if (_aboutScroller.contentOffset.y >= 1036 && _aboutScroller.contentOffset.y <= 1236) {
[_aboutScroller setContentOffset:CGPointMake(0, 1136) animated:YES];
} else if (_aboutScroller.contentOffset.y >= 1604 && _aboutScroller.contentOffset.y <= 1804) {
[_aboutScroller setContentOffset:CGPointMake(0, 1704) animated:YES];
} else if (_aboutScroller.contentOffset.y >= 2172 && _aboutScroller.contentOffset.y <= 2372) {
[_aboutScroller setContentOffset:CGPointMake(0, 2272) animated:YES];
}
}
关于ios - scrollViewWillEndDragging 吸附到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23047816/
我在 TabelViewCell 中有 CollectionView,我正在尝试为 CollectionView 的单元格进行分页和居中。但是当我使用方法时 func scrollViewWillEn
我有一个 View 覆盖在 UITableView 的顶部。但是当用户在顶部 View 上拖动时,我需要触发 UITableView 事件的滚动事件。 我在 View 上添加了 UIPanGestur
我找遍了所有地方,但找不到答案。所以,开始吧。我创建了一个长 ScrollView ,里面有 568 像素(全屏) View 。当用户向下滚动时,我希望 ScrollView 捕捉到特定位置。这是我的
我正在为我的 UICollectionView 创建自定义分页。我希望底部的一些单元格卡在屏幕边缘,但是,通过常规分页,滚动到下一页意味着如果页面底部的一半单元格显示,它只会显示另一半在下一页。我想让
documentation声明它是 points(每秒,我假设)?但是,我得到的值在 (.5, 3.5) 范围内。然后 ScrollView 在停止之前移动了数百个点。实际初速度应该相差几个数量级。
这是我的覆盖代码 - 它只是计算捕捉到的位置: - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(C
我正在为 targetContentOffset 设置一个新值在 scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)在 UIT
我希望我的 UIScrollView 以特定的增量值自然地滑动到结尾,对应于水平滚动 UIScrollView 的每 50 个宽度点。为此,我定制的 scrollViewWillEndDragging
我正在尝试在 iOS 5 中使用新的 scrollViewWillEndDragging:withVelocity:targetContentOffset: UIScrollView 委托(deleg
我在一个 View Controller 上有两个 UITableViews( View Controller 是他们的代表)。其中之一将取决于 scrollViewWillEndDragging:w
我在同一个 View Controller 上使用 UITableView 和 UICollectionView。 我想改变 UICollectionView 的滚动方式,所以我在扩展中添加了一个 s
我正在尝试使用 scrollViewWillEndDragging: 方法来滚动我自己的分页 UICollectionView,在两侧都有预览,类似于 App Store 应用程序。但是,如果我停止无
我正在尝试实现一个自定义标签栏,它是可滚动的并且在每个标签栏项目上都有分页。为此,我正在使用代理 scrollViewWillEndDragging:withVelocity:targetConten
如何用 Swift 编写此代码? 更新:发布了我试图转换的方法,最初发布了一个不同的方法,这不是我试图隐藏的方法 这适用于 Objective C,但不适用于 Swift。当我尝试将 ceilf 和
我希望我的垂直 UIScrollView 仅在用户向上滚动时停在最大内容偏移处,或者在用户向下滚动时停在最小内容偏移处。 我正在使用以下两个函数 func targetContentOffset(fo
我是一名优秀的程序员,十分优秀!