UIScrollView的相关笔记

  1. 当UIScrollview横向滚动时,如果在上面添加5个按钮,但当前scrollview 一页只能显示3个按钮,此时有一项要求,需要在点击第3个按钮时,scrollview自动向左滑动,显示后面的按钮等,需要在按钮点击方法或者UIScrollview的滑动代理方法scrollViewDidEndDecelerating里面添加下面内容。

CGFloat needMoveVisableOffset = btn.center.x - self.headerBkView.width/2;

if(needMoveVisableOffset < 0){

needMoveVisableOffset = 0;

}

CGFloat maxMoveOffset = self .headerBkView.contentSize.width - self.headerBkView.size.width;

if(needMoveVisableOffset > maxMoveOffset){

needMoveVisableOffset = maxMoveOffset;

}

**self** .headerBkView setContentOffset:CGPointMake(needMoveVisableOffset, 0) animated:**YES**\];

  1. 当拖动scrollview滑动的时候,正常情况下,下面两种方法都会执行,如果当拖动scrllview停止之前未减速或者未等scrollview滑动结束,立即切换了页面,此时scrollview不会掉用scrollViewDidEndDeceleration方法,只执行scrollViewDidEndDragging,此时需要在decelerate为NO时,重新执行后续动作。

//当离开UIScrollView的时候

  • (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

if(!decelerate){

// dosomething

}

}

//当UIScrollView停止滚动的时候

-(void)scrollViewDidEndDeceleration:(UIScrollView *)scrollView{

// dosomething

}

相关推荐
蒙小萌19934 小时前
Performance and metrics
ios
shughui5 小时前
APP、Web、H5、iOS与Android的区别及关系
android·前端·ios
Edward.W7 小时前
iOS 17+真机命令行操作对照表
macos·ios·cocoa
2501_916008891 天前
iOS开发APP上架全流程解析:从开发到App Store的完整指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915909062 天前
Charles 抓不到包怎么办?iOS 调试过程中如何判断请求路径
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
iOS和iPadOS文件管理系统全面解析与使用指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915921432 天前
iOS App 开发阶段性能优化,观察 CPU、内存和日志变化
android·ios·性能优化·小程序·uni-app·iphone·webview
游戏开发爱好者82 天前
在 iOS 开发、测试与上架过程中 如何做证书管理
android·ios·小程序·https·uni-app·iphone·webview
ii_best2 天前
按键精灵安卓/IOS手机助手 × 手机按键 App:1 分钟搞定设备连接(超详细教程)
android·ios·智能手机·自动化·编辑器
2501_916007472 天前
在没有 Mac 的情况下完成 iOS 应用上架 App Store
android·macos·ios·小程序·uni-app·iphone·webview