iOS开发- 点击通知栏回到顶部的动画效果
2023-09-11 14:21:22 时间
你可能经常会用到点击通知栏回到顶部的功能,那这么动画效果怎么实现呢?一开始博主也被误导了,用基础动画来写,麻烦不说,效果还不好,后来才知道原来系统提供了相应的方法,网上给出了好几种用法,还有种错误的用法,博主这里再总结下:
1.滚动到顶部
[_tableView setContentOffset:CGPointMake(0,0) animated:YES];
2.滚动到底部
CGPoint offset = CGPointMake(0,_tableView.contentSize.height - _tableView.frame.size.height);
[_tableView setContentOffset:offset animated:YES];
3.利用scrollToRowAtIndexPath:
可以滚动到tableView的任何位置
NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:6];
[_tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionBottom animated:YES];
这里注意,不能使用:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:0]; //0,1...都不行
即使你没有分组,一点就崩,用1报错如下:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: section (1) beyond bounds (1).'
看着是因为没那么多分组的原因,可是当你在多分组中用了,会报这样的错:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.'
说是需要包含section and row,由此我们可以摸清楚它的用法,请看第三条开始的代码。
相关文章
- 10个有用的第三方iOS开源库
- [转] iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么?
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- iOS之UI--辉光动画
- IOS 30多个iOS常用动画,带详细注释
- iOS之通过PaintCode快速实现交互动画的最方便方法 未解问题
- iOS开发UI篇—iOS开发中三种简单的动画设置
- iOS开发UI篇—ios应用数据存储方式(归档)
- iOS开发UI篇—ios应用数据存储方式(偏好设置)
- iOS动画相关(持续更新)
- IOS项目之弹出动画二
- IOS项目之弹出动画一
- IOS项目之弹出动画三
- IOS贝塞尔曲线圆形进度条和加载动画
- iOS中 蓝牙2.0详解/ios蓝牙设备详解
- 关东升的《iOS实战:图形图像、动画和多媒体卷(Swift版)》上市了
- iOS开发那些事-表视图UI设计模式
- EasyPlayer-RTSP播放器:从底层到上层专注于RTSP播放Windows、Android、iOS RTSP Player
- iOS push动画有延迟
- iOS swift present出UINavigationController然后present
- iOS 网络 HTTP(Hyper Text Transfer Protocol)超文本传输协议
- iOS(swift)动画
- ios直播开发基础,推流协议及流程
- iOS_25彩票_幸运转盘
- 猫猫学iOS 之第一次打开Xcode_git配置,git简单学习
- iOS项目开发实战——制作视图的缩放动画
- 【iOS】文件下载小记
- iOS_18_开关控制器_NavigationController_push道路_数据传输