[UIScrollViewDelegate]简介
The methods declared by the UIScrollViewDelegate protocol allow the adopting delegate to respond to messages from the UIScrollView class and thus respond to, and in some affect, operations such as scrolling, zooming, deceleration of scrolled content, and scrolling animations.
通过UIScrollViewDelegate协议声明的方法允许采用的代表来响应来自UIScrollView类的信息,因此在某些情况下,响应像滚动,缩放,滚动内容的减速和滚动的动画等操作。
-
Tells the delegate when the user scrolls the content view within the receiver.
当用户滚动接收器内的内容视图时通知delegate。
Declaration
SWIFT
optional func scrollViewDidScroll(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewDidScroll:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object in which the scrolling occurred.
滚动发生的滚动视图对象。
Discussion
The delegate typically implements this method to obtain the change in content offset from
scrollViewand draw the affected portion of the content view.delegate典型实现这个方法从scrollView获取内容边际的变化和现实内容视图受影响的部分。
Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Tells the delegate when the scroll view is about to start scrolling the content.
Declaration
SWIFT
optional func scrollViewWillBeginDragging(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object that is about to scroll the content view.
Discussion
The delegate might not receive this message until dragging has occurred over a small distance.
Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Tells the delegate when the user finishes scrolling the content.
Declaration
SWIFT
optional func scrollViewWillEndDragging(_scrollView: UIScrollView,
withVelocityvelocity: CGPoint,
targetContentOffsettargetContentOffset: UnsafeMutablePointer<CGPoint>)OBJECTIVE-C
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollViewwithVelocity:(CGPoint)velocitytargetContentOffset:(inout CGPoint *)targetContentOffsetParameters
scrollViewThe scroll-view object where the user ended the touch..
velocityThe velocity of the scroll view (in points) at the moment the touch was released.
targetContentOffsetThe expected offset when the scrolling action decelerates to a stop.
Discussion
This method is not called when the value of the scroll view’s
pagingEnabledproperty isYES. Your application can change the value of thetargetContentOffsetparameter to adjust where the scrollview finishes its scrolling animation.Import Statement
import UIKitAvailability
Available in iOS 5.0 and later.
-
Tells the delegate when dragging ended in the scroll view.
Declaration
SWIFT
optional func scrollViewDidEndDragging(_scrollView: UIScrollView,
willDeceleratedecelerate: Bool)OBJECTIVE-C
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollViewwillDecelerate:(BOOL)decelerateParameters
scrollViewThe scroll-view object that finished scrolling the content view.
decelerateYESif the scrolling movement will continue, but decelerate, after a touch-up gesture during a dragging operation. If the value isNO, scrolling stops immediately upon touch-up.Discussion
The scroll view sends this message when the user’s finger touches up after dragging content. The
deceleratingproperty ofUIScrollViewcontrols deceleration.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Asks the delegate if the scroll view should scroll to the top of the content.
Declaration
SWIFT
optional func scrollViewShouldScrollToTop(_scrollView: UIScrollView) -> BoolOBJECTIVE-C
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object requesting this information.
Return Value
YESto permit scrolling to the top of the content,NOto disallow it.Discussion
If the delegate doesn’t implement this method,
YESis assumed. For the scroll-to-top gesture (a tap on the status bar) to be effective, thescrollsToTopproperty of theUIScrollViewmust be set to YES.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Tells the delegate that the scroll view scrolled to the top of the content.
Declaration
SWIFT
optional func scrollViewDidScrollToTop(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object that perform the scrolling operation.
Discussion
The scroll view sends this message when it finishes scrolling to the top of the content. It might call it immediately if the top of the content is already shown. For the scroll-to-top gesture (a tap on the status bar) to be effective, the
scrollsToTopproperty of theUIScrollViewmust be set to YES.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Tells the delegate that the scroll view is starting to decelerate the scrolling movement.
Declaration
SWIFT
optional func scrollViewWillBeginDecelerating(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object that is decelerating the scrolling of the content view.
Discussion
The scroll view calls this method as the user’s finger touches up as it is moving during a scrolling operation; the scroll view will continue to move a short distance afterwards. The
deceleratingproperty ofUIScrollViewcontrols deceleration.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
See Also
-
Tells the delegate that the scroll view has ended decelerating the scrolling movement.
Declaration
SWIFT
optional func scrollViewDidEndDecelerating(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object that is decelerating the scrolling of the content view.
Discussion
The scroll view calls this method when the scrolling movement comes to a halt. The
deceleratingproperty ofUIScrollViewcontrols deceleration.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
See Also
-
-
Asks the delegate for the view to scale when zooming is about to occur in the scroll view.
Declaration
SWIFT
optional func viewForZoomingInScrollView(_scrollView: UIScrollView) -> UIView?OBJECTIVE-C
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object displaying the content view.
Return Value
A
UIViewobject that will be scaled as a result of the zooming gesture. Returnnilif you don’t want zooming to occur.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
-
Tells the delegate that zooming of the content in the scroll view is about to commence.
Declaration
SWIFT
optional func scrollViewWillBeginZooming(_scrollView: UIScrollView,
withViewview: UIView!)OBJECTIVE-C
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollViewwithView:(UIView *)viewParameters
scrollViewThe scroll-view object displaying the content view.
viewThe view object whose content is about to be zoomed.
Discussion
This method is called at the beginning of zoom gestures and in cases where a change in zoom level is to be animated. You can use this method to store state information or perform any additional actions prior to zooming the view’s content.
Import Statement
import UIKitAvailability
Available in iOS 3.2 and later.
-
Tells the delegate when zooming of the content in the scroll view completed.
Declaration
SWIFT
optional func scrollViewDidEndZooming(_scrollView: UIScrollView,
withViewview: UIView!,
atScalescale: CGFloat)OBJECTIVE-C
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollViewwithView:(UIView *)viewatScale:(CGFloat)scaleParameters
scrollViewThe scroll-view object displaying the content view.
viewThe view object representing that part of the content view that needs to be scaled.
scaleThe scale factor to use for scaling; this value must be between the limits established by the
UIScrollViewpropertiesmaximumZoomScaleandminimumZoomScale.Discussion
The scroll view also calls this method after any “bounce” animations. It also calls this method after animated changes to the zoom level and after a zoom-related gesture ends (regardless of whether the gesture resulted in a change to the zoom level).
Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.
See Also
-
Tells the delegate that the scroll view’s zoom factor changed.
Declaration
SWIFT
optional func scrollViewDidZoom(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewDidZoom:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object whose zoom factor changed.
Import Statement
import UIKitAvailability
Available in iOS 3.2 and later.
-
-
Tells the delegate when a scrolling animation in the scroll view concludes.
Declaration
SWIFT
optional func scrollViewDidEndScrollingAnimation(_scrollView: UIScrollView)OBJECTIVE-C
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollViewParameters
scrollViewThe scroll-view object that is performing the scrolling animation.
Discussion
The scroll view calls this method at the end of its implementations of the
setContentOffset:animated:andscrollRectToVisible:animated:methods, but only if animations are requested.Import Statement
import UIKitAvailability
Available in iOS 2.0 and later.

浙公网安备 33010602011771号