UIScrollView.h
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UIGeometry.h>
#import <UIKit/UIKitDefines.h>
NS_ASSUME_NONNULL_BEGIN
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 constCGFloat UIScrollViewDecelerationRateNormal NS_AVAILABLE_IOS(3_0);
UIKIT_EXTERN constCGFloat UIScrollViewDecelerationRateFast NS_AVAILABLE_IOS(3_0);
@class UIEvent,UIImageView, UIPanGestureRecognizer,UIPinchGestureRecognizer;
@protocol UIScrollViewDelegate;
//***************************************
//UIScrollView(滚动视图,继承与UIView)
NS_CLASS_AVAILABLE_IOS(2_0)@interface UIScrollView :UIView <NSCoding>
//内容的偏移位置。默认为(0,0),左上角原点。
@property(nonatomic) CGPoint contentOffset;
//内容的大小
@property(nonatomic) CGSize contentSize;
//内容视图在scrollview中的位置,UIEdgeInsets描述一个矩形区域默认UIEdgeInsetsZero
@property(nonatomic) UIEdgeInsets contentInset; @property(nullable,nonatomic,weak)id<UIScrollViewDelegate> delegate;
//指定控件是否只能在一个方向上滚动,默认NO
@property(nonatomic,getter=isDirectionalLockEnabled)BOOL directionalLockEnabled;
//反弹效果(默认是)
@property(nonatomic) BOOL bounces;
//是否有垂直反弹效果
@property(nonatomic) BOOL alwaysBounceVertical;
//是否有水平反弹效果
@property(nonatomic) BOOL alwaysBounceHorizontal;
//是否是页移动效果(默认NO)
@property(nonatomic,getter=isPagingEnabled)BOOL pagingEnabled;
//是否可以滚动(默认是)
@property(nonatomic,getter=isScrollEnabled)BOOL scrollEnabled;
//在滑动时是否显示水平的轨迹条(默认是)
@property(nonatomic) BOOL showsHorizontalScrollIndicator;
//在滑动时是否显示垂直的轨迹条(默认是)
@property(nonatomic) BOOL showsVerticalScrollIndicator;
//滚动条在滚动视图中的位置
@property(nonatomic) UIEdgeInsets scrollIndicatorInsets; // default is UIEdgeInsetsZero. adjust indicators inside of insets
//轨迹条的样式(默认UIScrollViewIndicatorStyleDefault)
@property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle;
//滑动速率
@property(nonatomic) CGFloat decelerationRateNS_AVAILABLE_IOS(3_0);
//设置内容的偏移位置,带动画
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;
- (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.
//用户已经触屏,但还拖动,返回YES。
@property(nonatomic,readonly,getter=isTracking) BOOL tracking;
//拖动中,返回YES。
@property(nonatomic,readonly,getter=isDragging) BOOL dragging;
//滑动中(用户不在拖动,但是仍在滑动),返回YES
@property(nonatomic,readonly,getter=isDecelerating)BOOL decelerating;
//是否延迟调用touchesShouldBegin:withEvent:inContentView
@property(nonatomic)BOOLdelaysContentTouches;
//默认是,如果为NO,我们保持触屏状态,移动手指,将不能拖动。
@property(nonatomic)BOOLcanCancelContentTouches;
// 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<UITouch *> *)touches withEvent:(nullableUIEvent *)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
- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
/最小缩放比例default is 1.0
@property(nonatomic)CGFloat minimumZoomScale;
//最大缩放比例default is 1.0. must be > minimum zoom scale to enable zooming
@property(nonatomic)CGFloatmaximumZoomScale;
//缩放比例 default is 1.0
@property(nonatomic)CGFloat zoomScaleNS_AVAILABLE_IOS(3_0);
- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animatedNS_AVAILABLE_IOS(3_0);
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animatedNS_AVAILABLE_IOS(3_0);
//缩放时候是否遇边界反弹 default is YES.
@property(nonatomic)BOOL bouncesZoom;
//正在缩放
@property(nonatomic,readonly,getter=isZooming) BOOL zooming;
//正在缩放反弹
@property(nonatomic,readonly,getter=isZoomBouncing) BOOLzoomBouncing;
//点击设备的状态栏时,scrollsToTop == YES的控件滚动返回至顶部。
/*
所以要实现某一UIScrollView的实例点击设备状态栏返回顶部,则需要关闭其他的UIScrollView的实例的scrollsToTop属性为NO。很好理解:若多个scrollView响应返回顶部的事件,系统就不知道到底要将那个scrollView返回顶部了,因此也就不做任何操作了。。。
*/
@property(nonatomic)BOOL scrollsToTop; // default is YES.
//拖动收拾
@property(nonatomic,readonly) UIPanGestureRecognizer *panGestureRecognizerNS_AVAILABLE_IOS(5_0);
//捏合手势
@property(nullable,nonatomic, readonly)UIPinchGestureRecognizer *pinchGestureRecognizerNS_AVAILABLE_IOS(5_0);
//设置键盘消失的方式
@property(nonatomic)UIScrollViewKeyboardDismissMode keyboardDismissModeNS_AVAILABLE_IOS(7_0);// default is UIScrollViewKeyboardDismissModeNone
@end
@protocol UIScrollViewDelegate<NSObject>
@optional
//只要滚动了就会触发
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
//只要缩放了就会触发
- (void)scrollViewDidZoom:(UIScrollView *)scrollViewNS_AVAILABLE_IOS(3_2);
//开始拖拽
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
//即将停止拖拽
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);
//已经停止拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
//将开始降速时
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
//减速停止了时执行,
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
//只要停止滚动了就会触发
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
//指定要缩放哪个视图
- (nullableUIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; // return a view that will be scaled. if delegate returns nil, nothing happens
//即将开始缩放时
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullableUIView *)view NS_AVAILABLE_IOS(3_2);
//已经停止缩放时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullableUIView *)view atScale:(CGFloat)scale;
- (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
@end
NS_ASSUME_NONNULL_END