use*_*533 5 objective-c uitableview uiscrollview bounce ios
UITableView当我下拉UITableView到负数时,我正在使用a 来对我的用户的个人资料图片(比如在Spotify应用程序中)实现缩放/非模糊效果contentOffset.y.这一切都很好......
现在,当一个用户下拉到一个contentOffset.y小于或等于某个值-let的时候调用它maintainOffsetY = 70.0- 并且他"放开"视图,我想保持这个,contentOffset直到用户再次"推"视图,而不是视图自动反弹回来contentOffset = (0,0).
为了实现这一点,我必须知道触摸何时开始和结束,我可以使用以下委托方法:
- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {
// is like touches begin
if ([scrollView isEqual:_tableView]) {
NSLog(@"touches began");
_touchesEnded = NO;
}
}
- (void) scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
// is like touches ended
NSLog(@"touches ended");
if ([scrollView isEqual:_tableView]) {
_touchesEnded = YES;
}
Run Code Online (Sandbox Code Playgroud)
}
然后进去
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Run Code Online (Sandbox Code Playgroud)
我检查是否contentOffset.y小于或等于maintainOffsetY,如果用户已经"放开"该表,那么它即将反弹(或已经反弹)回到contentOffset = (0,0).
它似乎不可能只让它反弹回来maintainOffsetY.有人知道解决方法或对如何解决这个问题有所了解吗?
任何帮助深表感谢!
要为滚动视图设置负偏移量,您可以使用它。
您需要保存滚动视图的初始内容插图。例如,如果您有半透明的导航栏,则它可能已经不为 0。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
contentInsetTopInitial = self.tableView.contentInset.top;
}
Run Code Online (Sandbox Code Playgroud)
然后写这个。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGPoint contentOffset = scrollView.contentOffset; // need to save contentOffset before changing contentInset
CGFloat contentOffsetY = contentOffset.y + contentInsetTopInitial; // calculate pure offset, without inset
if (contentOffsetY < -maintainOffsetY) {
scrollView.contentInset = UIEdgeInsetsMake(contentInsetTopInitial + maintainOffsetY, 0, maintainOffsetY, 0);
[scrollView setContentOffset:contentOffset animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助。
| 归档时间: |
|
| 查看次数: |
2371 次 |
| 最近记录: |