iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIScrollViewDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIScrollViewDelegate

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

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.

  • Tells the delegate when the user scrolls the content view within the receiver.

    Declaration

    Swift

    optional func scrollViewDidScroll(_ scrollView: UIScrollView)

    Objective-C

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView

    Parameters

    scrollView

    The scroll-view object in which the scrolling occurred.

    Discussion

    The delegate typically implements this method to obtain the change in content offset from scrollView and draw the affected portion of the content view.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 *)scrollView

    Parameters

    scrollView

    The 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

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate when the user finishes scrolling the content.

    Declaration

    Swift

    optional func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset targetContentOffset: UnsafeMutablePointer<CGPoint>)

    Objective-C

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset

    Parameters

    scrollView

    The scroll-view object where the user ended the touch..

    velocity

    The velocity of the scroll view (in points) at the moment the touch was released.

    targetContentOffset

    The expected offset when the scrolling action decelerates to a stop.

    Discussion

    This method is not called when the value of the scroll view’s pagingEnabled property is YEStrue. Your application can change the value of the targetContentOffset parameter to adjust where the scrollview finishes its scrolling animation.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Tells the delegate when dragging ended in the scroll view.

    Declaration

    Swift

    optional func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)

    Objective-C

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

    Parameters

    scrollView

    The scroll-view object that finished scrolling the content view.

    decelerate

    YEStrue if the scrolling movement will continue, but decelerate, after a touch-up gesture during a dragging operation. If the value is NOfalse, scrolling stops immediately upon touch-up.

    Discussion

    The scroll view sends this message when the user’s finger touches up after dragging content. The decelerating property of UIScrollView controls deceleration.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

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

    Objective-C

    - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView

    Parameters

    scrollView

    The scroll-view object requesting this information.

    Return Value

    YEStrue to permit scrolling to the top of the content, NOfalse to disallow it.

    Discussion

    If the delegate doesn’t implement this method, YEStrue is assumed. For the scroll-to-top gesture (a tap on the status bar) to be effective, the scrollsToTop property of the UIScrollView must be set to YES.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 *)scrollView

    Parameters

    scrollView

    The 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 scrollsToTop property of the UIScrollView must be set to YES.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 *)scrollView

    Parameters

    scrollView

    The 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 decelerating property of UIScrollView controls deceleration.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • 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 *)scrollView

    Parameters

    scrollView

    The 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 decelerating property of UIScrollView controls deceleration.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • 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 *)scrollView

    Parameters

    scrollView

    The scroll-view object displaying the content view.

    Return Value

    A UIView object that will be scaled as a result of the zooming gesture. Return nil if you don’t want zooming to occur.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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, withView view: UIView!)

    Objective-C

    - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view

    Parameters

    scrollView

    The scroll-view object displaying the content view.

    view

    The 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

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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, withView view: UIView!, atScale scale: CGFloat)

    Objective-C

    - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale

    Parameters

    scrollView

    The scroll-view object displaying the content view.

    view

    The view object representing that part of the content view that needs to be scaled.

    scale

    The scale factor to use for scaling; this value must be between the limits established by the UIScrollView properties maximumZoomScale and minimumZoomScale.

    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

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the delegate that the scroll view’s zoom factor changed.

    Declaration

    Swift

    optional func scrollViewDidZoom(_ scrollView: UIScrollView)

    Objective-C

    - (void)scrollViewDidZoom:(UIScrollView *)scrollView

    Parameters

    scrollView

    The scroll-view object whose zoom factor changed.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    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 *)scrollView

    Parameters

    scrollView

    The 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: and scrollRectToVisible:animated: methods, but only if animations are requested.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.