iOS Developer Library

Developer

UIKit Framework Reference UIScrollView Class Reference

Options
Deployment Target:

On This Page
Language:

UIScrollView

The UIScrollView class provides support for displaying content that is larger than the size of the application’s window. It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures. More...

Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 2.0 and later.
  • Sets the offset from the content view’s origin that corresponds to the receiver’s origin.

    Declaration

    Swift

    func setContentOffset(_ contentOffset: CGPoint, animated animated: Bool)

    Objective-C

    - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

    Parameters

    contentOffset

    A point (expressed in points) that is offset from the content view’s origin.

    animated

    YEStrue to animate the transition at a constant velocity to the new offset, NOfalse to make the transition immediate.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    contentOffset

  • The point at which the origin of the content view is offset from the origin of the scroll view.

    Declaration

    Swift

    var contentOffset: CGPoint

    Objective-C

    @property(nonatomic) CGPoint contentOffset

    Discussion

    The default value is CGPointZero.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The size of the content view.

    Declaration

    Swift

    var contentSize: CGSize

    Objective-C

    @property(nonatomic) CGSize contentSize

    Discussion

    The unit of size is points. The default size is CGSizeZero.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The distance that the content view is inset from the enclosing scroll view.

    Declaration

    Swift

    var contentInset: UIEdgeInsets

    Objective-C

    @property(nonatomic) UIEdgeInsets contentInset

    Discussion

    Use this property to add to the scrolling area around the content. The unit of size is points. The default value is UIEdgeInsetsZero.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether scrolling is enabled.

    Declaration

    Swift

    var scrollEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled

    Discussion

    If the value of this property is YEStrue , scrolling is enabled, and if it is NOfalse , scrolling is disabled. The default is YEStrue.

    When scrolling is disabled, the scroll view does not accept touch events; it forwards them up the responder chain.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether scrolling is disabled in a particular direction.

    Declaration

    Swift

    var directionalLockEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isDirectionalLockEnabled) BOOL directionalLockEnabled

    Discussion

    If this property is NOfalse, scrolling is permitted in both horizontal and vertical directions. If this property is YEStrue and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction. If the drag direction is diagonal, then scrolling will not be locked and the user can drag in any direction until the drag completes. The default value is NOfalse

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that controls whether the scroll-to-top gesture is enabled.

    Declaration

    Swift

    var scrollsToTop: Bool

    Objective-C

    @property(nonatomic) BOOL scrollsToTop

    Discussion

    The scroll-to-top gesture is a tap on the status bar. When a user makes this gesture, the system asks the scroll view closest to the status bar to scroll to the top. If that scroll view has scrollsToTop set to NOfalse, its delegate returns NOfalse from scrollViewShouldScrollToTop:, or the content is already at the top, nothing happens.

    After the scroll view scrolls to the top of the content view, it sends the delegate a scrollViewDidScrollToTop: message.

    The default value of scrollsToTop is YEStrue.

    Special Considerations

    On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YEStrue.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Scrolls a specific area of the content so that it is visible in the receiver.

    Declaration

    Swift

    func scrollRectToVisible(_ rect: CGRect, animated animated: Bool)

    Objective-C

    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

    Parameters

    rect

    A rectangle defining an area of the content view. The rectangle should be in the coordinate space of the scroll view.

    animated

    YEStrue if the scrolling should be animated, NOfalse if it should be immediate.

    Discussion

    This method scrolls the content view so that the area defined by rect is just visible inside the scroll view. If the area is already visible, the method does nothing.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether paging is enabled for the scroll view.

    Declaration

    Swift

    var pagingEnabled: Bool

    Objective-C

    @property(nonatomic, getter=isPagingEnabled) BOOL pagingEnabled

    Discussion

    If the value of this property is YEStrue, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NOfalse.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • bounces bounces Property

    A Boolean value that controls whether the scroll view bounces past the edge of content and back again.

    Declaration

    Swift

    var bounces: Bool

    Objective-C

    @property(nonatomic) BOOL bounces

    Discussion

    If the value of this property is YEStrue, the scroll view bounces when it encounters a boundary of the content. Bouncing visually indicates that scrolling has reached an edge of the content. If the value is NOfalse, scrolling stops immediately at the content boundary without bouncing. The default value is YEStrue.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether bouncing always occurs when vertical scrolling reaches the end of the content.

    Declaration

    Swift

    var alwaysBounceVertical: Bool

    Objective-C

    @property(nonatomic) BOOL alwaysBounceVertical

    Discussion

    If this property is set to YEStrue and bounces is YEStrue, vertical dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NOfalse.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether bouncing always occurs when horizontal scrolling reaches the end of the content view.

    Declaration

    Swift

    var alwaysBounceHorizontal: Bool

    Objective-C

    @property(nonatomic) BOOL alwaysBounceHorizontal

    Discussion

    If this property is set to YEStrue and bounces is YEStrue, horizontal dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NOfalse.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Overridden by subclasses to customize the default behavior when a finger touches down in displayed content.

    Declaration

    Swift

    func touchesShouldBegin(_ touches: NSSet!, withEvent event: UIEvent!, inContentView view: UIView!) -> Bool

    Objective-C

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

    Parameters

    touches

    A set of UITouch instances that represent the touches for the starting phase of the event represented by event.

    event

    An object representing the event to which the touch objects in touches belong.

    view

    The subview in the content where the touch-down gesture occurred.

    Return Value

    Return NOfalse if you don’t want the scroll view to send event messages to view. If you want view to receive those messages, return YEStrue (the default).

    Discussion

    The default behavior of UIScrollView is to invoke the UIResponder event-handling methods of the target subview that the touches occur in.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns whether to cancel touches related to the content subview and start dragging.

    Declaration

    Swift

    func touchesShouldCancelInContentView(_ view: UIView!) -> Bool

    Objective-C

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view

    Parameters

    view

    The view object in the content that is being touched.

    Return Value

    YEStrue to cancel further touch messages to view, NOfalse to have view continue to receive those messages. The default returned value is YEStrue if view is not a UIControl object; otherwise, it returns NOfalse.

    Discussion

    The scroll view calls this method just after it starts sending tracking messages to the content view. If it receives NOfalse from this method, it stops dragging and forwards the touch events to the content subview. The scroll view does not call this method if the value of the canCancelContentTouches property is NOfalse.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that controls whether touches in the content view always lead to tracking.

    Declaration

    Swift

    var canCancelContentTouches: Bool

    Objective-C

    @property(nonatomic) BOOL canCancelContentTouches

    Discussion

    If the value of this property is YEStrue and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll. If the value of this property is NOfalse, the scroll view does not scroll regardless of finger movement once the content view starts tracking.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether the scroll view delays the handling of touch-down gestures.

    Declaration

    Swift

    var delaysContentTouches: Bool

    Objective-C

    @property(nonatomic) BOOL delaysContentTouches

    Discussion

    If the value of this property is YEStrue, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is NOfalse , the scroll view immediately calls touchesShouldBegin:withEvent:inContentView:. The default value is YEStrue.

    See the class description for a fuller discussion.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A floating-point value that determines the rate of deceleration after the user lifts their finger.

    Declaration

    Swift

    var decelerationRate: CGFloat

    Objective-C

    @property(nonatomic) CGFloat decelerationRate

    Discussion

    Your application can use the UIScrollViewDecelerationRateNormal and UIScrollViewDecelerationRateFast constants as reference points for reasonable deceleration rates.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • dragging dragging Property

    A Boolean value that indicates whether the user has begun scrolling the content. (read-only)

    Declaration

    Swift

    var dragging: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isDragging) BOOL dragging

    Discussion

    The value held by this property might require some time or distance of scrolling before it is set to YEStrue.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    tracking

  • tracking tracking Property

    Returns whether the user has touched the content to initiate scrolling. (read-only)

    Declaration

    Swift

    var tracking: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isTracking) BOOL tracking

    Discussion

    The value of this property is YEStrue if the user has touched the content view but might not have yet have started dragging it.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    dragging

  • Returns whether the content is moving in the scroll view after the user lifted their finger. (read-only)

    Declaration

    Swift

    var decelerating: Bool { get }

    Objective-C

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

    Discussion

    The returned value is YEStrue if user isn't dragging the content but scrolling is still occurring.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The style of the scroll indicators.

    Declaration

    Swift

    var indicatorStyle: UIScrollViewIndicatorStyle

    Objective-C

    @property(nonatomic) UIScrollViewIndicatorStyle indicatorStyle

    Discussion

    The default style is UIScrollViewIndicatorStyleDefault. See Scroll Indicator Style for descriptions of these constants.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The distance the scroll indicators are inset from the edge of the scroll view.

    Declaration

    Swift

    var scrollIndicatorInsets: UIEdgeInsets

    Objective-C

    @property(nonatomic) UIEdgeInsets scrollIndicatorInsets

    Discussion

    The default value is UIEdgeInsetsZero.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that controls whether the horizontal scroll indicator is visible.

    Declaration

    Swift

    var showsHorizontalScrollIndicator: Bool

    Objective-C

    @property(nonatomic) BOOL showsHorizontalScrollIndicator

    Discussion

    The default value is YEStrue. The indicator is visible while tracking is underway and fades out after tracking.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that controls whether the vertical scroll indicator is visible.

    Declaration

    Swift

    var showsVerticalScrollIndicator: Bool

    Objective-C

    @property(nonatomic) BOOL showsVerticalScrollIndicator

    Discussion

    The default value is YEStrue. The indicator is visible while tracking is underway and fades out after tracking.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Displays the scroll indicators momentarily.

    Declaration

    Swift

    func flashScrollIndicators()

    Objective-C

    - (void)flashScrollIndicators

    Discussion

    You should call this method whenever you bring the scroll view to front.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The underlying gesture recognizer for pan gestures. (read-only)

    Declaration

    Swift

    var panGestureRecognizer: UIPanGestureRecognizer { get }

    Objective-C

    @property(nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer

    Discussion

    Your application accesses this property when it wants to more precisely control which pan gestures are recognized by the scroll view.

    Import Statement

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The underlying gesture recognizer for pinch gestures. (read-only)

    Declaration

    Swift

    var pinchGestureRecognizer: UIPinchGestureRecognizer! { get }

    Objective-C

    @property(nonatomic, readonly) UIPinchGestureRecognizer *pinchGestureRecognizer

    Discussion

    Your application accesses this property when it wants to more precisely control which pinch gestures are recognized by the scroll view.

    Import Statement

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Zooms to a specific area of the content so that it is visible in the receiver.

    Declaration

    Swift

    func zoomToRect(_ rect: CGRect, animated animated: Bool)

    Objective-C

    - (void)zoomToRect:(CGRect)rect animated:(BOOL)animated

    Parameters

    rect

    A rectangle defining an area of the content view. The rectangle should be in the coordinate space of the view returned by viewForZoomingInScrollView:.

    animated

    YEStrue if the scrolling should be animated, NOfalse if it should be immediate.

    Discussion

    This method zooms so that the content view becomes the area defined by rect, adjusting the zoomScale as necessary.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • zoomScale zoomScale Property

    A floating-point value that specifies the current scale factor applied to the scroll view's content.

    Declaration

    Swift

    var zoomScale: CGFloat

    Objective-C

    @property(nonatomic) CGFloat zoomScale

    Discussion

    This value determines how much the content is currently scaled. The default value is 1.0.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • A floating-point value that specifies the current zoom scale.

    Declaration

    Swift

    func setZoomScale(_ scale: CGFloat, animated animated: Bool)

    Objective-C

    - (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated

    Parameters

    scale

    The new value to scale the content to.

    animated

    YEStrue to animate the transition to the new scale, NOfalse to make the transition immediate.

    Discussion

    The new scale value should be between the minimumZoomScale and the maximumZoomScale.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • A floating-point value that specifies the maximum scale factor that can be applied to the scroll view's content.

    Declaration

    Swift

    var maximumZoomScale: CGFloat

    Objective-C

    @property(nonatomic) CGFloat maximumZoomScale

    Discussion

    This value determines how large the content can be scaled. It must be greater than the minimum zoom scale for zooming to be enabled. The default value is 1.0.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A floating-point value that specifies the minimum scale factor that can be applied to the scroll view's content.

    Declaration

    Swift

    var minimumZoomScale: CGFloat

    Objective-C

    @property(nonatomic) CGFloat minimumZoomScale

    Discussion

    This value determines how small the content can be scaled. The default value is 1.0

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that indicates that zooming has exceeded the scaling limits specified for the receiver. (read-only)

    Declaration

    Swift

    var zoomBouncing: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isZoomBouncing) BOOL zoomBouncing

    Discussion

    The value of this property is YEStrue if the scroll view is zooming back to a minimum or maximum zoom scaling value; otherwise the value is NOfalse .

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • zooming zooming Property

    A Boolean value that indicates whether the content view is currently zooming in or out. (read-only)

    Declaration

    Swift

    var zooming: Bool { get }

    Objective-C

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

    Discussion

    The value of this property is YEStrue if user is making a zoom gesture, otherwise it is NOfalse .

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • A Boolean value that determines whether the scroll view animates the content scaling when the scaling exceeds the maximum or minimum limits.

    Declaration

    Swift

    var bouncesZoom: Bool

    Objective-C

    @property(nonatomic) BOOL bouncesZoom

    Discussion

    If the value of this property is YEStrue and zooming exceeds either the maximum or minimum limits for scaling, the scroll view temporarily animates the content scaling just past these limits before returning to them. If this property is NOfalse, zooming stops immediately at one a scaling limits. The default is YEStrue .

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • delegate delegate Property

    The delegate of the scroll-view object.

    Declaration

    Swift

    unowned(unsafe) var delegate: UIScrollViewDelegate?

    Objective-C

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

    Discussion

    The delegate must adopt the UIScrollViewDelegate protocol. The UIScrollView class, which does not retain the delegate, invokes each protocol method the delegate implements.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The style of the scroll indicators. You use these constants to set the value of the indicatorStyle style.

    Declaration

    Swift

    enum UIScrollViewIndicatorStyle : Int { case Default case Black case White }

    Objective-C

    typedef enum : NSInteger { UIScrollViewIndicatorStyleDefault, UIScrollViewIndicatorStyleBlack, UIScrollViewIndicatorStyleWhite } UIScrollViewIndicatorStyle;

    Constants

    • Default

      UIScrollViewIndicatorStyleDefault

      The default style of scroll indicator, which is black with a white border. This style is good against any content background.

      Available in iOS 2.0 and later.

    • Black

      UIScrollViewIndicatorStyleBlack

      A style of indicator which is black and smaller than the default style. This style is good against a white content background.

      Available in iOS 2.0 and later.

    • White

      UIScrollViewIndicatorStyleWhite

      A style of indicator is white and smaller than the default style. This style is good against a black content background.

      Available in iOS 2.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The rate of deceleration for a scrolling view.

    Declaration

    Swift

    let UIScrollViewDecelerationRateNormal: CGFloat let UIScrollViewDecelerationRateFast: CGFloat

    Objective-C

    const float UIScrollViewDecelerationRateNormal; const float UIScrollViewDecelerationRateFast;

    Constants

    • UIScrollViewDecelerationRateNormal

      UIScrollViewDecelerationRateNormal

      The default deceleration rate for a scroll view.

      Available in iOS 3.0 and later.

    • UIScrollViewDecelerationRateFast

      UIScrollViewDecelerationRateFast

      A fast deceleration rate for a scroll view.

      Available in iOS 3.0 and later.

    Import Statement

  • The manner in which the keyboard is dismissed when a drag begins in the scroll view.

    Declaration

    Swift

    enum UIScrollViewKeyboardDismissMode : Int { case None case OnDrag case Interactive }

    Objective-C

    typedef enum : NSInteger { UIScrollViewKeyboardDismissModeNone, UIScrollViewKeyboardDismissModeOnDrag, UIScrollViewKeyboardDismissModeInteractive }UIScrollViewKeyboardDismissMode;

    Constants

    • None

      UIScrollViewKeyboardDismissModeNone

      The keyboard does not get dismissed with a drag.

      Available in iOS 7.0 and later.

    • OnDrag

      UIScrollViewKeyboardDismissModeOnDrag

      The keyboard is dismissed when a drag begins.

      Available in iOS 7.0 and later.

    • Interactive

      UIScrollViewKeyboardDismissModeInteractive

      The keyboard follows the dragging touch offscreen, and can be pulled upward again to cancel the dismiss.

      Available in iOS 7.0 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.