scrollView.h

scrollView.h

scrollView属性

contentOffset: 描述了内容视图相对于scrollView窗口的位置(当然是向上向左的偏移量咯)。默认值是CGPointZero,也就是(0,0)。当视图被拖动时,系统会不断修改该值。也可以通过setContentOffset:animated:方法让图片到达某个指定的位置。

@property(nonatomic)         CGPoint                      contentOffset;                  // default CGPointZero  在滚动视图中,contentOffset属性可以跟踪UIScrollView的具体位置,你能够自己获取和设置它,contentOffset的值是你当前可视内容在滚动视图上面偏移原来的左上角的偏移量

contentSize描述了有多大范围的内容需要使用scrollView的窗口来显示,其默认值为CGSizeZero,也就是一个宽和高都是0的范围。

@property(nonatomic)         CGSize                       contentSize;                    // default CGSizeZero
contentSize是内容大小,也就是可以滚动的大小,默认是0,没有滚动效果

contentInset: 表示scrollView的内边距,也就是内容视图边缘和scrollView的边缘的留空距离,默认值是UIEdgeInsetsZero,也就是没间距。这个属性用的不多,通常在需要刷新内容时才用得到。

@property(nonatomic)         UIEdgeInsets                 contentInset;                   // default UIEdgeInsetsZero. add additional scroll area around content contentInset增加你在contentSize中指定的内容能够滚动的上下左右区域的距离。

scrollView的委托对象,该委托对象必须实现UIScrollViewDelegate协议,这些方法会在合适的时候被调用。

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

directionalLockEnabled:是否锁定某个特定方向的滚动,默认值为NO。设置为YES时,一旦用户向水平或竖直方向拽动时,另一个方向的滚动则被锁定了。但是如果首次拽动是斜着的,那么则不会锁定方向。

@property(nonatomic,getter=isDirectionalLockEnabled) BOOL directionalLockEnabled;         // default NO. if YES, try to lock vertical or horizontal scrolling while dragging 默认是NO,可以在垂直和水平方向同时运动。当值是YES时,假如一开始是垂直或者水平运动,那么接下来会送定另外一个方向的滚动,加入一开始是对角方向移动,则不会禁止某个方向

scrollView的这种回弹机制,是可以设置的,相关的属性

bounces:描述的当scrollview的显示超过内容区域的边缘以及返回时,是否有弹性,默认值为YES。值为YES的时候,意味着到达contentSize所描绘的的边界的时候,拖动会产生弹性。值为No的时候,拖动到达边界时,会立即停止。所以,如果在上面的例子当中,将bounces设置为NO时,窗口中是不会显示contentSize范围外的内容的。

@property(nonatomic)         BOOL                         bounces;                        // default YES. if YES, bounces past edge of content and back again 默认是YES,就是滚动超过边界会反弹,有反弹回来的效果,如果是NO,那么滚动到达边界会立即停止

alwaysBounceVertical:默认值为NO,如果该值设为YES,并且bounces也设置为YES,那么,即使设置的contentSize比scrollView的size小,那么也是可以拖动的。

@property(nonatomic)         BOOL                         alwaysBounceVertical;           // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
默认是NO,如果是YES并且边界可以反弹,即使边界比较小,允许垂直拖动

alwaysBounceHorizontal:默认值为NO,如果该值设为YES,并且bounces也设置为YES,那么,即使设置的contentSize比scrollView的size小,那么也是可以拖动的。

@property(nonatomic)         BOOL                         alwaysBounceHorizontal;         // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally
默认是NO,如果是YES并且边界可以反弹,即使边界比较小,允许横向拖动

pagingEnabled:是否使用分页机制,默认值为NO。当设置为YES时,会按照scrollView的宽度对内容视图进行分页。

@property(nonatomic,getter=isPagingEnabled) BOOL          pagingEnabled __TVOS_PROHIBITED;// default NO. if YES, stop on multiples of view bounds
当值是YES会自动滚到视图边界的倍数上,默认为NO(也就是是否整页翻动)

scrollEnabled:视图是否可被拖动,默认值为YES。一旦该值设置为NO,则scrollView不再接受触屏事件,会直接传递响应链。

@property(nonatomic,getter=isScrollEnabled) BOOL          scrollEnabled;                  // default YES. turn off any dragging temporarily
默认是YES,决定是否可以滚动

状态条显示indicatorStyle showsHorizontalScrollIndicator showsVerticalScrollIndicator scrollIndicatorInsets flashScrollIndicators

showsHorizontalScrollIndicator : 当处于跟踪状态(tracking)时是否显示水平状态条,默认值为YES。下一节说明什么是跟踪状态。

@property(nonatomic)         BOOL                         showsHorizontalScrollIndicator; // default YES. show indicator while we are tracking. fades out after isTracking 滚动时是否显示水平滚动条

showsVerticalScrollIndicator : 当处于跟踪状态(tracking)时是否显示垂直状态条,默认值为YES。

@property(nonatomic)         BOOL                         showsVerticalScrollIndicator;   // default YES. show indicator while we are tracking. fades out after tracking  滚动时是否显示垂直滚动条

scrollIndicatorInsets : 状态条和scrollView边距的距离(暂时还没想明白为什么要有这个)。

@property(nonatomic)         UIEdgeInsets                 scrollIndicatorInsets;          // default is UIEdgeInsetsZero. adjust indicators inside of insets 设置滚动条的位置

indicatorStyle: 状态条的风格,默认值为UIScrollViewIndicatorStyleDefault。除此之外,还有UIScrollViewIndicatorStyleBlack, UIScrollViewIndicatorStyleWhite两种其他风格。可以用来和环境配色。

@property(nonatomic)         UIScrollViewIndicatorStyle   indicatorStyle;                 // default is UIScrollViewIndicatorStyleDefault
滚动条的样式,基本只是设置颜色,总共3个颜色:默认、黑、白

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
只有白色,小,在黑色背景下良好

};


其他设置

delaysContentTouches:是否推迟触屏手势处理,默认值为YES。设置为YES的时候,系统在确定是否发生scroll事件之后,才会处理触屏手势,否则,则会立即调用touchesShouldBegin:withEvent:inContentView:方法。

@property(nonatomic)         CGFloat                      decelerationRate NS_AVAILABLE_IOS(3_0);
// 设置手指放开后的减速率

方法

*1

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;  // animate at constant velocity to new offset
以恒定速度的动画到新的偏移量

*2

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;         // scroll so rect is just visible (nearest edges). nothing if rect completely visible 
// 上面这两个函数用来自动滚到想要的位置,此过程中设置有动画效果,停止时,触发该函数。当animated为YES的时候有动画效果

*3


- (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.

没有滚动条的滚动是一个有点复杂的。在触摸结束后,我们不知道用户将要滚动画着跟踪视图像控制。
在接触下来,我们开始一个计时器,也看任何运动。如果没有足够的时间改变位置,我们开始向中观的内容试图发送事件。如果用户拖拽足够远,我们切换回拖和取消在子视图的任何跟踪。
下面的方法是由滚动视图调用的,给子类重写点添加自定义行为。
你可以删除交货延迟 touchesBegen:withEvent: 设置子视图的delaysContentTouches


 */

状态跟踪

之前提到过跟踪状态(tracking)。相关的属性有三个:tracking dragging decelerate,这三个属性表明了当前视图的滚动状态。

tracking: 只读,一旦用户开始触摸视图(也许还没有开始拖动),该属性值为YES

@property(nonatomic,readonly,getter=isTracking)     BOOL tracking;        // returns YES if user has touched. may not yet have started dragging 当用户touch后还没有开始拖动的时候是YES,否则为NO

dragging: 只读,当用户开始拖动(手指已经在屏幕上滑动一段距离了),该属性值为YES

@property(nonatomic,readonly,getter=isDragging)     BOOL dragging;        // returns YES if user has started scrolling. this may require some time and or distance to move to initiate dragging 如果scrollView正在被拖动,返回YES(检测当前目标是否正在被拖拽)

decelerate: 只读,当用户松开手指,但视图仍在滚动时,该值返回YES

@property(nonatomic,readonly,getter=isDecelerating) BOOL decelerating;    // returns YES if user isn't dragging (touch up) but scroll view is still moving
当滚动后,手指放开但是孩子啊继续滚动中。这个时候是YES,其他时候是NO(监控当前目标是否正在减速)

其他设置

delaysContentTouches:是否推迟触屏手势处理,默认值为YES。设置为YES的时候,系统在确定是否发生scroll事件之后,才会处理触屏手势,否则,则会立即调用touchesShouldBegin:withEvent:inContentView:方法。

@property(nonatomic) BOOL delaysContentTouches;       // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses 默认是YES,当值是YES的时候,用户触碰开始,scrollView要延迟一会,看看用户是否有意图滚动。加入滚动了,那么捕捉touch-down时间,否则就不捕捉。加入值是NO,当用户触碰,scrollView会立即触发(控制试图是否延时调用开始滚动的方法)

@property(nonatomic) BOOL canCancelContentTouches;    // default is YES. if NO, then once we start tracking, we don't try to drag if the touch moves. this has no effect on presses 当值是YES的时候,用户触碰后,然后在一定时间内没有移动,scrollView发送tracking events,然后用户移动手指足够长度触发滚动事件,这个时候scrollView发送了touchesCancelled:withEvent:到subView,然后scrollView开始滚动。假如为NO,scrollView发送tracking events后,就算用户移动手指,scrollView也不会滚动(控制控件是否接触取消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
// this has no effect on presses
// default returns YES 默认返回是

方法

*1

- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view;
// 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
// this has no effect on presses

*2

- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
// 开始发送tracking message消息给subview的时候调用这个方法,决定是否发送tracking message消息给subView,假如返回NO,发送,YES则不发送




/*
 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:
 */

缩放

minimumZoomScale: 最小放大比例,默认值为1,不得大于maxmumZoomScale

@property(nonatomic) CGFloat minimumZoomScale;     // default is 1.0
表示能缩最小的倍数

maximumZoomScale: 最大放大比例,默认值为1,不得小于minimumZoomScale

@property(nonatomic) CGFloat maximumZoomScale;     // default is 1.0. must be > minimum zoom scale to enable zooming 表示能放最大的倍数

zoomScale: 当前的缩放比例。系统会根据缩放过程调整此值。

@property(nonatomic) CGFloat zoomScale NS_AVAILABLE_IOS(3_0);            // default is 1.0

方法

setZoomScale:animated:: 程序设置缩放大小。
- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);
zoomToRect:animated: 将内容视图缩放到指定的Rect中。
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated NS_AVAILABLE_IOS(3_0);

bouncesZoom: 描述在缩放超过缩放比例时,是否bounce,默认值为YES。如果值为NO,则达到最大或最小缩放比例时会立即停止缩放。否则,产生弹簧效果。


@property(nonatomic) BOOL  bouncesZoom;          // default is YES. if set, user can go past min/max zoom while gesturing and the zoom will animate to the min/max value at gesture end 和bounces类似,区别在于:这个效果反应在缩放方面加入缩放超过最大缩放,那么会有反弹效果;假如是NO,则到达最大或者最小的时候立即停止

zooming: 只读,用户是否正在进行缩放手势

@property(nonatomic,readonly,getter=isZooming)       BOOL zooming;       // returns YES if user in zoom gesture
当正在缩放的时候是YES,否则是NO

zoomBouncing:只读,当缩放超过最大或者最小范围的时候,回弹到最大最小范围的过程中,该值返回YES。

@property(nonatomic,readonly,getter=isZoomBouncing)  BOOL zoomBouncing;  // returns YES if we are in the middle of zooming back to the min/max value 当内容放大到最大或者缩小到最小的时候值是YES,否则是NO

// 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.

scrollToTop:是否启动“滚动至顶端”手势,默认值为YES。当用户使用了“滚动至顶端”手势(轻击状态栏)时,系统会要求离状态栏最近的scrollView滚动到顶端,如果scrollToTop设置为NO,则该scrollView的delegate的scrollViewShouldScrollToTop:方法会返回NO,不会滚动到顶端。否则,则会滚动到顶端。滚动到顶端之后,会给delegate发送scrollViewDidScrollToTop:消息。需要注意的是,在iphone上,如果有多个scrollview的scrollToTop参数设置为YES的时候,“滚动至顶端”手势会失效。

@property(nonatomic) BOOL  scrollsToTop __TVOS_PROHIBITED;          // default is YES.
是否支持滑动到最顶端(点击状态条的时候)
// Use these accessors to configure the scroll view's built-in gesture recognizers.
// Do not change the gestures' delegates or override the getters for these properties.

panGestureRecognizer

@property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer NS_AVAILABLE_IOS(5_0);
// `pinchGestureRecognizer` will return nil when zooming is disabled.

pinchGestureRecognizer

@property(nullable, nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer NS_AVAILABLE_IOS(5_0);
// `directionalPressGestureRecognizer` is disabled by default, but can be enabled to perform scrolling in response to up / down / left / right arrow button presses directly, instead of scrolling indirectly in response to focus updates.

directionalPressGestureRecognizer

@property(nonatomic, readonly) UIGestureRecognizer *directionalPressGestureRecognizer UIKIT_
AVAILABLE_TVOS_ONLY(9_0);

keyboardDismissMode: 当拖动发生时,键盘的消失模式,默认值是不消失

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

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);


@protocol UIScrollViewDelegate<NSObject>

@optional

*1scrollView已经滑动

// scrollView已经滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;                                               // any offset changes

解释

- (void)scrollViewDidScroll:(UIScrollView *)scrollView; 
// any offset changes 只要scrollView的content 这个方法在任何方式触发 contentOffset 
// 变化的时候都会被调用(包括用户拖动,减速过程,直接通过代码设置等),可以用于监控 contentOffset 
// 的变化,并根据当前的 contentOffset 对其他 view 做出随动调整。

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

列:

//scrollView滚动时,就调用该方法。任何offset值改变都调用该方法。即滚动过程中,调用多次 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidScroll");
    CGPoint point=scrollView.contentOffset;
    NSLog(@"%f,%f",point.x,point.y);
    // 从中可以读取contentOffset属性以确定其滚动到的位置。

    // 注意:当ContentSize属性小于Frame时,将不会出发滚动


}

*2视图已经放大或者缩小

// 视图已经放大或者缩小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2); // any zoom scale changes

列:

// 当scrollView缩放时,调用该方法。在缩放过程中,回多次调用
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidScroll");
    float value=scrollView.zoomScale;
    NSLog(@"%f",value);


}

*3scrollView开始拖动

// scrollView开始拖动
called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 

解释

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 
// 用户开始拖动 scroll view 的时候被调用,可能需要一些时间和距离移动之后才会触发。

// 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)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

    NSLog(@"scrollViewWillBeginDragging");

}

*4scrollView即将停止拖拽

// 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);

解释:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);
// 在 didEndDragging 前被调用,当 willEndDragging 方法中 velocity 为 CGPointZero
//(结束拖动时两个方向都没有速度)时,didEndDragging 中的 decelerate 为 NO,即没有减速过程,
//willBeginDecelerating 和 didEndDecelerating 也就不会被调用。反之,
// 当 velocity 不为 CGPointZero 时,scroll view 会以 velocity 为初速度,
// 减速直到 targetContentOffset。

列:

// 滑动scrollView,并且手指离开时执行。一次有效滑动,只执行一次。
// 当pagingEnabled属性为YES时,不调用,该方法
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

    NSLog(@"scrollViewWillEndDragging");

}

*5scrollView结束拖动

// scrollView结束拖动
//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)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
// 在用户结束拖动后被调用,decelerate 为 YES 时,
// 结束拖动后会有减速过程。注,在 didEndDragging 之后,如果有减速过程,
// scroll view 的 dragging 并不会立即置为 NO,而是要等到减速结束之后,
// 所以这个 dragging 属性的实际语义更接近 scrolling。

列:

//结束拖动,手指离开屏幕,decelerate(是否是减速状态)
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
     
//    decelerate == YES?NSLog(@"减速"):NSLog(@"停止");
}

*6scrollView即将减速完成

// scrollView即将减速完成
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // called on finger up as we are moving

解释:

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // 减速动画开始前被调用

列:

// 滑动减速时调用该方法。
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

    NSLog(@"scrollViewWillBeginDecelerating");
    // 该方法在scrollViewDidEndDragging方法之后。


}

*7scrollView减速完成

// scrollView减速完成
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll view grinds to a halt

解释:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      
// 减速动画结束时被调用,这里有一种特殊情况:当一次减速动画尚未结束的时候再次 drag scroll view,
// didEndDecelerating 不会被调用,并且这时 scroll view 的 dragging 和 decelerating 属性都是 YES。
// 新的 dragging 如果有加速度,那么 willBeginDecelerating 会再一次被调用,然后才是 didEndDecelerating;
// 如果没有加速度,虽然 willBeginDecelerating 不会被调用,但前一次留下的 didEndDecelerating 会被调用      

列:

// 滚动视图减速完成,滚动将停止时,调用该方法。一次有效滑动,只执行一次。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidEndDecelerating");

    [_scrollView setContentOffset:CGPointMake(0, 500) animated:YES];

}

*8scrollView结束减速并且必须有动画效果才会触发(必须要有动画效果)

// scrollView结束减速并且必须有动画效果才会触发(必须要有动画效果)
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

列:

// 当滚动视图动画完成后,调用该方法,如果没有动画,那么该方法将不被调用
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{

    NSLog(@"scrollViewDidEndScrollingAnimation");
    // 有效的动画方法为:
    //    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 方法
    //    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 方法


}

*9返回缩放后的试图,但只能返回scrollView(内容)上的子视图

// 返回缩放后的试图,但只能返回scrollView(内容)上的子视图
- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     // return a view that will be scaled. if delegate returns nil, nothing happens

解释:

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;     
// return a view that will be scaled. if delegate returns nil, nothing happens
告诉代理要缩放那个控件。 

列:

//设置放大缩小的视图,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;   
{
   NSLog(@"viewForZoomingInScrollView");
    return viewA;
}

*10开始缩放

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

解释:

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2); 
// called before the scroll view begins zooming its content缩放开始的时候调用

列:

// 当将要开始缩放时,执行该方法。一次有效缩放,就只执行一次。
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{

    NSLog(@"scrollViewWillBeginZooming");

}

*11结束缩放

// 结束缩放

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

解释:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale; 
// scale between minimum and maximum. called after any 'bounce' animations缩放完毕的时候调用。

列:

// 当缩放结束后,并且缩放大小回到minimumZoomScale与maximumZoomScale之间后(我们也许会超出缩放范围),调用该方法。
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{

    NSLog(@"scrollViewDidEndZooming");

}

*12点击状态栏,调用此方法,此方法能实现的前提是scrollToTop的属性是YES

// 点击状态栏,调用此方法,此方法能实现的前提是scrollToTop的属性是YES
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   // return a yes if you want to scroll to the top. if not defined, assumes YES

解释:

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   // return a yes if you want to scroll to the top. if not defined, assumes YES- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;      
// called when scrolling animation finished. may be called immediately if already at top滚动动画完成时调用。

列:

// 指示当用户点击状态栏后,滚动视图是否能够滚动到顶部。需要设置滚动视图的属性:_scrollView.scrollsToTop=YES;
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{

    return YES;


}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;   
{
    NSLog(@"scrollViewShouldScrollToTop");
   return YES;
}

*13scrollView已经回到顶部了

// scrollView已经回到顶部了
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;      // called when scrolling animation finished. may be called immediately if already at top
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,392评论 5 470
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,258评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,417评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,992评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,930评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,199评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,652评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,327评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,463评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,382评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,432评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,118评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,704评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,787评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,999评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,476评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,057评论 2 341

推荐阅读更多精彩内容