Class: UIScrollView

Inherits:
UIView show all

Overview

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.

Direct Known Subclasses

UICollectionView, UITableView, UITextView

Instance Attribute Summary (collapse)

Attributes inherited from UIView

#alpha, #autoresizesSubviews, #autoresizingMask, #backgroundColor, #bounds, #center, #clearsContextBeforeDrawing, #clipsToBounds, #contentMode, #contentScaleFactor, #exclusiveTouch, #frame, #gestureRecognizers, #hidden, #layer, #multipleTouchEnabled, #opaque, #restorationIdentifier, #subviews, #superview, #tag, #transform, #userInteractionEnabled, #window

Attributes inherited from UIResponder

#inputAccessoryView, #inputView, #undoManager

Instance Method Summary (collapse)

Methods inherited from UIView

#addConstraint:, #addConstraints:, #addGestureRecognizer:, #addSubview:, #alignmentRectForFrame:, #alignmentRectInsets, animateWithDuration:animations:, animateWithDuration:animations:completion:, animateWithDuration:delay:options:animations:completion:, areAnimationsEnabled, beginAnimations:context:, #bringSubviewToFront:, commitAnimations, #constraints, #constraintsAffectingLayoutForAxis:, #contentCompressionResistancePriorityForAxis:, #contentHuggingPriorityForAxis:, #convertPoint:fromView:, #convertPoint:toView:, #convertRect:fromView:, #convertRect:toView:, #decodeRestorableStateWithCoder:, #didAddSubview:, #didMoveToSuperview, #didMoveToWindow, #drawRect:, #drawRect:forViewPrintFormatter:, #encodeRestorableStateWithCoder:, #endEditing:, #exchangeSubviewAtIndex:withSubviewAtIndex:, #exerciseAmbiguityInLayout, #frameForAlignmentRect:, #gestureRecognizerShouldBegin:, #hasAmbiguousLayout, #hitTest:withEvent:, #initWithFrame:, #insertSubview:aboveSubview:, #insertSubview:atIndex:, #insertSubview:belowSubview:, #intrinsicContentSize, #invalidateIntrinsicContentSize, #isDescendantOfView:, layerClass, #layoutIfNeeded, #layoutSubviews, #needsUpdateConstraints, #pointInside:withEvent:, #removeConstraint:, #removeConstraints:, #removeFromSuperview, #removeGestureRecognizer:, requiresConstraintBasedLayout, #sendSubviewToBack:, setAnimationBeginsFromCurrentState:, setAnimationCurve:, setAnimationDelay:, setAnimationDelegate:, setAnimationDidStopSelector:, setAnimationDuration:, setAnimationRepeatAutoreverses:, setAnimationRepeatCount:, setAnimationStartDate:, setAnimationTransition:forView:cache:, setAnimationWillStartSelector:, setAnimationsEnabled:, #setContentCompressionResistancePriority:forAxis:, #setContentHuggingPriority:forAxis:, #setNeedsDisplay, #setNeedsDisplayInRect:, #setNeedsLayout, #setNeedsUpdateConstraints, #setTranslatesAutoresizingMaskIntoConstraints:, #sizeThatFits:, #sizeToFit, #systemLayoutSizeFittingSize:, transitionFromView:toView:duration:options:completion:, transitionWithView:duration:options:animations:completion:, #translatesAutoresizingMaskIntoConstraints, #updateConstraints, #updateConstraintsIfNeeded, #viewForBaselineLayout, #viewPrintFormatter, #viewWithTag:, #willMoveToSuperview:, #willMoveToWindow:, #willRemoveSubview:

Methods inherited from UIResponder

#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Boolean) alwaysBounceHorizontal

A Boolean value that determines whether bouncing always occurs when horizontal scrolling reaches the end of the content view. If this property is set to YES and bounces is YES, horizontal dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NO.

Returns:

  • (Boolean)

- (Boolean) alwaysBounceVertical

A Boolean value that determines whether bouncing always occurs when vertical scrolling reaches the end of the content. If this property is set to YES and bounces is YES, vertical dragging is allowed even if the content is smaller than the bounds of the scroll view. The default value is NO.

Returns:

  • (Boolean)

- (Boolean) bounces

A Boolean value that controls whether the scroll view bounces past the edge of content and back again. If the value of this property is YES, 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 NO, scrolling stops immediately at the content boundary without bouncing. The default value is YES.

Returns:

  • (Boolean)

- (Boolean) bouncesZoom

A Boolean value that determines whether the scroll view animates the content scaling when the scaling exceeds the maximum or minimum limits. If the value of this property is YES 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 NO, zooming stops immediately at one a scaling limits. The default is YES .

Returns:

  • (Boolean)

- (Boolean) canCancelContentTouches

A Boolean value that controls whether touches in the content view always lead to tracking. If the value of this property is YES 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 NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.

Returns:

  • (Boolean)

- (UIEdgeInsets) contentInset

The distance that the content view is inset from the enclosing scroll view. Use this property to add to the scrolling area around the content. The unit of size is points. The default value is UIEdgeInsetsZero.

Returns:

- (CGPoint) contentOffset

The point at which the origin of the content view is offset from the origin of the scroll view. The default value is CGPointZero.

Returns:

  • (CGPoint)

- (CGSize) contentSize

The size of the content view. The unit of size is points. The default size is CGSizeZero.

Returns:

- (Boolean) decelerating (readonly)

Returns whether the content is moving in the scroll view after the user lifted their finger. (read-only) The returned value is YES if user isn't dragging the content but scrolling is still occurring.

Returns:

  • (Boolean)

- (Float) decelerationRate

A floating-point value that determines the rate of deceleration after the user lifts their finger. Your application can use the UIScrollViewDecelerationRateNormal and UIScrollViewDecelerationRateFast constants as reference points for reasonable deceleration rates.

Returns:

- (Boolean) delaysContentTouches

A Boolean value that determines whether the scroll view delays the handling of touch-down gestures. If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is NO , the scroll view immediately calls touchesShouldBegin:withEvent:inContentView:. The default value is YES.See the class description for a fuller discussion.

Returns:

  • (Boolean)

- (Object) delegate

The delegate of the scroll-view object. The delegate must adopt the UIScrollViewDelegate protocol. The UIScrollView class, which does not retain the delegate, invokes each protocol method the delegate implements.

Returns:

- (Boolean) directionalLockEnabled

A Boolean value that determines whether scrolling is disabled in a particular direction If this property is NO, scrolling is permitted in both horizontal and vertical directions. If this property is YES 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 NO

Returns:

  • (Boolean)

- (Boolean) dragging (readonly)

A Boolean value that indicates whether the user has begun scrolling the content. (read-only) The value held by this property might require some time or distance of scrolling before it is set to YES.

Returns:

  • (Boolean)

- (UIScrollViewIndicatorStyle) indicatorStyle

The style of the scroll indicators. The default style is UIScrollViewIndicatorStyleDefault. See “Scroll Indicator Style” for descriptions of these constants.

- (Float) maximumZoomScale

A floating-point value that specifies the maximum scale factor that can be applied to the scroll view's content. 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.

Returns:

- (Float) minimumZoomScale

A floating-point value that specifies the minimum scale factor that can be applied to the scroll view's content. This value determines how small the content can be scaled. The default value is 1.0

Returns:

- (Boolean) pagingEnabled

A Boolean value that determines whether paging is enabled for the scroll view. If the value of this property is YES, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NO.

Returns:

  • (Boolean)

- (UIPanGestureRecognizer) panGestureRecognizer (readonly)

The underlying gesture recognizer for pan gestures. (read-only) Your application accesses this property when it wants to more precisely control which pan gestures are recognized by the scroll view.

- (UIPinchGestureRecognizer) pinchGestureRecognizer (readonly)

The underlying gesture recognizer for pinch gestures. (read-only) Your application accesses this property when it wants to more precisely control which pinch gestures are recognized by the scroll view.

- (Boolean) scrollEnabled

A Boolean value that determines whether scrolling is enabled. If the value of this property is YES , scrolling is enabled, and if it is NO , scrolling is disabled. The default is YES.When scrolling is disabled, the scroll view does not accept touch events; it forwards them up the responder chain.

Returns:

  • (Boolean)

- (UIEdgeInsets) scrollIndicatorInsets

The distance the scroll indicators are inset from the edge of the scroll view. The default value is UIEdgeInsetsZero.

Returns:

- (Boolean) scrollsToTop

A Boolean value that controls whether the scroll-to-top gesture is effective The scroll-to-top gesture is a tap on the status bar; when this property is YES, the scroll view jumps to the top of the content when this gesture occurs. The default value of this property is YES. This gesture works on a single visible scroll view; if there are multiple scroll views (for example, a date picker) with this property set, or if the delegate returns NO in scrollViewShouldScrollToTop:, UIScrollView ignores the request. After the scroll view scrolls to the top of the content view, it sends the delegate a scrollViewDidScrollToTop: message.

Returns:

  • (Boolean)

- (Boolean) showsHorizontalScrollIndicator

A Boolean value that controls whether the horizontal scroll indicator is visible. The default value is YES. The indicator is visible while tracking is underway and fades out after tracking.

Returns:

  • (Boolean)

- (Boolean) showsVerticalScrollIndicator

A Boolean value that controls whether the vertical scroll indicator is visible. The default value is YES. The indicator is visible while tracking is underway and fades out after tracking.

Returns:

  • (Boolean)

- (Boolean) tracking (readonly)

Returns whether the user has touched the content to initiate scrolling. (read-only) The value of this property is YES if the user has touched the content view but might not have yet have started dragging it.

Returns:

  • (Boolean)

- (Boolean) zoomBouncing (readonly)

A Boolean value that indicates that zooming has exceeded the scaling limits specified for the receiver. (read-only) The value of this property is YES if the scroll view is zooming back to a minimum or maximum zoom scaling value; otherwise the value is NO .

Returns:

  • (Boolean)

- (Boolean) zooming (readonly)

A Boolean value that indicates whether the content view is currently zooming in or out. (read-only) The value of this property is YES if user is making a zoom gesture, otherwise it is NO .

Returns:

  • (Boolean)

- (Float) zoomScale

A floating-point value that specifies the current scale factor applied to the scroll view's content. This value determines how much the content is currently scaled. The default value is 1.0.

Returns:

Instance Method Details

- (Object) flashScrollIndicators

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

Returns:

- (Object) scrollRectToVisible(rect, animated:animated)

Scrolls a specific area of the content so that it is visible in the receiver. 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.

Parameters:

  • rect (CGRect)

    A rectangle defining an area of the content view.

  • animated (Boolean)

    YES if the scrolling should be animated, NO if it should be immediate.

Returns:

- (Object) setContentOffset(contentOffset, animated:animated)

Sets the offset from the content view’s origin that corresponds to the receiver’s origin.

Parameters:

  • contentOffset (CGPoint)

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

  • animated (Boolean)

    YES to animate the transition at a constant velocity to the new offset, NO to make the transition immediate.

Returns:

- (Object) setZoomScale(scale, animated:animated)

A floating-point value that specifies the current zoom scale. The new scale value should be between the minimumZoomScale and the maximumZoomScale.

Parameters:

  • scale (Float)

    The new value to scale the content to.

  • animated (Boolean)

    YES to animate the transition to the new scale, NO to make the transition immediate.

Returns:

- (Boolean) touchesShouldBegin(touches, withEvent:event, inContentView:view)

Overridden by subclasses to customize the default behavior when a finger touches down in displayed content. The default behavior of UIScrollView is to invoke the UIResponder event-handling methods of the target subview that the touches occur in.

Parameters:

  • touches (NSSet)

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

  • event (UIEvent)

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

  • view (UIView)

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

Returns:

  • (Boolean)

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

- (Boolean) touchesShouldCancelInContentView(view)

Returns whether to cancel touches related to the content subview and start dragging. The scroll view calls this method just after it starts sending tracking messages to the content view. If it receives NO 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 NO.

Parameters:

  • view (UIView)

    The view object in the content that is being touched.

Returns:

  • (Boolean)

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

- (Object) zoomToRect(rect, animated:animated)

Zooms to a specific area of the content so that it is visible in the receiver. This method zooms so that the content view becomes the area defined by rect, adjusting the zoomScale as necessary.

Parameters:

  • rect (CGRect)

    A rectangle defining an area of the content view.

  • animated (Boolean)

    YES if the scrolling should be animated, NO if it should be immediate.

Returns: