UIScrollView属性详解

#import<Foundation/Foundation.h>

#import<CoreGraphics/CoreGraphics.h>

#import<UIKit/UIView.h>

#import<UIKit/UIGeometry.h>

#import<UIKit/UIKitDefines.h>


typedef enum{

   UIScrollViewIndicatorStyleDefault,    // black with white border. good againstany background

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

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

}UIScrollViewIndicatorStyle;


UIKIT_EXTERNconst float UIScrollViewDecelerationRateNormal__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

UIKIT_EXTERNconst float UIScrollViewDecelerationRateFast__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);


@class UIEvent, UIImageView, UIPanGestureRecognizer, UIPinchGestureRecognizer;

@protocolUIScrollViewDelegate;


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

  @package

    CGSize      _contentSize;

    UIEdgeInsets _contentInset;

    id         _delegate;

    UIImageView* _verticalScrollIndicator;

    UIImageView*_horizontalScrollIndicator;

    UIEdgeInsets _scrollIndicatorInset;

    struct {

      unsignedint tracking:1;

      unsignedint dragging:1;

      unsignedintverticalBounceEnabled:1;

      unsignedinthorizontalBounceEnabled:1;

      unsignedintverticalBouncing:1;

      unsignedinthorizontalBouncing:1;

      unsignedint bouncesZoom:1;

      unsignedint zoomBouncing:1;

      unsignedintalwaysBounceHorizontal:1;

      unsignedintalwaysBounceVertical:1;

      unsignedintcanCancelContentTouches:1;

      unsignedintdelaysContentTouches:1;

      unsignedintprogrammaticScrollDisabled:1;

      unsignedint scrollDisabled:1;

      unsignedint zoomDisabled:1;

      unsignedintscrollTriggered:1;

      unsignedintscrollDisabledOnTouchBegan:1;

      unsignedintignoreNextTouchesMoved:1;

      unsignedintcancelNextContentTouchEnded:1;

      unsignedintinContentViewCall:1;

      unsignedint dontSelect:1;

      unsignedint contentTouched:1;

      unsignedint cantCancel:1;

      unsignedintdirectionalLockEnabled:1;

      unsignedintdirectionalLockAutoEnabled:1;

      unsignedint lockVertical:1;

      unsignedint lockHorizontal:1;

      unsignedint keepLocked:1;

      unsignedintshowsHorizontalScrollIndicator:1;

      unsignedintshowsVerticalScrollIndicator:1;

      unsignedint indicatorStyle:2;

      unsignedint inZoom:1;

      unsignedinthideIndicatorsInZoom:1;

      unsignedintpushedTrackingMode:1;

      unsignedint multipleDrag:1;

      unsignedintdisplayingScrollIndicators:1;

      unsignedintverticalIndicatorShrunk:1;

      unsignedinthorizontalIndicatorShrunk:1;

      unsignedintcontentFitDisableScrolling:1;

      unsignedint pagingEnabled:1;

      unsignedint pagingLeft:1;

      unsignedint pagingRight:1;

      unsignedint pagingUp:1;

      unsignedint pagingDown:1;

      unsignedintlastHorizontalDirection:1;

      unsignedintlastVerticalDirection:1;

      unsignedintdontScrollToTop:1;

      unsignedint scrollingToTop:1;

      unsignedintuseGestureRecognizers:1;

      unsignedint autoscrolling:1;

      unsignedintautomaticContentOffsetAdjustmentDisabled:1;

      unsignedintskipStartOffsetAdjustment:1;

      unsignedintdelegateScrollViewDidScroll:1;

      unsignedintdelegateScrollViewDidZoom:1;

      unsignedintdelegateContentSizeForZoomScale:1;

      unsignedintpreserveCenterDuringRotation:1;

      unsignedintdelaysTrackingWhileDecelerating:1;

      unsignedint pinnedZoomMin:1;

      unsignedint pinnedXMin:1;

      unsignedint pinnedYMin:1;

      unsignedint pinnedXMax:1;

      unsignedint pinnedYMax:1;

      unsignedint skipLinkChecks:1;

      unsignedintstaysCenteredDuringPinch:1;

      unsignedintwasDelayingPinchForSystemGestures:1;

      unsignedintsystemGesturesRecognitionPossible:1;

      unsignedintdisableContentOffsetRounding:1;

      unsignedintadjustedDecelerationTargetX:1;

      unsignedintadjustedDecelerationTargetY:1;

    } _scrollViewFlags;

    CGFloat         _farthestDistance;

    CGPoint         _initialTouchPosition;

    CGPoint         _startTouchPosition;

    CFTimeInterval   _startTouchTime;

    double          _startOffsetX;

    double          _startOffsetY;

    double          _lastUpdateOffsetX;

    double          _lastUpdateOffsetY;

    CGPoint         _lastTouchPosition;

    CFTimeInterval   _lastTouchTime;

    CFTimeInterval   _lastUpdateTime;

    UIView         *_contentView;

    float           _minimumZoomScale;

    float           _maximumZoomScale;

    UIView         *_zoomView;

    double          _horizontalVelocity;

    double          _verticalVelocity;

    double          _previousHorizontalVelocity;

    double          _previousVerticalVelocity;

    CFTypeRef       _scrollHeartbeat;

    CGPoint         _pageDecelerationTarget;

    CGSize          _decelerationFactor;

    CGPoint         _adjustedDecelerationTarget;

    CGSize          _adjustedDecelerationFactor;

    double          _decelerationLnFactorH;

    double          _decelerationLnFactorV;

    NSArray       _deferredBeginTouchesInfo;

    UIImageView * __strong *_shadows;

    id             _scrollNotificationViews;

    CFTimeInterval   _contentOffsetAnimationDuration;

    id             _animation;

    id             _pinch;

    id              _pan;

    id             _swipe;

    CGFloat         _pagingSpringPull;

    CGFloat         _pagingFriction;

    NSInteger       _fastScrollCount;

    CGFloat         _fastScrollMultiplier;

    CGFloat         _fastScrollStartMultiplier;

    CFTimeInterval   _fastScrollEndTime;

    CGPoint         _parentAdjustment;

    CGPoint         _rotationCenterPoint;

    CGFloat         _accuracy;

    CGFloat         _hysteresis;

    NSUInteger      _zoomAnimationCount;

}


@property(nonatomic)       CGPoint                  contentOffset;               

// default CGPointZero

//在滚轴视图中,contentOffset属性可以跟踪UIScrollView的具体位置,你能够自己获取和设置它,contentOffset的值是你当前可视内容在滚轴视图上面偏移原来的左上角那个点的偏移量,有contentOffset.x和contentOffset.y。


@property(nonatomic)       CGSize                   contentSize;                 

// default CGSizeZero

//contentSize是内容的大小,也就是可以滚动的大小。默认是0,没有滚动效果。


@property(nonatomic)       UIEdgeInsets              contentInset; 

// default UIEdgeInsetsZero. add additional scroll area aroundcontent

//contentInset增加你在contentSize中指定的内容能够滚动的上下左右区域数量。contentInset.top、contentInset.buttom、contentInset.left、contentInset.right分别表示上面,下面,左边和右边的距离。


@property(nonatomic,assign)id<UIScrollViewDelegate    delegate;                   

// default nil. weak reference

//设置代理


@property(nonatomic,getter=isDirectionalLockEnabled)BOOLdirectionalLockEnabled;        

// default NO. if YES, try to lock vertical or horizontal scrollingwhile dragging

//默认是NO,可以在垂直和水平方向同时运动。当值是YES时,假如一开始是垂直或者是水平运动,那么接下来会锁定另外一个方向的滚动。假如一开始是对角方向移动,则不会禁止某个方向。


@property(nonatomic)       BOOL                     bounces;                    

// default YES. if YES, bounces past edge of content and backagain

//默认是YES,就是滚动超过边界会反弹,有反弹回来的效果。如果是NO,那么滚动到达边界会立即停止


@property(nonatomic     BOOL                    alwaysBounceVertical;         // default NO. if YES and bounces is YES,even if content is smaller than bounds, allow drag vertically

@property(nonatomic     BOOL                    alwaysBounceHorizontal;        //default NO. if YES and bounces is YES, even if content is smallerthan bounds, allow drag horizontally

@property(nonatomic,getter=isPagingEnabled)BOOL        pagingEnabled;               

// default NO. if YES, stop on multiples of view bounds

//当值是YES会自动滚到subview的边界,默认为NO


@property(nonatomic,getter=isScrollEnabled)BOOL        scrollEnabled;               

// default YES. turn off any dragging temporarily

//决定是否可以滚动


@property(nonatomic)       BOOL                    showsHorizontalScrollIndicator; 

// default YES. show indicator while we are tracking. fades outafter tracking

//滚动时是否显示水平滚动条


@property(nonatomic)       BOOL                    showsVerticalScrollIndicator;  

// default YES. show indicator while we are tracking. fades outafter tracking

//滚动时是否显示垂直滚动条


@property(nonatomic)       UIEdgeInsets              scrollIndicatorInsets;        

// default is UIEdgeInsetsZero. adjust indicators inside ofinsets

//设置滚动条的位置


@property(nonatomic)       UIScrollViewIndicatorStyle  indicatorStyle;              

// default is UIScrollViewIndicatorStyleDefault

//滚动条的样式,基本只是设置颜色,总共3个颜色:默认、黑、白。


@property(nonatomic)       float                    decelerationRate __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

//设置手指放开后的减速率


-(void)setContentOffset:(CGPoint)contentOffsetanimated:(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 rectcompletely visible

//上面这个两个函数用来自动滚到到想要的位置,此过程中设置有动画效果,停止时,触发该函数。当animated为YES的时候有动画效果


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


 


@property(nonatomic,readonly,getter=isTracking)   BOOLtracking;      

// returns YES if user has touched. may not yet have starteddragging

//当touch后还没有拖动的时候是YES,否则为NO


@property(nonatomic,readonly,getter=isDragging)    BOOLdragging;       //returns YES if user has started scrolling. this may require sometime and or distance to move to initiate dragging

@property(nonatomic,readonly,getter=isDecelerating)BOOL decelerating;   

// returns YES if user isn't dragging (touch up) but scroll view isstill moving

//当滚动后,手指放开但是还在继续滚动中。这个时候是YES,其他时候 NO


@property(nonatomic)BOOLdelaysContentTouches;      

// default is YES. if NO, we immediately call-touchesShouldBegin:withEvent:inContentView:

//当值是YES的时候,用户触碰开始,scrollview要延迟一会,看看是否用户有意图滚动。假如滚到了,那么捕捉touch-down事件,否则就不捕捉。假如值是NO,当用户触碰,scrollview会立即触发touchesSholdBegin:withEvent:inContentView:。默认为YES。


@property(nonatomic)BOOL canCancelContentTouches;   

// default is YES. if NO, then once we start tracking, we don't tryto drag if the touch moves

//当值是YES的时候,用户触碰后,然后在一定时间内没有移动,scrollView发送trackingevents,然后用户移动手指足够长度触发滚动事件,这个时候,scrollview发送了touchesCancelled:withEvent:到subview,然后scrollview开始滚动。假如为NO,scrollview发送trackingevents后,就算用户移动手指,scrollview也不会滚动。


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

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

// default returns YES。决定自己是否接收touch事件

-(BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;


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

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

-(BOOL)touchesShouldCancelInContentView:(UIView*)view;

//开始发送trackingmessage消息给subview的时候调用这个方法,决定是否发送trackingmessage消息给subview。假如返回NO,发送,YES则不发送。


 


@property(nonatomic)float minimumZoomScale;    

// default is 1.0。表示能缩最小的倍数


@property(nonatomic)float maximumZoomScale;    

// default is 1.0. must be > minimum zoom scale toenable zooming。表示能放最大的倍数


@property(nonatomic)float zoomScale __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);         // default is 1.0

-(void)setZoomScale:(float)scaleanimated:(BOOL)animated__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

-(void)zoomToRect:(CGRect)rect animated:(BOOL)animated__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);


@property(nonatomic)BOOL  bouncesZoom;        

// default is YES. if set, user can go past min/max zoom whilegesturing and the zoom will animate to the min/max value at gestureend

//和bounces类似,区别在于:这个效果反映在缩放方面假如缩放超过最大缩放,那么会有反弹效果;假如是NO,则到达最大或者最小的时候立即停止


@property(nonatomic,readonly,getter=isZooming)      BOOL zooming;     

// returns YES if user in zoom gesture。当正在缩放的时候是YES,否则为NO


@property(nonatomic,readonly,getter=isZoomBouncing) BOOLzoomBouncing; 

//returns YES if we are in the middle of zooming back to themin/max value

//当内容放大到最大或者最小的时候值是YES,否则为NO


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

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

@property(nonatomic)BOOL scrollsToTop;        // default is YES.


// Use these accessors to configure the scroll view's built-ingesture recognizers.

// Do not change the gestures' delegates or override the gettersfor these properties.

@property(nonatomic,readonly) UIPanGestureRecognizer*panGestureRecognizer__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

// `pinchGestureRecognizer` will return nil when zooming isdisabled.

@property(nonatomic,readonly) UIPinchGestureRecognizer*pinchGestureRecognizer__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);


@end


@protocolUIScrollViewDelegate<NSObject>


@optional


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

// any offset changes

//触摸屏幕来滚动画面还是其他的方法使得画面滚动,皆触发该函数


-(void)scrollViewDidZoom:(UIScrollView *)scrollView__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);// any zoom scale changes


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

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

// called on finger up if the user dragged. velocity is inpoints/second. targetContentOffset may be changed to adjust wherethe scroll view comes to rest. not called when pagingEnabled isYES

-(void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocitytargetContentOffset:(inoutCGPoint *)targetContentOffset__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);


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

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollViewwillDecelerate:(BOOL)decelerate;

//触摸屏幕并拖拽画面,再松开,最后停止时,触发该函数


-(void)scrollViewWillBeginDecelerating:(UIScrollView*)scrollView;  //called on finger up as we are moving

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

 // calledwhen scroll view grinds to a halt

//滚动停止时,触发该函数


- (void)scrollViewDidEndScrollingAnimation:(UIScrollView*)scrollView; // called whensetContentOffset/scrollRectVisible:animated: finishes. not calledif not animating


//scrollview还处理缩放和平移手势,要实现缩放和平移,必须实现委托viewForZoomingInScrollView:和scrollViewDidEndZooming:withView:atSacle:两个方法。另外maximumZoomScale和mimimumZoomScale两个属性要不一样

- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView;    // return a view that will be scaled. ifdelegate returns nil, nothing happens

-(void)scrollViewWillBeginZooming:(UIScrollView*)scrollView withView:(UIView*)view__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);// called before the scroll viewbegins zooming its content

-(void)scrollViewDidEndZooming:(UIScrollView *)scrollViewwithView:(UIView *)viewatScale:(float)scale;// scale between minimum and maximum.called after any 'bounce' animations


- (BOOL)scrollViewShouldScrollToTop:(UIScrollView*)scrollView;   // returna yes if you want to scroll to the top. if not defined, assumesYES

- (void)scrollViewDidScrollToTop:(UIScrollView*)scrollView;     // called when scrolling animationfinished. may be called immediately if already at top


@end


http://blog.sina.com.cn/s/blog_7fa6b06f0101227t.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值