UIScrollView 属性和方法

本文详细介绍了UIScrollView的属性和方法,包括滚动、缩放等交互行为的实现原理。解释了UIScrollView的多种状态及其触发的方法,并探讨了触摸事件传递机制。

typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {

    UIScrollViewIndicatorStyleDefault,     // black with white border. good against any background

    UIScrollViewIndicatorStyleBlack,       // black only. smaller. good against a white background

    UIScrollViewIndicatorStyleWhite        // white only. smaller. good against a black background

};


typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) {

    UIScrollViewKeyboardDismissModeNone,

    UIScrollViewKeyboardDismissModeOnDrag,      // dismisses the keyboard when a drag begins

    UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss

} NS_ENUM_AVAILABLE_IOS(7_0);


UIKIT_EXTERN const CGFloat UIScrollViewDecelerationRateNormal NS_AVAILABLE_IOS(3_0);

UIKIT_EXTERN const CGFloat UIScrollViewDecelerationRateFast NS_AVAILABLE_IOS(3_0);


@class UIEvent, UIImageView, UIPanGestureRecognizer, UIPinchGestureRecognizer;

@protocol UIScrollViewDelegate;


NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding> {

  @package

    id                _delegate;

}


@property(nonatomic)         CGPoint                      contentOffset;                  // 表示scrollview的偏移量

@property(nonatomic)         CGSize                       contentSize;                    // scrollview的滚动范围

@property(nonatomic)         UIEdgeInsets                 contentInset;                   // contentview四周的扩展大小,相当于改变了contentview的大小

@property(nonatomic,assign) id<UIScrollViewDelegate>      delegate;                       // default nil. weak reference

@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled;         // 指定空间只能在一个反向上滚动

@property(nonatomic)         BOOL                         bounces;                        //控件遇到边框是否反弹

@property(nonatomic)         BOOL                         alwaysBounceVertical;           // 控件垂直反向遇到边框是否反弹

@property(nonatomic)         BOOL                         alwaysBounceHorizontal;         // 控件水平反向遇到边框是否反弹

@property(nonatomic,getter=isPagingEnabled) BOOL          pagingEnabled;                  // 控件是否整页滚动

@property(nonatomic,getter=isScrollEnabled) BOOL          scrollEnabled;                  // 控件是否能滚动

@property(nonatomic)         BOOL                         showsHorizontalScrollIndicator; // 控件是否显示水平滚动条

@property(nonatomic)         BOOL                         showsVerticalScrollIndicator;   // 控件是否显示垂直滚动条

@property(nonatomic)         UIEdgeInsets                 scrollIndicatorInsets;          // 指定滚动条在scrollview中的位置

@property(nonatomic)         UIScrollViewIndicatorStyle   indicatorStyle;                 // 设定滚动条的样式

@property(nonatomic)         CGFloat                      decelerationRate NS_AVAILABLE_IOS(3_0);改变scrollview的速度点位置


- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;         // scroll so rect is just visible (nearest edges). nothing if rect completely visible


- (void)flashScrollIndicators;             // displays the scroll indicators for a short time. This should be done whenever you bring the scroll view to front.


/*

 Scrolling with no scroll bars is a bit complex. on touch down, we don't know if the user will want to scroll or track a subview like a control.

 on touch down, we start a timer and also look at any movement. if the time elapses without sufficient change in position, we start sending events to

 the hit view in the content subview. if the user then drags far enough, we switch back to dragging and cancel any tracking in the subview.

 the methods below are called by the scroll view and give subclasses override points to add in custom behaviour.

 you can remove the delay in delivery of touchesBegan:withEvent: to subviews by setting delaysContentTouches to NO.

 */


@property(nonatomic,readonly,getter=isTracking)     BOOL tracking;        // 监控当前目标是否被跟踪

@property(nonatomic,readonly,getter=isDragging)     BOOL dragging;        // 监控当前目标是否被拖拽

@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating;    // 监控当前目标是否正在减速


@property(nonatomic) BOOL delaysContentTouches;       // 控制视图是否延迟调用开始滚动的方法

@property(nonatomic) BOOL canCancelContentTouches;    // 控制控件是否接触取消touch事件


// override points for subclasses to control delivery of touch events to subviews of the scroll view

// called before touches are delivered to a subview of the scroll view. if it returns NO the touches will not be delivered to the subview

// default returns YES

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view; 决定自己是否可以接受touch事件

// called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur

// not called if canCancelContentTouches is NO. default returns YES if view isn't a UIControl

- (BOOL)touchesShouldCancelInContentView:(UIView *)view; 开始发送 tracking messages 消息给subview 的时候调用这个方法,决定是否发送 tracking messages 消息到subview。假如返回NO,发送。YES 则不发送。
假如 canCancelContentTouches属性是NO,则不调用这个方法来影响如何处理滚动手势


/*

 the following properties and methods are for zooming. as the user tracks with two fingers, we adjust the offset and the scale of the content. When the gesture ends, you should update the content

 as necessary. Note that the gesture can end and a finger could still be down. While the gesture is in progress, we do not send any tracking calls to the subview.

 the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale: in order for zooming to work and the max/min zoom scale must be different

 note that we are not scaling the actual scroll view but the 'content view' returned by the delegate. the delegate must return a subview, not the scroll view itself, from viewForZoomingInScrollview:

 */


@property(nonatomic) CGFloat minimumZoomScale;     // 缩小的最小比例

@property(nonatomic) CGFloat maximumZoomScale;     // 放大的最大比例


@property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0);            // 设置变化比例

- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);

- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);


@property(nonatomic) BOOL  bouncesZoom;          // 控制缩放的时候是否反弹


@property(nonatomic,readonly,getter=isZooming)       BOOL zooming;       //判断控件的大小是否正在被改变

@property(nonatomic,readonly,getter=isZoomBouncing)  BOOL zoomBouncing;  // 判断是否正在进行缩放反弹


// When the user taps the status bar, the scroll view beneath the touch which is closest to the status bar will be scrolled to top, but only if its `scrollsToTop` property is YES, its delegate does not return NO from `shouldScrollViewScrollToTop`, and it is not already at the top.

// On iPhone, we execute this gesture only if there's one on-screen scroll view with `scrollsToTop` == YES. If more than one is found, none will be scrolled.

@property(nonatomic) BOOL  scrollsToTop;          // 滚动到顶部



@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);按下手势

// `pinchGestureRecognizer` will return nil when zooming is disabled.

@property(nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);捏和的手势


@property(nonatomic) UIScrollViewKeyboardDismissMode keyboardDismissMode NS_AVAILABLE_IOS(7_0); // default is UIScrollViewKeyboardDismissModeNone

设置键盘的消失模式


@end


@protocol UIScrollViewDelegate<NSObject>


@optional


- (void)scrollViewDidScroll:(UIScrollView *)scrollView;                                               // any offset changes视图已经开始滑动所触发的方法

- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // any zoom scale changes视图开始缩放触发的方法


// called on start of dragging (may require some time and or distance to move)

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;视图开始拽动所触发的方法

// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

视图拖动结束所触发的方法

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // called on finger up as we are moving视图开始减速时所触发的方法

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll view grinds to a halt视图结束减速时所触发的方法


- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

视图动画结束时触发的方法,使用set方法设置偏移量后回触发

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     // return a view that will be scaled. if delegate returns nil, nothing happens返回进行缩放的视图

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2); // called before the scroll view begins zooming its content

视图内容将要开始缩放时触发的方法

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale; // scale between minimum and maximum. called after any 'bounce' animations

视图内容结束缩放时触发的方法

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   // return a yes if you want to scroll to the top. if not defined, assumes YES返回yes,开启快捷滚动回顶端,将要滚动时调用

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;      // called when scrolling animation finished. may be called immediately if already at top视图快捷滚动回顶端开始动作时调用




补充几点:

从你的手指touch屏幕开始,scrollView开始一个timer,如果:

1.  150ms内如果你的手指没有任何动作,消息就会传给subView。

2.  150ms内手指有明显的滑动(一个swipe动作),scrollView就会滚动,消息不会传给subView,这里就是产生问题二的原因。

3. 150ms内手指没有滑动,scrollView将消息传给subView,但是之后手指开始滑动,scrollView传送touchesCancelled消息给subView,然后开始滚动。

观察下tableView的情况,你先按住一个cell,cell开始高亮,手不要放开,开始滑动,tableView开始滚动,高亮取消。

delaysContentTouches的作用:

这个标志默认是YES,使用上面的150ms的timer,如果设置为NO,touch事件立即传递给subView,不会有150ms的等待。

cancelsTouches的作用:

这个标准默认为YES,如果设置为NO,这消息一旦传递给subView,这scroll事件不会再发生。


采用PyQt5框架与Python编程语言构建图书信息管理平台 本项目基于Python编程环境,结合PyQt5图形界面开发库,设计实现了一套完整的图书信息管理解决方案。该系统主要面向图书馆、书店等机构的日常运营需求,通过模块化设计实现了图书信息的标准化管理流程。 系统架构采用典型的三层设计模式,包含数据存储层、业务逻辑层用户界面层。数据持久化方案支持SQLite轻量级数据库与MySQL企业级数据库的双重配置选项,通过统一的数据库操作接口实现数据存取隔离。在数据建模方面,设计了包含图书基本信息、读者档案、借阅记录等核心数据实体,各实体间通过主外键约束建立关联关系。 核心功能模块包含六大子系统: 1. 图书编目管理:支持国际标准书号、中国图书馆分类法等专业元数据的规范化著录,提供批量导入与单条录入两种数据采集方式 2. 库存动态监控:实时追踪在架数量、借出状态、预约队列等流通指标,设置库存预警阈值自动提醒补货 3. 读者服务管理:建立完整的读者信用评价体系,记录借阅历史与违规行为,实施差异化借阅权限管理 4. 流通业务处理:涵盖借书登记、归还处理、续借申请、逾期计算等标准业务流程,支持射频识别技术设备集成 5. 统计报表生成:按日/月/年周期自动生成流通统计、热门图书排行、读者活跃度等多维度分析图表 6. 系统维护配置:提供用户权限分级管理、数据备份恢复、操作日志审计等管理功能 在技术实现层面,界面设计遵循Material Design设计规范,采用QSS样式表实现视觉定制化。通过信号槽机制实现前后端数据双向绑定,运用多线程处理技术保障界面响应流畅度。数据验证机制包含前端格式校验与后端业务规则双重保障,关键操作均设有二次确认流程。 该系统适用于中小型图书管理场景,通过可扩展的插件架构支持功能模块的灵活组合。开发过程中特别注重代码的可维护性,采用面向对象编程范式实现高内聚低耦合的组件设计,为后续功能迭代奠定技术基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
《基于SSM架构的学籍数据管理平台技术解析》 在当代数字化教育背景下,数据管理平台已成为教育机构运营的核心支撑。本系统以SSM技术组合为基础架构,构建了一套完整的学籍信息处理体系,通过系统化的技术方案实现教育数据的规范化管理与智能分析。以下从架构设计、技术实现与功能模块三个维度展开说明。 一、系统架构设计 该平台采用分层式架构设计,充分体现模块化与可维护性特征。Spring框架作为核心容器,通过依赖注入机制实现组件解耦;SpringMVC架构负责前端请求的路由与响应处理;MyBatis数据层框架则封装了数据库交互过程,通过映射配置简化SQL操作。三层架构协同工作,形成高内聚低耦合的技术体系。 二、技术实现要点 1. Spring容器:基于控制反转原则管理业务对象生命周期,结合面向切面编程实现事务控制与日志管理 2. SpringMVC模块:采用模型-视图-控制器设计范式,规范Web层开发流程,支持RESTful接口设计 3. MyBatis组件:通过XML配置实现对象关系映射,提供动态SQL生成机制,显著减少冗余编码 三、核心功能模块 1. 学籍信息维护:实现学员基本资料的增删改查操作,涵盖学籍编号、个人信息、所属院系等关键字段 2. 学业成绩管理:支持课程分数录入与批量处理,提供多维度统计分析功能 3. 教学组织管理:建立班级体系与学员关联关系,实现分级数据管理 4. 权限控制机制:基于角色访问控制模型,划分管理员、教职工、学员三级操作权限 5. 系统审计功能:完整记录用户操作轨迹,构建安全追踪体系 四、系统开发方法论 在项目生命周期中,采用结构化开发流程。前期通过需求调研确定系统边界,中期完成数据库范式设计与接口规范制定,后期采用迭代开发模式配合自动化测试,确保系统交付质量。 五、技术演进展望 当前系统虽未集成智能算法,但为未来升级预留了扩展接口。可预见的技术演进方向包括:基于学习行为数据的智能预警、个性化学习路径推荐等深度应用场景。 综上所述,该平台通过SSM技术体系实现了教育管理数据的标准化处理,既展示了现代软件开发范式的实践价值,也为教育信息化建设提供了可复用的技术方案。这种系统化的问题解决思路,充分体现了软件工程方法在教育领域的应用潜力。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值