美文网首页
UIScorllView

UIScorllView

作者: 第1001号群众演员 | 来源:发表于2016-11-06 09:57 被阅读20次

    UIScrollView:继承与UIView,该类的对象包含的控件可在手机上进行缩放、滑动、滚动

    使用步骤:

    1、创建一个UIScrollView对象

    2、为创建的对象添加子控件

    3、设置对象的ContentSize属性(只能手动设置)

    UIScrollView对象的常用属性:

    是否显示水平滚动条的属性默认有滚动条

    @property(nonatomic) BOOLshowsHorizontalScrollIndicator;// default YES. show indicator while weare tracking. fades out after tracking

    是否显示垂直滚动条的属性默认有滚动条

    @property(nonatomic)BOOLshowsVerticalScrollIndicator;//default YES. show indicator while we are tracking. fades out after tracking

    注:水平和垂直滚动条为UIView对象

    保存弹簧效果的属性默认有弹簧效果

    @property(nonatomic) BOOLbounces;// default YES. if YES, bouncespast edge of content and back again

    保存对象是否可以滚动的属性默认可以滚动

    @property(nonatomic,getter=isScrollEnabled)BOOLscrollEnabled;// default YES. turn off any draggingtemporarily

    滚动内边距属性

    @property(nonatomic)UIEdgeInsetscontentInset;// defaultUIEdgeInsetsZero. add additional scroll area around content

    滚动的坐标,保存当前滚动屏幕的显示的位置的坐标

    @property(nonatomic) CGPointcontentOffset;// default CGPointZero

    滚动动画

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

    缩小时最小可以缩小的倍数

    @property(nonatomic) CGFloatminimumZoomScale;// default is 1.0

    发大时最大可以发大的倍数

    @property(nonatomic) CGFloatmaximumZoomScale;// default is 1.0.must be > minimum zoom scale to enable zooming

    UIScrollView对象的分页功能,以自身的宽度进行分页

    @property(nonatomic,getter=isPagingEnabled)BOOLpagingEnabled __TVOS_PROHIBITED;//default NO. if YES, stop on multiples of view bounds

    关于最大X值,最大Y值的函数:

    返回值为传入的rect的X+W

    CG_EXTERN CGFloat CGRectGetMaxX(CGRectrect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

    返回值为传入的rect的Y+H

    CG_EXTERN CGFloat CGRectGetMaxY(CGRectrect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

    UIScrollViewDelegate:UIScrollView的代理协议,系统默认提供的代理协议

    UIScrollView的代理的成员:遵守UIScrollViewDelegate代理协议即可

    @property(nullable,nonatomic,weak)id delegate;// default nil. weak reference

    常用的协议中的方法:方法中的参数为当前滚动的UIScrollView对象

    正在滑动时调用的方法

    -(void)scrollViewDidScroll:(UIScrollView*)scrollView;// any offset changes

    将要滑动时调用的方法

    - (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView;

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

    结束滑动时调用的方法

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

    滑动停止时调用的方法

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called whenscroll view grinds to a halt

    当我们需要对UIScrollView中的控件发大缩小时,需要确定发大的控件,我们使用下面这个方法将需要发大的控件作为返回值即可

    - (nullable UIView *)viewForZoomingInScrollView:(UIScrollView*)scrollView;// return a view thatwill be scaled. if delegate returns nil, nothing happens

    一般我们给当前的View作为UIScrollView对象的代理。使当前的View遵守UIScrollViewDelegate代理协议,编写对象的代理方法即可。

    相关文章

      网友评论

          本文标题:UIScorllView

          本文链接:https://www.haomeiwen.com/subject/stoguttx.html