You are on page 1of 134

UIView Class Reference

Contents

UIView Class Reference 7


Overview 7 Creating a View 9 The View Drawing Cycle 9 Animations 10 Threading Considerations 11 Subclassing Notes 11 Tasks 13 Initializing a View Object 13 Configuring a Views Visual Appearance 13 Configuring the Event-Related Behavior 14 Configuring the Bounds and Frame Rectangles 15 Managing the View Hierarchy 15 Configuring the Resizing Behavior 16 Laying out Subviews 16 Opting in to Constraint-Based Layout 16 Managing Constraints 17 Measuring in Constraint-Based Layout 17 Aligning Views with Constraint-Based Layout 18 Triggering Constraint-Based Layout 18 Debugging Constraint-Based Layout 18 Drawing and Updating the View 19 Formatting Printed View Content 19 Managing Gesture Recognizers 19 Animating Views with Block Objects 20 Animating Views 20 Using Motion Effects 21 Preserving and Restoring State 22 Capturing a View Snapshot 22 Identifying the View at Runtime 22 Converting Between View Coordinate Systems 22 Hit Testing in a View 23 Ending a View Editing Session 23 Observing View-Related Changes 23

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

Contents

Properties 24 alpha 24 autoresizesSubviews 24 autoresizingMask 25 backgroundColor 26 bounds 26 center 27 clearsContextBeforeDrawing 28 clipsToBounds 29 contentMode 29 contentScaleFactor 30 exclusiveTouch 31 frame 31 gestureRecognizers 32 hidden 33 layer 34 motionEffects 34 multipleTouchEnabled 35 opaque 35 restorationIdentifier 36 subviews 37 superview 37 tag 38 tintAdjustmentMode 38 tintColor 39 transform 40 userInteractionEnabled 40 window 41 Class Methods 41 addKeyframeWithRelativeStartTime:relativeDuration:animations: 41 animateKeyframesWithDuration:delay:options:animations:completion: 43 animateWithDuration:animations: 44 animateWithDuration:animations:completion: 45 animateWithDuration:delay:options:animations:completion: 46 animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options: animations:completion: 47 areAnimationsEnabled 48 beginAnimations:context: 49 commitAnimations 50

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

Contents

layerClass 51 performSystemAnimation:onViews:options:animations:completion: 52 performWithoutAnimation: 52 requiresConstraintBasedLayout 53 setAnimationBeginsFromCurrentState: 53 setAnimationCurve: 54 setAnimationDelay: 55 setAnimationDelegate: 56 setAnimationDidStopSelector: 57 setAnimationDuration: 58 setAnimationRepeatAutoreverses: 59 setAnimationRepeatCount: 60 setAnimationsEnabled: 61 setAnimationStartDate: 62 setAnimationTransition:forView:cache: 63 setAnimationWillStartSelector: 64 transitionFromView:toView:duration:options:completion: 65 transitionWithView:duration:options:animations:completion: 67 Instance Methods 68 addConstraint: 68 addConstraints: 69 addGestureRecognizer: 69 addMotionEffect: 70 addSubview: 71 alignmentRectForFrame: 71 alignmentRectInsets 72 bringSubviewToFront: 73 constraints 73 constraintsAffectingLayoutForAxis: 74 contentCompressionResistancePriorityForAxis: 74 contentHuggingPriorityForAxis: 75 convertPoint:fromView: 76 convertPoint:toView: 76 convertRect:fromView: 77 convertRect:toView: 78 decodeRestorableStateWithCoder: 78 didAddSubview: 79 didMoveToSuperview 80 didMoveToWindow 80

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

Contents

drawRect: 81 drawRect:forViewPrintFormatter: 82 drawViewHierarchyInRect:afterScreenUpdates: 82 encodeRestorableStateWithCoder: 83 endEditing: 84 exchangeSubviewAtIndex:withSubviewAtIndex: 85 exerciseAmbiguityInLayout 86 frameForAlignmentRect: 86 gestureRecognizerShouldBegin: 87 hasAmbiguousLayout 88 hitTest:withEvent: 88 initWithFrame: 89 insertSubview:aboveSubview: 90 insertSubview:atIndex: 91 insertSubview:belowSubview: 91 intrinsicContentSize 92 invalidateIntrinsicContentSize 93 isDescendantOfView: 93 layoutIfNeeded 94 layoutSubviews 94 needsUpdateConstraints 95 pointInside:withEvent: 95 removeConstraint: 96 removeConstraints: 96 removeFromSuperview 97 removeGestureRecognizer: 97 removeMotionEffect: 98 resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: 98 sendSubviewToBack: 100 setContentCompressionResistancePriority:forAxis: 100 setContentHuggingPriority:forAxis: 101 setNeedsDisplay 102 setNeedsDisplayInRect: 103 setNeedsLayout 104 setNeedsUpdateConstraints 104 setTranslatesAutoresizingMaskIntoConstraints: 105 sizeThatFits: 105 sizeToFit 106 snapshotViewAfterScreenUpdates: 107

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

Contents

systemLayoutSizeFittingSize: 108 tintColorDidChange 108 translatesAutoresizingMaskIntoConstraints 109 updateConstraints 110 updateConstraintsIfNeeded 110 viewForBaselineLayout 111 viewPrintFormatter 111 viewWithTag: 112 willMoveToSuperview: 112 willMoveToWindow: 113 willRemoveSubview: 114 Constants 114 UIViewAnimationOptions 114 UIViewAnimationCurve 118 UIViewKeyframeAnimationOptions 119 UIViewContentMode 121 UILayoutConstraintAxis 123 UIViewTintAdjustmentMode 124 UISystemAnimation 125 Fitting Size 125 UIView Intrinsic Metric Constant 126 UIViewAutoresizing 126 UIViewAnimationTransition 128

Deprecated UIView Methods 130


Deprecated in iOS 6.0 130 contentStretch 130

Document Revision History 131

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

UIView Class Reference

Inherits from Conforms to

UIResponder : NSObject NSCoding UIAppearance UIAppearanceContainer UIDynamicItem NSObject (NSObject)

Framework Availability Declared in

/System/Library/Frameworks/UIKit.framework Available in iOS 2.0 and later. UIPrintFormatter.h UITextField.h UIView.h

Companion guides

View Programming Guide for iOS UIKit User Interface Catalog

Related sample code

AdvancedURLConnections iPhoneCoreDataRecipes TheElements UICatalog UIKit Dynamics Catalog

Overview
The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

UIView Class Reference Overview

the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image. Because view objects are the main way your application interacts with the user, they have a number of responsibilities. Here are just a few:

Drawing and animation

Views draw content in their rectangular area using technologies such as UIKit, Core Graphics, and OpenGL ES. Some view properties can be animated to new values.

Layout and subview management

A view may contain zero or more subviews. Each view defines its own default resizing behavior in relation to its parent view. A view can define the size and position of its subviews as needed.

Event handling

A view is a responder and can handle touch events and other events defined by the UIResponder class. Views can use the addGestureRecognizer: (page 69) method to install gesture recognizers to handle common gestures.

Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationship between the view being embedded (known as the subview) and the parent view doing the embedding (known as the superview). Normally, a subviews visible area is not clipped to the bounds of its superview, but in iOS you can use the clipsToBounds (page 29) property to alter that behavior. A parent view may contain any number of subviews but each subview has only one superview, which is responsible for positioning its subviews appropriately. The geometry of a view is defined by its frame (page 31), bounds (page 26), and center (page 27) properties. The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view. The center property can be used to adjust the position of the view without changing its size. The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both. For detailed information about how to use the UIView class, see View Programming Guide for iOS .

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

UIView Class Reference Overview

Note: In iOS 2.x, the maximum size of a UIView object is 1024 x 1024 points. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. It is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider tiling any content that is significantly larger than the dimensions the screen.

Creating a View
To create a view programmatically, you can use code like the following:
CGRect viewRect = CGRectMake(10, 10, 100, 100);

UIView* myView = [[UIView alloc] initWithFrame:viewRect];

This code creates the view and positions it at the point (10, 10) in its superviews coordinate system (once it is added to that superview). To add a subview to another view, you use the addSubview: (page 71) method. In iOS, sibling views may overlap each other without any issues, allowing complex view placement. The addSubview: (page 71) method places the specified view on top of other siblings. You can specify the relative z-order of a subview by adding it using the insertSubview:aboveSubview: (page 90) and insertSubview:belowSubview: (page 91) methods. You can also exchange the position of already added subviews using the exchangeSubviewAtIndex:withSubviewAtIndex: (page 85) method. When creating a view, it is important to assign an appropriate value to the autoresizingMask (page 25) property to ensure the view resizes correctly. View resizing primarily occurs when the orientation of your applications interface changes but it may happen at other times as well. For example, calling the setNeedsLayout (page 104) method forces your view to update its layout.

The View Drawing Cycle


View drawing occurs on an as-needed basis. When a view is first shown, or when all or part of it becomes visible due to layout changes, the system asks the view to draw its contents. For views that contain custom content using UIKit or Core Graphics, the system calls the views drawRect: (page 81) method. Your implementation of this method is responsible for drawing the views content into the current graphics context, which is set up by the system automatically prior to calling this method. This creates a static visual representation of your views content that can then be displayed on the screen. When the actual content of your view changes, it is your responsibility to notify the system that your view needs to be redrawn. You do this by calling your views setNeedsDisplay (page 102) or setNeedsDisplayInRect: (page 103) method of the view. These methods let the system know that it should update the view during the next drawing cycle. Because it waits until the next drawing cycle to update the view, you can call these methods on multiple views to update them at the same time.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

UIView Class Reference Overview

Note: If you are using OpenGL ES to do your drawing, you should use the GLKView class instead of subclassing UIView. For more information about how to draw using OpenGL ES, see OpenGL ES Programming Guide for iOS .

For detailed information about the view drawing cycle and the role your views have in this cycle, see View Programming Guide for iOS .

Animations
Changes to several view properties can be animatedthat is, changing the property creates an animation that conveys the change to the user over a short period of time. The UIView class does most of the work of performing the actual animations but you must still indicate which property changes you want to be animated. There are two different ways to initiate animations:

In iOS 4 and later, use the block-based animation methods. (Recommended) Use the begin/commit animation methods.

The block-based animation methods (such as animateWithDuration:animations: (page 44)) greatly simplify the creation of animations. With one method call, you specify the animations to be performed and the options for the animation. However, block-based animations are available only in iOS 4 and later. If your application runs on earlier versions of iOS, you must use the beginAnimations:context: (page 49) and commitAnimations (page 50) class methods to mark the beginning and ending of your animations. The following properties of the UIView class are animatable:
@property frame

(page 31) (page 26) (page 27) (page 40)

@property bounds @property center

@property transform @property alpha

(page 24) (page 26)

@property backgroundColor @property contentStretch

(page 130)

For more information about how to configure animations, see View Programming Guide for iOS .

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

10

UIView Class Reference Overview

Threading Considerations
Manipulations to your applications user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. The only time this may not be strictly necessary is when creating the view object itself but all other manipulations should occur on the main thread.

Subclassing Notes
The UIView class is a key subclassing point for visual content that also requires user interactions. Although there are many good reasons to subclass UIView, it is recommended that you do so only when the basic UIView class or the standard system views do not provide the capabilities that you need. Subclassing requires more work on your part to implement the view and to tune its performance. For information about ways to avoid subclassing, see Alternatives to Subclassing (page 12).

Methods to Override
When subclassing UIView, there are only a handful of methods you should override and many methods that you might override depending on your needs. Because UIView is a highly configurable class, there are also many ways to implement sophisticated view behaviors without overriding custom methods, which are discussed in the Alternatives to Subclassing section. In the meantime, the following list includes the methods you might consider overriding in your UIView subclasses:

Initialization:

(page 89) - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.
initWithFrame:

initWithCoder: - Implement this method if you load your view from an Interface Builder nib file

and your view requires custom initialization.

(page 51) - Implement this method only if you want your view to use a different Core Animation layer for its backing store. For example, if your view uses tiling to display a large scrollable area, you might want to override this method and return the CATiledLayer class.
layerClass

Drawing and printing:

(page 81) - Implement this method if your view draws custom content. If your view does not do any custom drawing, avoid overriding this method.
drawRect:

(page 82) - Implement this method only if you want to draw your views content differently during printing.
drawRect:forViewPrintFormatter:

Constraints:

requiresConstraintBasedLayout (page 53) - Implement this class method if your view class requires

constraints to work properly.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

11

UIView Class Reference Overview

updateConstraints (page 110) - Implement this method if your view needs to create custom constraints

between your subviews.

alignmentRectForFrame: (page 71), frameForAlignmentRect: (page 86) - Implement these methods

to override how your views are aligned to other views.

Layout:

(page 105) - Implement this method if you want your view to have a different default size than it normally would during resizing operations. For example, you might use this method to prevent your view from shrinking to the point where subviews cannot be displayed correctly.
sizeThatFits: layoutSubviews (page 94) - Implement this method if you need more precise control over the layout

of your subviews than either the constraint or autoresizing behaviors provide.

(page 79), willRemoveSubview: (page 114) - Implement these methods as needed to track the additions and removals of subviews.
didAddSubview:

(page 112), didMoveToSuperview (page 80) - Implement these methods as needed to track the movement of the current view in your view hierarchy.
willMoveToSuperview:

(page 113), didMoveToWindow (page 80) - Implement these methods as needed to track the movement of your view to a different window.
willMoveToWindow:

Event Handling:

touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:, touchesCancelled:withEvent: - Implement these methods if you need to handle touch events

directly. (For gesture-based input, use gesture recognizers.)

(page 87) - Implement this method if your view handles touch events directly and might want to prevent attached gesture recognizers from triggering additional actions.
gestureRecognizerShouldBegin:

Alternatives to Subclassing
Many view behaviors can be configured without the need for subclassing. Before you start overriding methods, consider whether modifying the following properties or behaviors would provide the behavior you need.

addConstraint:

(page 68) - Define automatic layout behavior for the view and its subviews.

(page 25) - Provides automatic layout behavior when the superviews frame changes. These behaviors can be combined with constraints.
autoresizingMask

(page 29) - Provides layout behavior for the views content, as opposed to the frame of the view. This property also affects how the content is scaled to fit the view and whether it is cached or redrawn.
contentMode

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

12

UIView Class Reference Tasks

(page 130) - Defines portions of the view as being stretchable. This behavior is typically used to implement buttons and other resizable views with sophisticated layout needs where redrawing the view every time would affect performance.
contentStretch

(page 33) or alpha (page 24) - Change the transparency of the view as a whole rather than hiding or applying alpha to your views rendered content.
hidden backgroundColor

(page 26) - Set the views color rather than drawing that color yourself.

Subviews - Rather than draw your content using a drawRect: (page 81) method, embed image and label subviews with the content you want to present. Gesture recognizers - Rather than subclass to intercept and handle touch events yourself, you can use gesture recognizers to send an action message to a target object. Animations - Use the built-in animation support rather than trying to animate changes yourself. The animation support provided by Core Animation is fast and easy to use. Image-based backgrounds - For views that display relatively static content, consider using a UIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the views CALayer object.

Animations are another way to make visible changes to a view without requiring you to subclass and implement complex drawing code. Many properties of the UIView class are animatable, which means changes to those properties can trigger system-generated animations. Starting animations requires as little as one line of code to indicate that any changes that follow should be animated. For more information about animation support for views, see Animations (page 10). For more information about appearance and behavior configuration, see About Views in UIKit User Interface Catalog .

Tasks
Initializing a View Object
initWithFrame:

(page 89) Initializes and returns a newly allocated view object with the specified frame rectangle.

Configuring a Views Visual Appearance


backgroundColor

(page 26) property The views background color.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

13

UIView Class Reference Tasks

hidden

(page 33) property A Boolean value that determines whether the view is hidden. (page 24) property The views alpha value. (page 35) property A Boolean value that determines whether the view is opaque. (page 39) property The first nondefault tint color value in the views hierarchy, ascending from and starting with the view itself. (page 38) property The first non-default tint adjustment mode value in the views hierarchy, ascending from and starting with the view itself. (page 29) property A Boolean value that determines whether subviews are confined to the bounds of the view. (page 28) property A Boolean value that determines whether the views bounds should be automatically cleared before drawing. (page 51) Returns the class used to create the layer for instances of this class. (page 34) property The views Core Animation layer used for rendering. (read-only)

alpha

opaque

tintColor

tintAdjustmentMode

clipsToBounds

clearsContextBeforeDrawing

+ layerClass

layer

Configuring the Event-Related Behavior


userInteractionEnabled

(page 40) property A Boolean value that determines whether user events are ignored and removed from the event queue. (page 35) property A Boolean value that indicates whether the receiver handles multi-touch events. (page 31) property A Boolean value that indicates whether the receiver handles touch events exclusively.

multipleTouchEnabled

exclusiveTouch

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

14

UIView Class Reference Tasks

Configuring the Bounds and Frame Rectangles


frame

(page 31) property The frame rectangle, which describes the views location and size in its superviews coordinate system. (page 26) property The bounds rectangle, which describes the views location and size in its own coordinate system. (page 27) property The center of the frame. (page 40) property Specifies the transform applied to the receiver, relative to the center of its bounds.

bounds

center

transform

Managing the View Hierarchy


superview

(page 37) property The receivers superview, or nil if it has none. (read-only) (page 37) property The receivers immediate subviews. (read-only) (page 41) property The receivers window object, or nil if it has none. (read-only) (page 71) Adds a view to the end of the receivers list of subviews. (page 73) Moves the specified subview so that it appears on top of its siblings. (page 100) Moves the specified subview so that it appears behind its siblings. (page 97) Unlinks the view from its superview and its window, and removes it from the responder chain. (page 91) Inserts a subview at the specified index. (page 90) Inserts a view above another view in the view hierarchy. (page 91) Inserts a view below another view in the view hierarchy. (page 85) Exchanges the subviews at the specified indices.

subviews

window

addSubview:

bringSubviewToFront:

sendSubviewToBack:

removeFromSuperview

insertSubview:atIndex:

insertSubview:aboveSubview:

insertSubview:belowSubview:

exchangeSubviewAtIndex:withSubviewAtIndex:

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

15

UIView Class Reference Tasks

isDescendantOfView:

(page 93) Returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.

Configuring the Resizing Behavior


autoresizingMask

(page 25) property An integer bit mask that determines how the receiver resizes itself when its superviews bounds change. (page 24) property A Boolean value that determines whether the receiver automatically resizes its subviews when its bounds change. (page 29) property A flag used to determine how a view lays out its content when its bounds change. (page 105) Asks the view to calculate and return the size that best fits its subviews. (page 106) Resizes and moves the receiver view so it just encloses its subviews. (page 130) property Deprecated in iOS 6.0 The rectangle that defines the stretchable and nonstretchable regions of a view.

autoresizesSubviews

contentMode

sizeThatFits:

sizeToFit

contentStretch

Laying out Subviews


layoutSubviews

(page 94) Lays out subviews. (page 104) Invalidates the current layout of the receiver and triggers a layout update during the next update cycle. (page 94) Lays out the subviews immediately.

setNeedsLayout

layoutIfNeeded

Opting in to Constraint-Based Layout


+ requiresConstraintBasedLayout

(page 53) Returns whether the receiver depends on the constraint-based layout system.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

16

UIView Class Reference Tasks

translatesAutoresizingMaskIntoConstraints

(page 109) Returns a Boolean value that indicates whether the views autoresizing mask is translated into constraints for the constraint-based layout system. (page 105) Sets whether the views autoresizing mask should be translated into constraints for the constraint-based layout system.

setTranslatesAutoresizingMaskIntoConstraints:

Managing Constraints
constraints

(page 73) Returns the constraints held by the view. (page 68) Adds a constraint on the layout of the receiving view or its subviews. (page 69) Adds multiple constraints on the layout of the receiving view or its subviews. (page 96) Removes the specified constraint from the view. (page 96) Removes the specified constraints from the view.

addConstraint:

addConstraints:

removeConstraint:

removeConstraints:

Measuring in Constraint-Based Layout


systemLayoutSizeFittingSize:

(page 108) Returns the size of the view that satisfies the constraints it holds. (page 92) Returns the natural size for the receiving view, considering only properties of the view itself. (page 93) Invalidates the views intrinsic content size. (page 74) Returns the priority with which a view resists being made smaller than its intrinsic size. (page 100) Sets the priority with which a view resists being made smaller than its intrinsic size. (page 75) Returns the priority with which a view resists being made larger than its intrinsic size.

intrinsicContentSize

invalidateIntrinsicContentSize

contentCompressionResistancePriorityForAxis:

setContentCompressionResistancePriority:forAxis:

contentHuggingPriorityForAxis:

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

17

UIView Class Reference Tasks

setContentHuggingPriority:forAxis:

(page 101) Sets the priority with which a view resists being made larger than its intrinsic size.

Aligning Views with Constraint-Based Layout


alignmentRectForFrame:

(page 71) Returns the views alignment rectangle for a given frame. (page 86) Returns the views frame for a given alignment rectangle. (page 72) Returns the insets from the views frame that define its alignment rectangle. (page 111) Returns a view used to satisfy baseline constraints.

frameForAlignmentRect:

alignmentRectInsets

viewForBaselineLayout

Triggering Constraint-Based Layout


needsUpdateConstraints

(page 95) Returns whether the views constraints need updating. (page 104) Controls whether the views constraints need updating. (page 110) Updates constraints for the view. (page 110) Updates the constraints for the receiving view and its subviews.

setNeedsUpdateConstraints

updateConstraints

updateConstraintsIfNeeded

Debugging Constraint-Based Layout


See Auto Layout Guide for more details on debugging constraint-based layout.
constraintsAffectingLayoutForAxis:

(page 74) Returns the constraints impacting the layout of the view for a given axis. (page 88) Returns whether the constraints impacting the layout of the view incompletely specify the location of the view.

hasAmbiguousLayout

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

18

UIView Class Reference Tasks

exerciseAmbiguityInLayout

(page 86) Randomly changes the frame of a view with an ambiguous layout between the different valid values.

Drawing and Updating the View


drawRect:

(page 81) Draws the receivers image within the passed-in rectangle. (page 102) Marks the receivers entire bounds rectangle as needing to be redrawn. (page 103) Marks the specified rectangle of the receiver as needing to be redrawn. (page 30) property The scale factor applied to the view. (page 108) Called by the system when the tintColor property changes.

setNeedsDisplay

setNeedsDisplayInRect:

contentScaleFactor

tintColorDidChange

Formatting Printed View Content


viewPrintFormatter

(page 111) Returns a print formatter for the receiving view. (page 82) Implemented to draw the views content for printing.

drawRect:forViewPrintFormatter:

Managing Gesture Recognizers


addGestureRecognizer:

(page 69) Attaches a gesture recognizer to the view. (page 97) Detaches a gesture recognizer from the receiving view. (page 32) property The gesture-recognizer objects currently attached to the view. (page 87) Asks the view if the gesture recognizer should be allowed to continue tracking touch events.

removeGestureRecognizer:

gestureRecognizers

gestureRecognizerShouldBegin:

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

19

UIView Class Reference Tasks

Animating Views with Block Objects


+ animateWithDuration:delay:options:animations:completion:

(page 46) Animate changes to one or more views using the specified duration, delay, options, and completion handler. (page 45) Animate changes to one or more views using the specified duration and completion handler. (page 44) Animate changes to one or more views using the specified duration. (page 67) Creates a transition animation for the specified container view.

+ animateWithDuration:animations:completion:

+ animateWithDuration:animations:

+ transitionWithView:duration:options:animations:completion:

+ transitionFromView:toView:duration:options:completion:

(page 65) Creates a transition animation between the specified views using the given parameters. (page 43) Creates an animation block object that can be used to set up keyframe-based animations for the current view. (page 41) Specifies the timing and animation values for a single frame of a keyframe animation. (page 52) Performs a specified system-provided animation on one or more views, along with optional parallel animations that you define.

+ animateKeyframesWithDuration:delay:options:animations:completion:

+ addKeyframeWithRelativeStartTime:relativeDuration:animations:

+ performSystemAnimation:onViews:options:animations:completion:

+ animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion: (page

47) Performs a view animation using a timing curve corresponding to the motion of a physical spring.
+ performWithoutAnimation:

(page 52) Disables a view transition animation.

Animating Views
Use of the methods in this section is discouraged in iOS 4 and later. Use the block-based animation methods instead.
+ beginAnimations:context:

(page 49) Marks the beginning of a begin/commit animation block. (page 50) Marks the end of a begin/commit animation block and schedules the animations for execution.

+ commitAnimations

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

20

UIView Class Reference Tasks

+ setAnimationStartDate:

(page 62) Sets the start time for the current animation block. (page 61) Sets whether animations are enabled. (page 56) Sets the delegate for any animation messages. (page 64) Sets the message to send to the animation delegate when the animation starts. (page 57) Sets the message to send to the animation delegate when animation stops. (page 58) Sets the duration (measured in seconds) of the animations in an animation block. (page 55) Sets the amount of time (in seconds) to wait before animating property changes within an animation block. (page 54) Sets the curve to use when animating property changes within an animation block. (page 60) Sets the number of times animations within an animation block repeat. (page 59) Sets whether the animations within an animation block automatically reverse themselves. (page 53) Sets whether the animation should begin playing from the current state. (page 63) Sets a transition to apply to a view during an animation block. (page 48) Returns a Boolean value indicating whether animations are enabled.

+ setAnimationsEnabled:

+ setAnimationDelegate:

+ setAnimationWillStartSelector:

+ setAnimationDidStopSelector:

+ setAnimationDuration:

+ setAnimationDelay:

+ setAnimationCurve:

+ setAnimationRepeatCount:

+ setAnimationRepeatAutoreverses:

+ setAnimationBeginsFromCurrentState:

+ setAnimationTransition:forView:cache:

+ areAnimationsEnabled

Using Motion Effects


addMotionEffect:

(page 70) Begins applying a motion effect to the view. (page 34) property The array of motion effects for the view.

motionEffects

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

21

UIView Class Reference Tasks

removeMotionEffect:

(page 98) Stops applying a motion effect to the view.

Preserving and Restoring State


restorationIdentifier

(page 36) property The identifier that determines whether the view supports state restoration. (page 83) Encodes state-related information for the view. (page 78) Decodes and restores state-related information for the view.

encodeRestorableStateWithCoder:

decodeRestorableStateWithCoder:

Capturing a View Snapshot


snapshotViewAfterScreenUpdates:

(page 107) Returns a snapshot view based on the contents of the current view. (page 98) Returns a snapshot view based on the specified contents of the current view, with stretchable insets. (page 82) Renders a snapshot of the complete view hierarchy as visible onscreen into the current context.

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

drawViewHierarchyInRect:afterScreenUpdates:

Identifying the View at Runtime


tag

(page 38) property An integer that you can use to identify view objects in your application. (page 112) Returns the view whose tag matches the specified value.

viewWithTag:

Converting Between View Coordinate Systems


convertPoint:toView:

(page 76) Converts a point from the receivers coordinate system to that of the specified view.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

22

UIView Class Reference Tasks

convertPoint:fromView:

(page 76) Converts a point from the coordinate system of a given view to that of the receiver. (page 78) Converts a rectangle from the receivers coordinate system to that of another view. (page 77) Converts a rectangle from the coordinate system of another view to that of the receiver.

convertRect:toView:

convertRect:fromView:

Hit Testing in a View


hitTest:withEvent:

(page 88) Returns the farthest descendant of the receiver in the view hierarchy (including itself ) that contains a specified point. (page 95) Returns a Boolean value indicating whether the receiver contains the specified point.

pointInside:withEvent:

Ending a View Editing Session


endEditing:

(page 84) Causes the view (or one of its embedded text fields) to resign the first responder status.

Observing View-Related Changes


didAddSubview:

(page 79) Tells the view that a subview was added. (page 114) Tells the view that a subview is about to be removed. (page 112) Tells the view that its superview is about to change to the specified superview. (page 80) Tells the view that its superview changed. (page 113) Tells the view that its window object is about to change. (page 80) Tells the view that its window object changed.

willRemoveSubview:

willMoveToSuperview:

didMoveToSuperview

willMoveToWindow:

didMoveToWindow

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

23

UIView Class Reference Properties

Properties
alpha
The views alpha value.
@property(nonatomic) CGFloat alpha

Discussion The value of this property is a floating-point number in the range 0.0 to 1.0, where 0.0 represents totally transparent and 1.0 represents totally opaque. This value affects only the current view and does not affect any of its embedded subviews. Changes to this property can be animated. Availability Available in iOS 2.0 and later. See Also
@property backgroundColor @property opaque

(page 26)

(page 35)

Related Sample Code

iPhoneCoreDataRecipes LocateMe SimpleNetworkStreams UIImagePicker Video Recorder UnwindSegue Declared in


UIView.h

autoresizesSubviews
A Boolean value that determines whether the receiver automatically resizes its subviews when its bounds change.
@property(nonatomic) BOOL autoresizesSubviews

Discussion When set to YES, the receiver adjusts the size of its subviews when its bounds change. The default value is YES.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

24

UIView Class Reference Properties

Availability Available in iOS 2.0 and later. See Also


@property autoresizingMask

(page 25)

Declared in
UIView.h

autoresizingMask
An integer bit mask that determines how the receiver resizes itself when its superviews bounds change.
@property(nonatomic) UIViewAutoresizing autoresizingMask

Discussion When a views bounds change, that view automatically resizes its subviews according to each subviews autoresizing mask. You specify the value of this mask by combining the constants described in UIViewAutoresizing (page 126) using the C bitwise OR operator. Combining these constants lets you specify which dimensions of the view should grow or shrink relative to the superview. The default value of this property is UIViewAutoresizingNone, which indicates that the view should not be resized at all. When more than one option along the same axis is set, the default behavior is to distribute the size difference proportionally among the flexible portions. The larger the flexible portion, relative to the other flexible portions, the more it is likely to grow. For example, suppose this property includes the UIViewAutoresizingFlexibleWidth (page 127) and UIViewAutoresizingFlexibleRightMargin (page 127) constants but does not include the UIViewAutoresizingFlexibleLeftMargin constant, thus indicating that the width of the views left margin is fixed but that the views width and right margin may change. Thus, the view appears anchored to the left side of its superview while both the view width and the gap to the right of the view increase. If the autoresizing behaviors do not offer the precise layout that you need for your views, you can use a custom container view and override its layoutSubviews (page 94) method to position your subviews more precisely. Availability Available in iOS 2.0 and later. See Also
@property autoresizesSubviews

(page 24)

Related Sample Code

MVCNetworking NavBar

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

25

UIView Class Reference Properties

PrintPhoto UICatalog XMLPerformance Declared in


UIView.h

backgroundColor
The views background color.
@property(nonatomic, copy) UIColor *backgroundColor

Discussion Changes to this property can be animated. The default value is nil, which results in a transparent background color. Availability Available in iOS 2.0 and later. See Also (page 24) @property opaque (page 35)
@property alpha

Related Sample Code

iPhoneCoreDataRecipes MoviePlayer NavBar UICatalog XMLPerformance Declared in


UIView.h

bounds
The bounds rectangle, which describes the views location and size in its own coordinate system.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

26

UIView Class Reference Properties

@property(nonatomic) CGRect bounds

Discussion On the screen, the bounds rectangle represents the same visible portion of the view as its frame rectangle. By default, the origin of the bounds rectangle is set to (0, 0) but you can change this value to display different portions of the view. The size of the bounds rectangle is coupled to the size of the frame rectangle, so that changes to one affect the other. Changing the bounds size grows or shrinks the view relative to its center point. The coordinates of the bounds rectangle are always specified in points. Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: (page 81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, set the contentMode (page 29) property to UIViewContentModeRedraw (page 122). Changes to this property can be animated. The default bounds origin is (0,0) and the size is the same as the frame rectangles size. Availability Available in iOS 2.0 and later. See Also (page 31) @property center (page 27) @property transform (page 40)
@property frame

Related Sample Code

iAdInterstitialSuite SpeakHere Teslameter UICatalog UIKit Dynamics Catalog Declared in


UIView.h

center
The center of the frame.
@property(nonatomic) CGPoint center

Discussion The center is specified within the coordinate system of its superview and is measured in points. Setting this property changes the values of the frame (page 31) properties accordingly.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

27

UIView Class Reference Properties

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: (page 81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, set the contentMode (page 29) property to UIViewContentModeRedraw (page 122). Changes to this property can be animated. Use the beginAnimations:context: (page 49) class method to begin and the commitAnimations (page 50) class method to end an animation block. Availability Available in iOS 2.0 and later. See Also (page 31) @property bounds (page 26) @property transform (page 40)
@property frame

Related Sample Code

AVLoupe Handling Touches Using Responder Methods and Gesture Recognizers iAdInterstitialSuite iAdSuite RosyWriter Declared in
UIView.h

clearsContextBeforeDrawing
A Boolean value that determines whether the views bounds should be automatically cleared before drawing.
@property(nonatomic) BOOL clearsContextBeforeDrawing

Discussion When set to YES, the drawing buffer is automatically cleared to transparent black before the drawRect: (page 81) method is called. This behavior ensures that there are no visual artifacts left over when the views contents are redrawn. If the views opaque (page 35) property is also set to YES, the backgroundColor (page 26) property of the view must not be nil or drawing errors may occur. The default value of this property is YES. If you set the value of this property to NO, you are responsible for ensuring the contents of the view are drawn properly in your drawRect: method. If your drawing code is already heavily optimized, setting this property is NO can improve performance, especially during scrolling when only a portion of the view might need to be redrawn.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

28

UIView Class Reference Properties

Availability Available in iOS 2.0 and later. Declared in


UIView.h

clipsToBounds
A Boolean value that determines whether subviews are confined to the bounds of the view.
@property(nonatomic) BOOL clipsToBounds

Discussion Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO. Availability Available in iOS 2.0 and later.
Related Sample Code

UIKit Dynamics Catalog Declared in


UIView.h

contentMode
A flag used to determine how a view lays out its content when its bounds change.
@property(nonatomic) UIViewContentMode contentMode

Discussion The content mode specifies how the cached bitmap of the views layer is adjusted when the views bounds change. This property is often used to implement resizable controls, usually in conjunction with the contentStretch (page 130) property. Instead of redrawing the contents of the view every time, you can use this property to specify that you want to scale the contents (either with or without distortion) or pin them to a particular spot on the view.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

29

UIView Class Reference Properties

Note: You can always force the contents of a view to be redrawn by calling the setNeedsDisplay (page 102) or setNeedsDisplayInRect: (page 103) method.

For a list of values you can assign to this property, see UIViewContentMode (page 121). The default value of this property is UIViewContentModeScaleToFill (page 122). Availability Available in iOS 2.0 and later.
Related Sample Code

AirDrop Examples iPhoneCoreDataRecipes PrintPhoto WiTap ZoomingPDFViewer Declared in


UIView.h

contentScaleFactor
The scale factor applied to the view.
@property(nonatomic) CGFloat contentScaleFactor

Discussion The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels). This value is typically either 1.0 or 2.0. Higher scale factors indicate that each point in the view is represented by more than one pixel in the underlying layer. For example, if the scale factor is 2.0 and the view frame size is 50 x 50 points, the size of the bitmap used to present that content is 100 x 100 pixels. The default value for this property is the scale factor associated with the screen currently displaying the view. If your custom view implements a custom drawRect: (page 81) method and is associated with a window, or if you use the GLKView class to draw OpenGL ES content, your view draws at the full resolution of the screen. For system views, the value of this property may be 1.0 even on high resolution screens. In general, you should not need to modify the value in this property. However, if your application draws using OpenGL ES, you may want to change the scale factor to trade image quality for rendering performance. For more information on how to adjust your OpenGL ES rendering environment, see Supporting High-Resolution Displays in OpenGL ES Programming Guide for iOS .

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

30

UIView Class Reference Properties

Availability Available in iOS 4.0 and later.


Related Sample Code

GLCameraRipple Large Image Downsizing Declared in


UIView.h

exclusiveTouch
A Boolean value that indicates whether the receiver handles touch events exclusively.
@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch

Discussion Setting this property to YES causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NO. Availability Available in iOS 2.0 and later. See Also
@property multipleTouchEnabled

(page 35)

Declared in
UIView.h

frame
The frame rectangle, which describes the views location and size in its superviews coordinate system.
@property(nonatomic) CGRect frame

Discussion This rectangle defines the size and position of the view in its superviews coordinate system. You use this rectangle during layout operations to size and position the view. Setting this property changes the point specified by the center (page 27) property and the size in the bounds (page 26) rectangle accordingly. The coordinates of the frame rectangle are always specified in points.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

31

UIView Class Reference Properties

Warning: If the transform (page 40) property is not the identity transform, the value of this property is undefined and therefore should be ignored. Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: (page 81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, set the contentMode (page 29) property to UIViewContentModeRedraw (page 122). Changes to this property can be animated. However, if the transform (page 40) property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center (page 27) property and adjust the size using the bounds (page 26) property instead. Availability Available in iOS 2.0 and later. See Also (page 26) @property center (page 27) @property transform (page 40)
@property bounds

Related Sample Code

PVRTextureLoader SpeakHere StreetScroller UICatalog XMLPerformance Declared in


UIView.h

gestureRecognizers
The gesture-recognizer objects currently attached to the view.
@property(nonatomic, copy) NSArray *gestureRecognizers

Discussion Each of these objects is an instance of a subclass of the abstract base class UIGestureRecognizer. If there are no gesture recognizers attached, the value of this property is an empty array.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

32

UIView Class Reference Properties

Availability Available in iOS 3.2 and later. Declared in


UIView.h

hidden
A Boolean value that determines whether the view is hidden.
@property(nonatomic, getter=isHidden) BOOL hidden

Discussion Setting the value of this property to YES hides the receiver and setting it to NO shows the receiver. The default value is NO. A hidden view disappears from its window and does not receive input events. It remains in its superviews list of subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect of hiding those subviews and any view descendants they might have. This effect is implicit and does not alter the hidden state of the receivers descendants. Hiding the view that is the windows current first responder causes the views next valid key view to become the new first responder. The value of this property reflects the state of the receiver only and does not account for the state of the receivers ancestors in the view hierarchy. Thus this property can be NO but the receiver may still be hidden if an ancestor is hidden. Availability Available in iOS 2.0 and later.
Related Sample Code

CryptoExercise GeocoderDemo iAdInterstitialSuite Regions UICatalog Declared in


UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

33

UIView Class Reference Properties

layer
The views Core Animation layer used for rendering. (read-only)
@property(nonatomic, readonly, retain) CALayer *layer

Discussion This property is never nil. The actual class of the object is determined by the value returned by the layerClass method. The view is the layers delegate. Warning: Because the view is the layers delegate, never make the view the delegate of another
CALayer object. Additionally, never change the delegate of this layer object.

Availability Available in iOS 2.0 and later. See Also


+ layerClass

(page 51)

Related Sample Code

GeocoderDemo Handling Touches Using Responder Methods and Gesture Recognizers MTAudioProcessingTap Audio Processor PhotosByLocation UnwindSegue Declared in
UIView.h

motionEffects
The array of motion effects for the view.
@property(copy, nonatomic) NSArray *motionEffects

Availability Available in iOS 7.0 and later. Declared in


UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

34

UIView Class Reference Properties

multipleTouchEnabled
A Boolean value that indicates whether the receiver handles multi-touch events.
@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

Discussion When set to YES, the receiver receives all touches associated with a multi-touch sequence. When set to NO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property is NO. Other views in the same window can still receive touch events when this property is NO. If you want this view to handle multi-touch events exclusively, set the values of both this property and the exclusiveTouch (page 31) property to YES. Availability Available in iOS 2.0 and later. See Also
@property exclusiveTouch

(page 31)

Related Sample Code

aurioTouch2 Declared in
UIView.h

opaque
A Boolean value that determines whether the view is opaque.
@property(nonatomic, getter=isOpaque) BOOL opaque

Discussion This property provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NO, the drawing system composites the view normally with other content. The default value of this property is YES. An opaque view is expected to fill its bounds with entirely opaque contentthat is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

35

UIView Class Reference Properties

Availability Available in iOS 2.0 and later. See Also


@property backgroundColor @property alpha

(page 26)

(page 24)

Related Sample Code

AVMovieExporter MapCallouts NavBar pARk UICatalog Declared in


UIView.h

restorationIdentifier
The identifier that determines whether the view supports state restoration.
@property(nonatomic, copy) NSString *restorationIdentifier

Discussion This property indicates whether state information in the view should be preserved; it is also used to identify the view during the restoration process. The value of this property is nil by default, which indicates that the views state does not need to be saved. Assigning a string object to the property lets the owning view controller know that the view has relevant state information to save. Assign a value to this property only if you are implementing a custom view that implements the encodeRestorableStateWithCoder: (page 83) and decodeRestorableStateWithCoder: (page 78) methods for saving and restoring state. You use those methods to write any view-specific state information and subsequently use that data to restore the view to its previous configuration. Important: Simply setting the value of this property is not enough to ensure that the view is preserved and restored. Its owning view controller, and all of that view controller's parent view controllers, must also have a restoration identifier. For more information about the preservation and restoration process, see iOS App Programming Guide . Availability Available in iOS 6.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

36

UIView Class Reference Properties

Declared in
UIView.h

subviews
The receivers immediate subviews. (read-only)
@property(nonatomic, readonly, copy) NSArray *subviews

Discussion You can use this property to retrieve the subviews associated with your custom view hierarchies. The order of the subviews in the array reflects their visible order on the screen, with the view at index 0 being the back-most view. For complex views declared in UIKit and other system frameworks, any subviews of the view are generally considered private and subject to change at any time. Therefore, you should not attempt to retrieve or modify subviews for these types of system-supplied views. If you do, your code may break during a future system update. Availability Available in iOS 2.0 and later. See Also (page 37) removeFromSuperview (page 97)
@property superview

Related Sample Code

PageControl SimpleNetworkStreams Declared in


UIView.h

superview
The receivers superview, or nil if it has none. (read-only)
@property(nonatomic, readonly) UIView *superview

Availability Available in iOS 2.0 and later. See Also


@property subviews

(page 37)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

37

UIView Class Reference Properties

removeFromSuperview

(page 97)

Related Sample Code

DateCell Handling Touches Using Responder Methods and Gesture Recognizers WiTap Declared in
UIView.h

tag
An integer that you can use to identify view objects in your application.
@property(nonatomic) NSInteger tag

Discussion The default value is 0. You can set the value of this tag and use that value to identify the view later. Availability Available in iOS 2.0 and later. See Also
viewWithTag:

(page 112)

Related Sample Code

Audio Mixer (MixerHost) GenericKeychain iPhoneCoreDataRecipes iPhoneMultichannelMixerTest LocateMe Declared in


UIView.h

tintAdjustmentMode
The first non-default tint adjustment mode value in the views hierarchy, ascending from and starting with the view itself.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

38

UIView Class Reference Properties

@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode

Discussion When this propertys value is UIViewTintAdjustmentModeDimmed (page 125), the value of the tintColor (page 39) property is modified to provide a dimmed appearance. If the system cannot find a non-default value in the subview hierarchy when you query this property, the value is UIViewTintAdjustmentModeNormal (page 124). When this propertys value changes (either by the views value changing or by one of its superviews values changing), -the system calls the tintColorDidChange (page 108) method to allow the view to refresh its rendering. Availability Available in iOS 7.0 and later. Declared in
UIView.h

tintColor
The first nondefault tint color value in the views hierarchy, ascending from and starting with the view itself.
@property(nonatomic, retain) UIColor *tintColor

Discussion If the system cannot find a nondefault color in the hierarchy, this propertys value is a system-defined color instead. If the views tintAdjustmentMode (page 38) propertys value is UIViewTintAdjustmentModeDimmed (page 125), then the tintColor property value is automatically dimmed. To refresh subview rendering when this property changes, override the tintColorDidChange (page 108) method. Colors that are pattern colors (as described in UIColor Class Reference ) are not supported. Important: If you attempt to use a pattern color as a tint color, the system raises an exception. Availability Available in iOS 7.0 and later. See Also
tintColorDidChange

(page 108)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

39

UIView Class Reference Properties

Declared in
UIView.h

transform
Specifies the transform applied to the receiver, relative to the center of its bounds.
@property(nonatomic) CGAffineTransform transform

Discussion The origin of the transform is the value of the center (page 27) property, or the layers anchorPoint property if it was changed. (Use the layer (page 34) property to get the underlying Core Animation layer object.) The default value is CGAffineTransformIdentity. Changes to this property can be animated. Use the beginAnimations:context: (page 49) class method to begin and the commitAnimations (page 50) class method to end an animation block. The default is whatever the center value is (or anchor point if changed) Warning: If this property is not the identity transform, the value of the frame (page 31) property is undefined and therefore should be ignored. Availability Available in iOS 2.0 and later. See Also (page 31) @property bounds (page 26) @property center (page 27)
@property frame

Related Sample Code

aurioTouch2 Handling Touches Using Responder Methods and Gesture Recognizers RosyWriter SquareCam Declared in
UIView.h

userInteractionEnabled
A Boolean value that determines whether user events are ignored and removed from the event queue.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

40

UIView Class Reference Class Methods

@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

Discussion When set to NO, user eventssuch as touch and keyboardintended for the view are ignored and removed from the event queue. When set to YES, events are delivered to the view normally. The default value of this property is YES. During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying the UIViewAnimationOptionAllowUserInteraction (page 115) option when configuring the animation. Note: Some UIKit subclasses override this property and return a different default value. See the documentation for that class to determine if it returns a different value.

Availability Available in iOS 2.0 and later. Declared in


UIView.h

window
The receivers window object, or nil if it has none. (read-only)
@property(nonatomic, readonly) UIWindow *window

Discussion This property is nil if the view has not yet been added to a window. Availability Available in iOS 2.0 and later. Declared in
UIView.h

Class Methods
addKeyframeWithRelativeStartTime:relativeDuration:animations:
Specifies the timing and animation values for a single frame of a keyframe animation.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

41

UIView Class Reference Class Methods

+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime

relativeDuration:(double)frameDuration animations:(void (^)(void))animations

Parameters
frameStartTime

The time at which to start the specified animations. This value must be in the range 0 to 1, where 0 represents the start of the overall animation and 1 represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of 0.5 causes the animations to begin executing one second after the start of the overall animation.
frameDuration

The length of time over which to animate to the specified value. This value must be in the range 0 to 1 and indicates the amount of time relative to the overall animation length. If you specify a value of 0, any properties you set in the animations block update immediately at the specified start time. If you specify a nonzero value, the properties animate over that amount of time. For example, for an animation that is two seconds in duration, specifying a duration of 0.5 results in an animation duration of one second.
animations

A block object containing the animations you want to perform. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be nil. Discussion To animate view properties during a keyframe animation, call this method from within the animation block you pass to the animateKeyframesWithDuration:delay:options:animations:completion: method. To animate between different values, or to tweak the timing of your view property animations, you can call this method multiple times within a block. The view properties you change in the animations block animate over the timespan you specify in frameDuration parameter. The properties do not begin animating until the time you specify in the frameStartTime parameter. After the frame start time, the animation executes over its specified duration or until interrupted by another animation. Availability Available in iOS 7.0 and later. See Also
+ animateKeyframesWithDuration:delay:options:animations:completion:

(page 43)

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

42

UIView Class Reference Class Methods

animateKeyframesWithDuration:delay:options:animations:completion:
Creates an animation block object that can be used to set up keyframe-based animations for the current view.
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration

delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Parameters
duration

The duration of the overall animation, measured in seconds. If you specify a negative value or 0, changes are made immediately and without animations.
delay

Specifies the time (in seconds) to wait before starting the animation.
options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewKeyframeAnimationOptions (page 119).
animations

A block object containing the changes to commit to the views. Typically, you call the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times from inside this block. You may also change view values directly if you want those changes to animate over the full duration. This block takes no parameters and has no return value. Do not use a nil value for this parameter.
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. You can use a nil value for this parameter. Discussion This method creates an animation block that you can use to set up a keyframe-based animation. The keyframes themselves are not part of the initial animation block you create using this method. Inside the animations block, you must add the keyframe time and animation data by calling the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times. Adding keyframes causes the animation to animate the view from its current value to the value of the first keyframe, then to the value of the next keyframe, and so on at the times you specify. If you do not add any keyframes in the animations block, the animation proceeds from start to end like a standard animation block. In other words, the system animates from the current view values to any new values over the specified duration.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

43

UIView Class Reference Class Methods

Availability Available in iOS 7.0 and later. See Also


+ addKeyframeWithRelativeStartTime:relativeDuration:animations:

(page 41)

Declared in
UIView.h

animateWithDuration:animations:
Animate changes to one or more views using the specified duration.
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void

(^)(void))animations

Parameters
duration

The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.
animations

A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL. Discussion This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut (page 116) and UIViewAnimationOptionTransitionNone (page 117) animation options. During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) Availability Available in iOS 4.0 and later.
Related Sample Code

HeadsUpUI iAdSuite MoveMe Simple Gesture Recognizers UIImagePicker Video Recorder

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

44

UIView Class Reference Class Methods

Declared in
UIView.h

animateWithDuration:animations:completion:
Animate changes to one or more views using the specified duration and completion handler.
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void

(^)(void))animations completion:(void (^)(BOOL finished))completion

Parameters
duration

The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.
animations

A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL. Discussion This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut (page 116) and UIViewAnimationOptionTransitionNone (page 117) animation options. For example, if you want to fade a view until it is totally transparent and then remove it from your view hierarchy, you could use code similar to the following:
[UIView animateWithDuration:0.2 animations:^{view.alpha = 0.0;} completion:^(BOOL finished){ [view removeFromSuperview]; }];

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

45

UIView Class Reference Class Methods

Availability Available in iOS 4.0 and later.


Related Sample Code

AVPlayerDemo DateCell iAdInterstitialSuite SquareCam StitchedStreamPlayer Declared in


UIView.h

animateWithDuration:delay:options:animations:completion:
Animate changes to one or more views using the specified duration, delay, options, and completion handler.
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay

options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Parameters
duration

The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.
delay

The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of 0 to begin the animations immediately.
options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions (page 114).
animations

A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

46

UIView Class Reference Class Methods

Discussion This method initiates a set of animations to perform on the view. The block object in the animations parameter contains the code for animating the properties of one or more views. During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction (page 115) constant in the options parameter. Availability Available in iOS 4.0 and later.
Related Sample Code

AirDrop Examples UIImagePicker Video Recorder UnwindSegue Declared in


UIView.h

animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options: animations:completion:
Performs a view animation using a timing curve corresponding to the motion of a physical spring.
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay

usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Parameters
duration

The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.
delay

The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of 0 to begin the animations immediately.
dampingRatio

The damping ratio for the spring animation as it approaches its quiescent state. To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

47

UIView Class Reference Class Methods

velocity

The initial spring velocity. For smooth start to the animation, match this value to the views velocity as it was prior to attachment. A value of 1 corresponds to the total animation distance traversed in one second. For example, if the total animation distance is 200 points and you want the start of the animation to match a view velocity of 100 pt/s, use a value of 0.5.
options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions (page 114).
animations

A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be NULL.
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL. Discussion Availability Available in iOS 7.0 and later. Declared in
UIView.h

areAnimationsEnabled
Returns a Boolean value indicating whether animations are enabled.
+ (BOOL)areAnimationsEnabled

Return Value YES if animations are enabled; otherwise, NO. Availability Available in iOS 2.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

48

UIView Class Reference Class Methods

See Also (page 61) + performWithoutAnimation: (page 52)


+ setAnimationsEnabled:

Related Sample Code

iAdSuite

Declared in
UIView.h

beginAnimations:context:
Marks the beginning of a begin/commit animation block.
+ (void)beginAnimations:(NSString *)animationID context:(void *)context

Parameters
animationID

An application-supplied identifier for the animations.


context

Custom data that you want to associate with this set of animations. information that is passed to the animation delegate messagesthe selectors set using the setAnimationWillStartSelector: (page 64) and setAnimationDidStopSelector: (page 57) methods. Discussion This method signals to the system that you want to specify one or more animations to perform. After calling this method, configure the animation options (using the setAnimation class methods) and then change the desired animatable properties of your views. When you are done changing your view properties, call the commitAnimations (page 50) method to close the set and schedule the animations. You can nest sets of animations (by calling this method again before committing a previous set of animations) as needed. Nesting animations groups them together and allows you to set different animation options for the nested group. If you install a start or stop selector using the setAnimationWillStartSelector: (page 64) or setAnimationDidStopSelector: (page 57) method, the values you specify for the animationID and context parameters are passed to your selectors at runtime. You can use these parameters to pass additional information to those selectors. Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

49

UIView Class Reference Class Methods

Availability Available in iOS 2.0 and later. See Also


+ commitAnimations

(page 50)

(page 64) + setAnimationDidStopSelector: (page 57) + setAnimationDelegate: (page 56)


+ setAnimationWillStartSelector:

Related Sample Code

AdvancedURLConnections Handling Touches Using Responder Methods and Gesture Recognizers KeyboardAccessory LocateMe UICatalog Declared in
UIView.h

commitAnimations
Marks the end of a begin/commit animation block and schedules the animations for execution.
+ (void)commitAnimations

Discussion If the current animation set is the outermost set, this method starts the animations when the application returns to the run loop. If the current animation set is nested inside another set, this method waits until the outermost set of animations is committed, at which point it commits all of the animations together. Animations run in a separate thread to avoid blocking the application. In this way, multiple animations can be piled on top of one another. See setAnimationBeginsFromCurrentState: (page 53) for how to start animations while others are in progress. Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context:

(page 49)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

50

UIView Class Reference Class Methods

Related Sample Code

AdvancedURLConnections Handling Touches Using Responder Methods and Gesture Recognizers KeyboardAccessory LocateMe UICatalog Declared in
UIView.h

layerClass
Returns the class used to create the layer for instances of this class.
+ (Class)layerClass

Return Value The class used to create the views Core Animation layer. Discussion This method returns the CALayer class object by default. Subclasses can override this method and return a different layer class as needed. For example, if your view uses tiling to display a large scrollable area, you might want to override this method and return the CATiledLayer class. This method is called only once early in the creation of the view in order to create the corresponding layer object. Availability Available in iOS 2.0 and later. See Also
@property layer

(page 34)

Related Sample Code

GLES2Sample GLImageProcessing GLTextureAtlas PVRTextureLoader SpeakHere Declared in


UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

51

UIView Class Reference Class Methods

performSystemAnimation:onViews:options:animations:completion:
Performs a specified system-provided animation on one or more views, along with optional parallel animations that you define.
+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views

options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion

Parameters
animation

The system animation to perform; a constant from the UISystemAnimation (page 125) enum.
views

The views to perform the animations on.


options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions (page 114).
parallelAnimations

Additional animations you specify to run alongside the system animation, with the same timing and duration that the system animation defines or inherits. In your additional animations, do not modify properties of the view on which the system animation is being performed.
completion

A block object to be executed when the animation sequence ends. The single Boolean argument indicates whether or not the animations finished before the completion handler was called. If the animation duration is 0, this block is performed at the beginning of the next run-loop cycle. You can use a nil value for this parameter. Availability Available in iOS 7.0 and later. Declared in
UIView.h

performWithoutAnimation:
Disables a view transition animation.
+ (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

52

UIView Class Reference Class Methods

Parameters
actionsWithoutAnimation

The view transition code that you want to perform without animation. Availability Available in iOS 7.0 and later. See Also (page 61) + areAnimationsEnabled (page 48)
+ setAnimationsEnabled:

Declared in
UIView.h

requiresConstraintBasedLayout
Returns whether the receiver depends on the constraint-based layout system.
+ (BOOL)requiresConstraintBasedLayout

Return Value YES if the view must be in a window using constraint-based layout to function properly, NO otherwise. Discussion Custom views should override this to return YES if they can not layout correctly using autoresizing. Availability Available in iOS 6.0 and later. Declared in
UIView.h

setAnimationBeginsFromCurrentState:
Sets whether the animation should begin playing from the current state.
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState

Parameters
fromCurrentState

Specify YES if animations should begin from their currently visible state; otherwise, NO.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

53

UIView Class Reference Class Methods

Discussion If set to YES when an animation is in flight, the current view position of the in-flight animation is used as the starting state for the new animation. If set to NO, the in-flight animation ends before the new animation begins using the last view position as the starting state. This method does nothing if an animation is not in flight or invoked outside of an animation block. Use the beginAnimations:context: (page 49) class method to start and the commitAnimations (page 50) class method to end an animation block. The default value is NO. Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: (page 46) method to specify your animations and the animation options. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations + + + + + +

(page 49)

(page 50) setAnimationStartDate: (page 62) setAnimationDuration: (page 58) setAnimationDelay: (page 55) setAnimationCurve: (page 54) setAnimationRepeatCount: (page 60) setAnimationRepeatAutoreverses: (page 59)

Declared in
UIView.h

setAnimationCurve:
Sets the curve to use when animating property changes within an animation block.
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve

Discussion If you specify your animations using begin/commit set of methods, you use this method to specify the type of curve you want to use for the animation. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. And you must call this method prior to changing the animatable properties of your views. The default value is UIViewAnimationCurveEaseInOut (page 118).

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

54

UIView Class Reference Class Methods

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: (page 46) method to specify your animations and the animation curve options. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations + + + + + +

(page 49)

(page 50) setAnimationStartDate: (page 62) setAnimationDuration: (page 58) setAnimationDelay: (page 55) setAnimationRepeatCount: (page 60) setAnimationRepeatAutoreverses: (page 59) setAnimationBeginsFromCurrentState: (page 53)

Related Sample Code

AdvancedURLConnections MultipeerGroupChat Declared in


UIView.h

setAnimationDelay:
Sets the amount of time (in seconds) to wait before animating property changes within an animation block.
+ (void)setAnimationDelay:(NSTimeInterval)delay

Discussion If you specify your animations using begin/commit set of methods, you use this method to specify the amount of time to wait before starting the animations. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. And you must call this method prior to changing the animatable properties of your views. The default value is 0.0 seconds. Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: (page 46) method to specify your animations and the starting delay. Availability Available in iOS 2.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

55

UIView Class Reference Class Methods

See Also
+ beginAnimations:context: + commitAnimations + + + + + +

(page 49) (page 50) setAnimationStartDate: (page 62) setAnimationDuration: (page 58) setAnimationCurve: (page 54) setAnimationRepeatCount: (page 60) setAnimationRepeatAutoreverses: (page 59) setAnimationBeginsFromCurrentState: (page 53)

Declared in
UIView.h

setAnimationDelegate:
Sets the delegate for any animation messages.
+ (void)setAnimationDelegate:(id)delegate

Parameters
delegate

An object that defines the methods registered using the setAnimationWillStartSelector: (page 64) and setAnimationDidStopSelector: (page 57) methods. The view maintains a strong reference to this object for the duration of the animation. Discussion You can specify an animation delegate in cases where you want to receive messages when the animation starts or stops. After calling this method, you should call the setAnimationWillStartSelector: (page 64) and setAnimationDidStopSelector: (page 57) methods as needed to register appropriate selectors. By default, the animation delegate is set to nil. You primarily use this method to set the delegate for animation blocks created using the begin/commit animation methods. Calling this method from outside an animation block does nothing. Use of this method is discouraged in iOS 4.0 and later. If you are using the block-based animation methods, you can include your delegates start and end code directly inside your block. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context:

(page 49)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

56

UIView Class Reference Class Methods

+ commitAnimations

(page 50)

(page 64) + setAnimationDidStopSelector: (page 57)


+ setAnimationWillStartSelector:

Related Sample Code

AQOfflineRenderTest iPhoneMultichannelMixerTest MoveMe TheElements Declared in


UIView.h

setAnimationDidStopSelector:
Sets the message to send to the animation delegate when animation stops.
+ (void)setAnimationDidStopSelector:(SEL)selector

Parameters
selector

The message sent to the animation delegate after animations end. The default value is NULL. The selector should be of the form: - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context. Your method must take the following arguments:
animationID

An NSString containing an optional application-supplied identifier. This is the identifier that is passed to the beginAnimations:context: (page 49) method. This argument can be nil.
finished

An NSNumber object containing a Boolean value. The value is YES if the animation ran to completion before it stopped or NO if it did not.
context

An optional application-supplied context. This is the context data passed to the beginAnimations:context: (page 49) method. This argument can be nil.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

57

UIView Class Reference Class Methods

Discussion If you specify an animation delegate for a begin/commit set of animations, you use this method to specify the selector to call after the animations end. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. This selector is set to NULL by default. Note: Your stop selector is still called even if animations are disabled.

Use of this method is discouraged in iOS 4.0 and later. If you are using the block-based animation methods, you can include your delegates end code directly inside your block. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations

(page 49)

(page 50) + setAnimationDelegate: (page 56)


+ setAnimationWillStartSelector:

(page 64)

Related Sample Code

AQOfflineRenderTest iPhoneMultichannelMixerTest MoveMe TheElements Declared in


UIView.h

setAnimationDuration:
Sets the duration (measured in seconds) of the animations in an animation block.
+ (void)setAnimationDuration:(NSTimeInterval)duration

Parameters
duration

The period over which the animation occurs, measured in seconds.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

58

UIView Class Reference Class Methods

Discussion If you specify your animations using begin/commit set of methods, you use this method to specify the duration of the animations. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. And you must call this method prior to changing the animatable properties of your views. The default value is 0.2 seconds. Use of this method is discouraged in iOS 4.0 and later. Instead, you should use any of the block-based animation methods to specify your animations and their duration. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations + + + + + +

(page 49)

(page 50) setAnimationStartDate: (page 62) setAnimationDelay: (page 55) setAnimationCurve: (page 54) setAnimationRepeatCount: (page 60) setAnimationRepeatAutoreverses: (page 59) setAnimationBeginsFromCurrentState: (page 53)

Related Sample Code

KeyboardAccessory LocateMe MoveMe TheElements UICatalog Declared in


UIView.h

setAnimationRepeatAutoreverses:
Sets whether the animations within an animation block automatically reverse themselves.
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses

Parameters
repeatAutoreverses

Specify YES to enable autoreversing or NO to disable it.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

59

UIView Class Reference Class Methods

Discussion If you enable autoreversing, a single animation cycle changes the properties being animated to their new values and then back to their original values. At the end of the animations, the affected views are then updated immediately to reflect the new values. This method does nothing if called from outside of an animation block. By default, autoreversing is disabled. If you combine autoreversing with a repeat count (settable using the setAnimationRepeatCount: (page 60) method), you can create animations that shift back and forth between the old and new values the specified number of times. However, remember that the repeat count indicates the number of complete cycles. If you specify an integral value such as 2.0, the animation ends on the old value, which is followed by the view immediately updating itself to show the new value, which might be jarring. If you want the animation to end on the new value (instead of the old value), add 0.5 to the repeat count value. This adds an extra half cycle to the animation. Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: (page 46) method to specify your animations and the animation options. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations + + + + +

(page 49) (page 50) setAnimationStartDate: (page 62) setAnimationDuration: (page 58) setAnimationDelay: (page 55) setAnimationCurve: (page 54) setAnimationRepeatCount: (page 60) (page 53)

+ setAnimationBeginsFromCurrentState:

Declared in
UIView.h

setAnimationRepeatCount:
Sets the number of times animations within an animation block repeat.
+ (void)setAnimationRepeatCount:(float)repeatCount

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

60

UIView Class Reference Class Methods

Parameters
repeatCount

The number of times animations repeat. This value can be a fraction. If you specify the value 0, the animation is performed once without repeating. Discussion Use this method to specify the number of times to repeat the specified animations. This method does nothing if called from outside of an animation block. You can use this method in conjunction with either the block-based methods or the begin/commit methods for defining an animation block. If you do not explicitly set a repeat count, the animation is not repeated. If you pass the UIViewAnimationOptionRepeat (page 115) option to the animateWithDuration:delay:options:animations:completion: (page 46) method without setting an explicit repeat count, the animation repeats indefinitely. If you want the animation to repeat a finite number of times, call this method from inside your block. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations + + + +

(page 49)

(page 50) setAnimationStartDate: (page 62) setAnimationDuration: (page 58) setAnimationDelay: (page 55) setAnimationCurve: (page 54) (page 59) (page 53)

+ setAnimationRepeatAutoreverses:

+ setAnimationBeginsFromCurrentState:

Declared in
UIView.h

setAnimationsEnabled:
Sets whether animations are enabled.
+ (void)setAnimationsEnabled:(BOOL)enabled

Parameters
enabled

Specify YES to enable animations or NO to disable them.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

61

UIView Class Reference Class Methods

Discussion Animations are enabled by default. If you disable animations, code inside subsequent animation blocks is still executed but no animations actually occur. Thus, any changes you make inside an animation block are reflected immediately instead of being animated. This is true whether you use the block-based animation methods or the begin/commit animation methods. This method affects only those animations that are submitted after it is called. If you call this method while existing animations are running, those animations continue running until they reach their natural end point. Availability Available in iOS 2.0 and later. See Also (page 48) + performWithoutAnimation: (page 52)
+ areAnimationsEnabled

Declared in
UIView.h

setAnimationStartDate:
Sets the start time for the current animation block.
+ (void)setAnimationStartDate:(NSDate *)startTime

Parameters
startTime

The time to begin the animations. Discussion Call this method between the beginAnimations:context: (page 49) and commitAnimations (page 50) methods to specify the start time for that set of animations. And call this method prior to changing the animatable properties of your views. (Do not call this method in conjunction with a block-based animation.) If you do not call this method, the start time is set to the value returned by the CFAbsoluteTimeGetCurrent function, which begins the animations as soon as possible. Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead. Availability Available in iOS 2.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

62

UIView Class Reference Class Methods

See Also
+ beginAnimations:context: + commitAnimations + + + + + +

(page 49)

(page 50) setAnimationDuration: (page 58) setAnimationDelay: (page 55) setAnimationCurve: (page 54) setAnimationRepeatCount: (page 60) setAnimationRepeatAutoreverses: (page 59) setAnimationBeginsFromCurrentState: (page 53)

Declared in
UIView.h

setAnimationTransition:forView:cache:
Sets a transition to apply to a view during an animation block.
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView

*)view cache:(BOOL)cache

Parameters
transition

A transition to apply to view. Possible values are described in UIViewAnimationTransition (page 128).
view

The view to apply the transition to.


cache

If YES, the before and after images of view are rendered once and used to create the frames in the animation. Caching can improve performance but if you set this parameter to YES, you must not update the view or its subviews during the transition. Updating the view and its subviews may interfere with the caching behaviors and cause the view contents to be rendered incorrectly (or in the wrong location) during the animation. You must wait until the transition ends to update the view. If NO, the view and its contents must be updated for each frame of the transition animation, which may noticeably affect the frame rate. Discussion If you want to change the appearance of a view during a transitionfor example, flip from one view to anotherthen use a container view, an instance of UIView, as follows:
1. 2.

Begin an animation block. Set the transition on the container view.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

63

UIView Class Reference Class Methods

3. 4. 5.

Remove the subview from the container view. Add the new subview to the container view. Commit the animation block.

Use of this method is discouraged in iOS 4.0 and later. You should use the transitionWithView:duration:options:animations:completion: (page 67) method to perform transitions instead. Availability Available in iOS 2.0 and later.
Related Sample Code

AQOfflineRenderTest Breadcrumb iPhoneMultichannelMixerTest TheElements UICatalog Declared in


UIView.h

setAnimationWillStartSelector:
Sets the message to send to the animation delegate when the animation starts.
+ (void)setAnimationWillStartSelector:(SEL)selector

Parameters
selector

The message to send to the animation delegate before animations start. The default value is NULL. This selector should be of the form: - (void)animationDidStart:(NSString *)animationID context:(void *)context. Your method must take the following arguments:
animationID

An NSString containing an optional application-supplied identifier. This is the identifier string that is passed to the beginAnimations:context: (page 49) method. This argument can be nil.
context

An optional application-supplied context. This is the context data passed to the beginAnimations:context: (page 49) method. This argument can be nil.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

64

UIView Class Reference Class Methods

Discussion If you specify an animation delegate for a begin/commit set of animations, you use this method to specify the selector to call before the animations begin. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. This selector is set to NULL by default. Note: Your start selector is not called if animations are disabled.

Use of this method is discouraged in iOS 4.0 and later. If you are using the block-based animation methods, you can include your delegates start code directly inside your block. Availability Available in iOS 2.0 and later. See Also
+ beginAnimations:context: + commitAnimations

(page 49)

(page 50) + setAnimationDelegate: (page 56) + setAnimationDidStopSelector: (page 57) Declared in


UIView.h

transitionFromView:toView:duration:options:completion:
Creates a transition animation between the specified views using the given parameters.
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView

duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

Parameters
fromView

The starting view for the transition. By default, this view is removed from its superview as part of the transition.
toView

The ending view for the transition. By default, this view is added to the superview of fromView as part of the transition.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

65

UIView Class Reference Class Methods

duration

The duration of the transition animation, measured in seconds. If you specify a negative value or 0, the transition is made without animations.
options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions (page 114).
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL. Discussion This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews (page 116) option in the options parameter to simply hide or show them. This method modifies the views in their view hierarchy only. It does not modify your applications view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change. The view transition starts immediately unless another animation is already in-flight, in which case it starts immediately after the current animation finishes. During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction (page 115) constant in the options parameter. Availability Available in iOS 4.0 and later.
Related Sample Code

PrefsInCloud ViewTransitions Declared in


UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

66

UIView Class Reference Class Methods

transitionWithView:duration:options:animations:completion:
Creates a transition animation for the specified container view.
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration

options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Parameters
view

The container view that performs the transition.


duration

The duration of the transition animation, measured in seconds. If you specify a negative value or 0, the transition is made without animations.
options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see UIViewAnimationOptions (page 114).
animations

A block object that contains the changes you want to make to the specified view. This block takes no parameters and has no return value. This parameter must not be NULL.
completion

A block object to be executed when the animation sequence ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished before the completion handler was called. If the duration of the animation is 0, this block is performed at the beginning of the next run loop cycle. This parameter may be NULL. Discussion This method applies a transition to the specified view so that you can make state changes to it. The block you specify in the animations parameter contains whatever state changes you want to make. You can use this block to add, remove, show, or hide subviews of the specified view. If you want to incorporate other animatable changes, you must include the UIViewAnimationOptionAllowAnimatedContent (page 116) key in the options parameter. The following code creates a flip transition for the specified container view. At the appropriate point in the transition, one subview is removed and another is added to the container view. This makes it look as if a new view was flipped into place with the new subview, but really it is just the same view animated back into place with a new configuration.
[UIView transitionWithView:containerView duration:0.2

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

67

UIView Class Reference Instance Methods

options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; } completion:NULL];

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction (page 115) constant in the options parameter. Availability Available in iOS 4.0 and later.
Related Sample Code

AppPrefs

Declared in
UIView.h

Instance Methods
addConstraint:
Adds a constraint on the layout of the receiving view or its subviews.
- (void)addConstraint:(NSLayoutConstraint *)constraint

Parameters
constraint

The constraint to be added to the view. The constraint may only reference the view itself or its subviews. Discussion The constraint must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating the constraint is the coordinate system of the view that holds the constraint. Availability Available in iOS 6.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

68

UIView Class Reference Instance Methods

Declared in
UIView.h

addConstraints:
Adds multiple constraints on the layout of the receiving view or its subviews.
- (void)addConstraints:(NSArray *)constraints

Parameters
constraints

An array of constraints to be added to the view. All constraints may only reference the view itself or its subviews. Discussion All constraints must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating each constraint is the coordinate system of the view that holds the constraint. Availability Available in iOS 6.0 and later.
Related Sample Code

PrefsInCloud ViewTransitions Declared in


UIView.h

addGestureRecognizer:
Attaches a gesture recognizer to the view.
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

Parameters
gestureRecognizer

An object whose class descends from the UIGestureRecognizer class. This parameter must not be nil.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

69

UIView Class Reference Instance Methods

Discussion Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesture recognizer. Availability Available in iOS 3.2 and later. See Also
removeGestureRecognizer:

(page 97) @property gestureRecognizers (page 32)

Related Sample Code

AVPlayerDemo DocInteraction PageControl StitchedStreamPlayer Declared in


UIView.h

addMotionEffect:
Begins applying a motion effect to the view.
- (void)addMotionEffect:(UIMotionEffect *)effect

Parameters
effect

The motion effect. Discussion The system animates the transition to the motion effect's values using the present UIView animation context. The motion effects keyPath/value pairs are applied to the views presentation layer. Availability Available in iOS 7.0 and later. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

70

UIView Class Reference Instance Methods

addSubview:
Adds a view to the end of the receivers list of subviews.
- (void)addSubview:(UIView *)view

Parameters
view

The view to be added. After being added, this view appears on top of any other subviews. Discussion This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview. Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview. Availability Available in iOS 2.0 and later. See Also (page 91) insertSubview:aboveSubview: (page 90) insertSubview:belowSubview: (page 91)
insertSubview:atIndex: exchangeSubviewAtIndex:withSubviewAtIndex:

(page 85)

Related Sample Code

GenericKeychain GeocoderDemo iAdSuite iPhoneCoreDataRecipes UICatalog Declared in


UIView.h

alignmentRectForFrame:
Returns the views alignment rectangle for a given frame.
- (CGRect)alignmentRectForFrame:(CGRect)frame

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

71

UIView Class Reference Instance Methods

Parameters
frame

The frame whose corresponding alignment rectangle is desired. Return Value The alignment rectangle for the specified frame. Discussion The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections. The default implementation returns the views frame modified by the views alignmentRectInsets (page 72). Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can override alignmentRectForFrame: and frameForAlignmentRect: (page 86) to describe the location of their content. These two methods must always be inverses of each other. Availability Available in iOS 6.0 and later. Declared in
UIView.h

alignmentRectInsets
Returns the insets from the views frame that define its alignment rectangle.
- (UIEdgeInsets)alignmentRectInsets

Return Value The insets from the views frame that define its alignment rectangle. Discussion The default implementation of this method returns an NSEdgeInsets structure with zero values. Custom views that draw ornamentation around their content should override this method to return insets that align with the edges of the content, excluding the ornamentation. This allows the constraint-based layout system to align views based on their content, rather than just their frame. Custom views whose content location cant be expressed by a simple set of insets should override alignmentRectForFrame: (page 71) and frameForAlignmentRect: (page 86) to describe their custom transform between alignment rectangle and frame.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

72

UIView Class Reference Instance Methods

Availability Available in iOS 6.0 and later. Declared in


UIView.h

bringSubviewToFront:
Moves the specified subview so that it appears on top of its siblings.
- (void)bringSubviewToFront:(UIView *)view

Parameters
view

The subview to move to the front. Discussion This method moves the specified view to the end of the array of views in the subviews (page 37) property. Availability Available in iOS 2.0 and later. See Also
sendSubviewToBack:

(page 100)

Declared in
UIView.h

constraints
Returns the constraints held by the view.
- (NSArray *)constraints

Return Value The constraints held by the view. Availability Available in iOS 6.0 and later. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

73

UIView Class Reference Instance Methods

constraintsAffectingLayoutForAxis:
Returns the constraints impacting the layout of the view for a given axis.
- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis

Parameters
axis

The axis for which the constraints should be found. Return Value The constraints impacting the layout of the view for the specified axis. Discussion The returned set of constraints may not all include the view explicitly. Constraints that impact the location of the view implicitly may also be included. While this provides a good starting point for debugging, there is no guarantee that the returned set of constraints will include all of the constraints that have an impact on the views layout in the given orientation. This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation. Availability Available in iOS 6.0 and later. Declared in
UIView.h

contentCompressionResistancePriorityForAxis:
Returns the priority with which a view resists being made smaller than its intrinsic size.
(UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis

Parameters
axis

The axis of the view that might be reduced. Return Value The priority with which the view should resist being compressed from its intrinsic size on the specified axis.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

74

UIView Class Reference Instance Methods

Discussion The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be smaller than their intrinsic size. Subclasses should not override this method. Instead, custom views should set default values for their content on creation, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. Availability Available in iOS 6.0 and later. See Also
setContentCompressionResistancePriority:forAxis:

(page 100)

Declared in
UIView.h

contentHuggingPriorityForAxis:
Returns the priority with which a view resists being made larger than its intrinsic size.
- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis

Parameters
axis

The axis of the view that might be enlarged. Return Value The priority with which the view should resist being enlarged from its intrinsic size on the specified axis. Discussion The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be larger than their intrinsic size. Availability Available in iOS 6.0 and later. See Also
setContentHuggingPriority:forAxis:

(page 101)

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

75

UIView Class Reference Instance Methods

convertPoint:fromView:
Converts a point from the coordinate system of a given view to that of the receiver.
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view

Parameters
point

A point specified in the local coordinate system (bounds) of view.


view

The view with point in its coordinate system. If view is nil, this method instead converts from window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object. Return Value The point converted to the local coordinate system (bounds) of the receiver. Availability Available in iOS 2.0 and later. See Also (page 76) convertRect:toView: (page 78) convertRect:fromView: (page 77)
convertPoint:toView:

Declared in
UIView.h

convertPoint:toView:
Converts a point from the receivers coordinate system to that of the specified view.
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view

Parameters
point

A point specified in the local coordinate system (bounds) of the receiver.


view

The view into whose coordinate system point is to be converted. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

76

UIView Class Reference Instance Methods

Return Value The point converted to the coordinate system of view. Availability Available in iOS 2.0 and later. See Also (page 76) convertRect:toView: (page 78) convertRect:fromView: (page 77)
convertPoint:fromView:

Related Sample Code

Handling Touches Using Responder Methods and Gesture Recognizers Declared in


UIView.h

convertRect:fromView:
Converts a rectangle from the coordinate system of another view to that of the receiver.
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view

Parameters
rect

A rectangle specified in the local coordinate system (bounds) of view.


view

The view with rect in its coordinate system. If view is nil, this method instead converts from window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object. Return Value The converted rectangle. Availability Available in iOS 2.0 and later. See Also (page 76) convertPoint:fromView: (page 76) convertRect:toView: (page 78)
convertPoint:toView:

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

77

UIView Class Reference Instance Methods

convertRect:toView:
Converts a rectangle from the receivers coordinate system to that of another view.
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view

Parameters
rect

A rectangle specified in the local coordinate system (bounds) of the receiver.


view

The view that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object. Return Value The converted rectangle. Availability Available in iOS 2.0 and later. See Also (page 76) convertPoint:fromView: (page 76) convertRect:fromView: (page 77)
convertPoint:toView:

Declared in
UIView.h

decodeRestorableStateWithCoder:
Decodes and restores state-related information for the view.
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder

Parameters
coder

The coder object to use to decode the state of the view.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

78

UIView Class Reference Instance Methods

Discussion If your app supports state restoration, you should override this method for any views for which you also overrode the encodeRestorableStateWithCoder: method. Your implementation of this method should use any saved state information to restore the view to its previous configuration. If your encodeRestorableStateWithCoder: method called super, this method should similarly call super at some point in its implementation. Availability Available in iOS 6.0 and later. See Also
encodeRestorableStateWithCoder:

(page 83)

Declared in
UIView.h

didAddSubview:
Tells the view that a subview was added.
- (void)didAddSubview:(UIView *)subview

Parameters
subview

The view that was added as a subview. Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions when subviews are added. This method is called in response to adding a subview using any of the relevant view methods. Availability Available in iOS 2.0 and later. See Also
willRemoveSubview:

(page 114) addSubview: (page 71) insertSubview:atIndex: (page 91) insertSubview:aboveSubview: (page 90) insertSubview:belowSubview: (page 91)

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

79

UIView Class Reference Instance Methods

didMoveToSuperview
Tells the view that its superview changed.
- (void)didMoveToSuperview

Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes. Availability Available in iOS 2.0 and later. See Also
willMoveToSuperview:

(page 112)

Declared in
UIView.h

didMoveToWindow
Tells the view that its window object changed.
- (void)didMoveToWindow

Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes. The window (page 41) property may be nil by the time that this method is called, indicating that the receiver does not currently reside in any window. This occurs when the receiver has just been removed from its superview or when the receiver has just been added to a superview that is not attached to a window. Overrides of this method may choose to ignore such cases if they are not of interest. Availability Available in iOS 2.0 and later. See Also
willMoveToWindow:

(page 113)

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

80

UIView Class Reference Instance Methods

drawRect:
Draws the receivers image within the passed-in rectangle.
- (void)drawRect:(CGRect)rect

Parameters
rect

The portion of the views bounds that needs to be updated. The first time your view is drawn, this rectangle is typically the entire visible bounds of your view. However, during subsequent drawing operations, the rectangle may specify only part of your view. Discussion The default implementation of this method does nothing. Subclasses that use technologies such as Core Graphics and UIKit to draw their views content should override this method and implement their drawing code there. You do not need to override this method if your view sets its content in other ways. For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object. By the time this method is called, UIKit has configured the drawing environment appropriately for your view and you can simply call whatever drawing methods and functions you need to render your content. Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that context so that its origin matches the origin of your views bounds rectangle. You can get a reference to the graphics context using the UIGraphicsGetCurrentContext function, but do not establish a strong reference to the graphics context because it can change between calls to the drawRect: method. Similarly, if you draw using OpenGL ES and the GLKView class, GLKit configures the underlying OpenGL ES context appropriately for your view before calling this method (or the glkView:drawInRect: method of your GLKView delegate), so you can simply issue whatever OpenGL ES commands you need to render your content. For more information about how to draw using OpenGL ES, see OpenGL ES Programming Guide for iOS . You should limit any drawing to the rectangle specified in the rect parameter. In addition, if the opaque (page 35) property of your view is set to YES, your drawRect: method must totally fill the specified rectangle with opaque content. If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation. This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay (page 102) or setNeedsDisplayInRect: (page 103) method instead.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

81

UIView Class Reference Instance Methods

Availability Available in iOS 2.0 and later. See Also (page 102) setNeedsDisplayInRect: (page 103) @property contentMode (page 29)
setNeedsDisplay

Declared in
UIView.h

drawRect:forViewPrintFormatter:
Implemented to draw the views content for printing.
- (void)drawRect:(CGRect)area forViewPrintFormatter:(UIViewPrintFormatter *)formatter

Parameters
area

A rectangle that defines the area for drawing printable content.


formatter

An instance of UIViewPrintFormatter obtained by calling the viewPrintFormatter (page 111) method. Discussion You implement this method if you want a views printed content to appear differently than its displayed content. If you add a view print formatter to a print job but do not implement this method, the views drawRect: (page 81) method is called to provide the content for printing. For more information about how to implement a custom drawing routine for printed content, see Drawing and Printing Guide for iOS . Availability Available in iOS 4.2 and later. Declared in
UIPrintFormatter.h

drawViewHierarchyInRect:afterScreenUpdates:
Renders a snapshot of the complete view hierarchy as visible onscreen into the current context.
- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

82

UIView Class Reference Instance Methods

Parameters
rect

A rectangle specified in the local coordinate system (bounds) of the view.


afterUpdates

A Boolean value that indicates whether the snapshot should be rendered after recent changes have been incorporated. Specify the value NO if you want to render a snapshot in the view hierarchys current state, which might not include recent changes. Return Value Returns YES if the snapshot is complete, or NO if the snapshot is missing image data for any view in the hierarchy. Discussion Use this method when you want to apply a graphical effect, such as a blur, to a view snapshot. This method is not as fast as the snapshotViewAfterScreenUpdates: (page 107) method. Availability Available in iOS 7.0 and later. See Also
snapshotViewAfterScreenUpdates:

(page 107)

Declared in
UIView.h

encodeRestorableStateWithCoder:
Encodes state-related information for the view.
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder

Parameters
coder

The coder object to use to encode the state of the view. Discussion If your app supports state preservation, you can override this method for any views that have state information that should be saved between launches of your app. You should save only the data required to return the view to its current configuration. Do not save the view object itself and do not save any data that could be determined by other means at launch time.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

83

UIView Class Reference Instance Methods

Few views should need to save state information. Most views should just be configured using the data from their view controller. However, this method is available for those views that have user-configurable state that would be otherwise lost between app launches. Your implementation of this method can encode other restorable view and view controller objects that it needs to reference. Encoding a restorable view or view controller writes that objects restoration identifier to the coder. (That identifier is used during the decode process to locate the new version of the object.) If the view or view controller defines its own own version of this method, that method is also called at some point so that the object can encode its own state. Apart from views and view controllers, other objects follow the normal serialization process and must adopt the NSCoding protocol before they can be encoded. Encoding such objects embeds the objects contents in the archive directly. During the decode process, a new object is created and initialized with the data from the archive. It is recommended that you call super at some point during your implementation to give parent classes an opportunity to save their state information. Availability Available in iOS 6.0 and later. See Also
decodeRestorableStateWithCoder:

(page 78)

Declared in
UIView.h

endEditing:
Causes the view (or one of its embedded text fields) to resign the first responder status.
- (BOOL)endEditing:(BOOL)force

Parameters
force

Specify YES to force the first responder to resign, regardless of whether it wants to do so. Return Value YES if the view resigned the first responder status or NO if it did not.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

84

UIView Class Reference Instance Methods

Discussion This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign. Availability Available in iOS 2.0 and later.
Related Sample Code

MultipeerGroupChat Simple Core Data Relationships Declared in


UITextField.h

exchangeSubviewAtIndex:withSubviewAtIndex:
Exchanges the subviews at the specified indices.
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2

Parameters
index1

The index of the first subview in the receiver.


index2

The index of the second subview in the receiver. Discussion Each index represents the position of the corresponding view in the array in the subviews (page 37) property. Subview indices start at 0 and cannot be greater than the number of subviews. This method does not change the superview of either view but simply swaps their positions in the subviews (page 37) array. Availability Available in iOS 2.0 and later. See Also
addSubview:

(page 71)

(page 91) insertSubview:aboveSubview: (page 90) insertSubview:belowSubview: (page 91)


insertSubview:atIndex:

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

85

UIView Class Reference Instance Methods

exerciseAmbiguityInLayout
Randomly changes the frame of a view with an ambiguous layout between the different valid values.
- (void)exerciseAmbiguityInLayout

Discussion This method randomly changes the frame of a view with an ambiguous layout between its different valid values, causing the view to move in the interface. This makes it easy to visually identify what the valid frames are and may enable the developer to discern what constraints need to be added to the layout to fully specify a location for the view. This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation. Availability Available in iOS 6.0 and later. Declared in
UIView.h

frameForAlignmentRect:
Returns the views frame for a given alignment rectangle.
- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect

Parameters
alignmentRect

The alignment rectangle whose corresponding frame is desired. Return Value The frame for the specified alignment rectangle Discussion The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

86

UIView Class Reference Instance Methods

The default implementation returns alignmentRect modified by the views alignmentRectInsets (page 72). Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can override alignmentRectForFrame: (page 71) and frameForAlignmentRect: to describe the location of their content. These two methods must always be inverses of each other. Availability Available in iOS 6.0 and later. Declared in
UIView.h

gestureRecognizerShouldBegin:
Asks the view if the gesture recognizer should be allowed to continue tracking touch events.
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

Parameters
gestureRecognizer

The gesture recognizer that is attempting to transition out of the UIGestureRecognizerStatePossible state. Return Value YES if the gesture recognizer should continue tracking touch events and use them to trigger a gesture or NO if it should transition to the UIGestureRecognizerStateFailed state. Discussion Subclasses may override this method and use it to prevent the recognition of particular gestures. For example, the UISlider class uses this method to prevent swipes parallel to the sliders travel direction and that start in the thumb. At the time this method is called, the gesture recognizer is in the UIGestureRecognizerStatePossible state and thinks it has the events needed to move to the UIGestureRecognizerStateBegan state. The default implementation of this method returns YES. Availability Available in iOS 6.0 and later. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

87

UIView Class Reference Instance Methods

hasAmbiguousLayout
Returns whether the constraints impacting the layout of the view incompletely specify the location of the view.
- (BOOL)hasAmbiguousLayout

Return Value YES if the views location is incompletely specified, NO otherwise. Discussion This method checks to see if there is any other frame the view could have that would also satisfy the constraints on the view. This is an expensive operation and is not run as part of the normal layout process, but can be useful when debugging whether a given interface has been specified with a sufficient number of constraints to ensure consistent layout. This method should only be used for debugging constraint-based layout. No application should ship with calls to this method as part of its operation. Availability Available in iOS 6.0 and later. Declared in
UIView.h

hitTest:withEvent:
Returns the farthest descendant of the receiver in the view hierarchy (including itself) that contains a specified point.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

Parameters
point

A point specified in the receivers local coordinate system (bounds).


event

The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify nil. Return Value The view object that is the farthest descendent the current view and contains point. Returns nil if the point lies completely outside the receivers view hierarchy.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

88

UIView Class Reference Instance Methods

Discussion This method traverses the view hierarchy by calling the pointInside:withEvent: (page 95) method of each subview to determine which subview should receive a touch event. If pointInside:withEvent: (page 95) returns YES, then the subviews hierarchy is similarly traversed until the frontmost view containing the specified point is found. If a view does not contain the point, its branch of the view hierarchy is ignored. You rarely need to call this method yourself, but you might override it to hide touch events from subviews. This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the views content into account when determining a hit. Thus, a view can still be returned even if the specified point is in a transparent portion of that views content. Points that lie outside the receivers bounds are never reported as hits, even if they actually lie within one of the receivers subviews. This can occur if the current views clipsToBounds (page 29) property is set to NO and the affected subview extends beyond the views bounds. Availability Available in iOS 2.0 and later. See Also
pointInside:withEvent:

(page 95)

Declared in
UIView.h

initWithFrame:
Initializes and returns a newly allocated view object with the specified frame rectangle.
- (id)initWithFrame:(CGRect)aRect

Parameters
aRect

The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center (page 27) and bounds (page 26) properties accordingly. Return Value An initialized view object or nil if the object couldn't be created.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

89

UIView Class Reference Instance Methods

Discussion The new view object must be inserted into the view hierarchy of a window before it can be used. If you create a view object programmatically, this method is the designated initializer for the UIView class. Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation. If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file. For detailed information about how views are loaded from a nib file, see Resource Programming Guide . Availability Available in iOS 2.0 and later. Declared in
UIView.h

insertSubview:aboveSubview:
Inserts a view above another view in the view hierarchy.
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview

Parameters
view

The view to insert. Its removed from its superview if its not a sibling of siblingSubview.
siblingSubview

The sibling view that will be behind the inserted view. Discussion This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview. Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview. Availability Available in iOS 2.0 and later. See Also
addSubview:

(page 71) (page 91)

insertSubview:atIndex:

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

90

UIView Class Reference Instance Methods

insertSubview:belowSubview:

(page 91) (page 85)

exchangeSubviewAtIndex:withSubviewAtIndex:

Declared in
UIView.h

insertSubview:atIndex:
Inserts a subview at the specified index.
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index

Parameters
view

The view to insert. This value cannot be nil.


index

The index in the array of the subviews (page 37) property at which to insert the view. Subview indices start at 0 and cannot be greater than the number of subviews. Discussion This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview. Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview. Availability Available in iOS 2.0 and later. See Also
addSubview:

(page 71)

(page 90) insertSubview:belowSubview: (page 91)


insertSubview:aboveSubview: exchangeSubviewAtIndex:withSubviewAtIndex:

(page 85)

Declared in
UIView.h

insertSubview:belowSubview:
Inserts a view below another view in the view hierarchy.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

91

UIView Class Reference Instance Methods

- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview

Parameters
view

The view to insert below another view. Its removed from its superview if its not a sibling of siblingSubview.
siblingSubview

The sibling view that will be above the inserted view. Discussion This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview. Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview. Availability Available in iOS 2.0 and later. See Also
addSubview:

(page 71)

(page 91) insertSubview:aboveSubview: (page 90)


insertSubview:atIndex: exchangeSubviewAtIndex:withSubviewAtIndex:

(page 85)

Declared in
UIView.h

intrinsicContentSize
Returns the natural size for the receiving view, considering only properties of the view itself.
- (CGSize)intrinsicContentSize

Return Value A size indicating the natural size for the receiving view based on its intrinsic properties. Discussion Custom views typically have content that they display of which the layout system is unaware. Overriding this method allows a custom view to communicate to the layout system what size it would like to be based on its content. This intrinsic size must be independent of the content frame, because theres no way to dynamically communicate a changed width to the layout system based on a changed height, for example.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

92

UIView Class Reference Instance Methods

If a custom view has no intrinsic size for a given dimension, it can return UIViewNoIntrinsicMetric (page 126) for that dimension. Availability Available in iOS 6.0 and later. Declared in
UIView.h

invalidateIntrinsicContentSize
Invalidates the views intrinsic content size.
- (void)invalidateIntrinsicContentSize

Discussion Call this when something changes in your custom view that invalidates its intrinsic content size. This allows the constraint-based layout system to take the new intrinsic content size into account in its next layout pass. Availability Available in iOS 6.0 and later. Declared in
UIView.h

isDescendantOfView:
Returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.
- (BOOL)isDescendantOfView:(UIView *)view

Parameters
view

The view to test against the receivers view hierarchy. Return Value YES if the receiver is an immediate or distant subview of view or if view is the receiver itself; otherwise NO. Availability Available in iOS 2.0 and later. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

93

UIView Class Reference Instance Methods

layoutIfNeeded
Lays out the subviews immediately.
- (void)layoutIfNeeded

Discussion Use this method to force the layout of subviews before drawing. Using the view that receives the message as the root view, this method lays out the view subtree starting at the root. Availability Available in iOS 2.0 and later. See Also (page 104) layoutSubviews (page 94)
setNeedsLayout

Declared in
UIView.h

layoutSubviews
Lays out subviews.
- (void)layoutSubviews

Discussion The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews. Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly. You should not call this method directly. If you want to force a layout update, call the setNeedsLayout (page 104) method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded (page 94) method. Availability Available in iOS 2.0 and later. See Also
setNeedsLayout

(page 104)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

94

UIView Class Reference Instance Methods

layoutIfNeeded

(page 94)

Related Sample Code

GLImageProcessing iPhoneCoreDataRecipes MVCNetworking SpeakHere ZoomingPDFViewer Declared in


UIView.h

needsUpdateConstraints
Returns whether the views constraints need updating.
- (BOOL)needsUpdateConstraints

Return Value YES if the views constraints need updating, NO otherwise. Discussion The constraint-based layout system uses the return value of this method to determine whether it needs to call updateConstraints (page 110) on your view as part of its normal layout pass. Availability Available in iOS 6.0 and later. See Also
setNeedsUpdateConstraints

(page 104)

Declared in
UIView.h

pointInside:withEvent:
Returns a Boolean value indicating whether the receiver contains the specified point.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

Parameters
point

A point that is in the receivers local coordinate system (bounds).

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

95

UIView Class Reference Instance Methods

event

The event that warranted a call to this method. If you are calling this method from outside your event-handling code, you may specify nil. Return Value YES if point is inside the receivers bounds; otherwise, NO. Availability Available in iOS 2.0 and later. See Also
hitTest:withEvent:

(page 88)

Declared in
UIView.h

removeConstraint:
Removes the specified constraint from the view.
- (void)removeConstraint:(NSLayoutConstraint *)constraint

Parameters
constraint

The constraint to remove. Removing a constraint not held by the view has no effect. Availability Available in iOS 6.0 and later. Declared in
UIView.h

removeConstraints:
Removes the specified constraints from the view.
- (void)removeConstraints:(NSArray *)constraints

Parameters
constraints

The constraints to remove.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

96

UIView Class Reference Instance Methods

Availability Available in iOS 6.0 and later. Declared in


UIView.h

removeFromSuperview
Unlinks the view from its superview and its window, and removes it from the responder chain.
- (void)removeFromSuperview

Discussion If the views superview is not nil, the superview releases the view. Calling this method removes any constraints that refer to the view you are removing, or that refer to any view in the subtree of the view you are removing. Important: Never call this method from inside your views drawRect: (page 81) method. Availability Available in iOS 2.0 and later. See Also (page 37) @property subviews (page 37)
@property superview

Related Sample Code

iPhoneCoreDataRecipes StreetScroller UICatalog ViewTransitions ZoomingPDFViewer Declared in


UIView.h

removeGestureRecognizer:
Detaches a gesture recognizer from the receiving view.
- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

97

UIView Class Reference Instance Methods

Parameters
gestureRecognizer

An object whose class descends from the UIGestureRecognizer class. Discussion This method releases gestureRecognizer in addition to detaching it from the view. Availability Available in iOS 3.2 and later. See Also
addGestureRecognizer:

(page 69) @property gestureRecognizers (page 32)

Declared in
UIView.h

removeMotionEffect:
Stops applying a motion effect to the view.
- (void)removeMotionEffect:(UIMotionEffect *)effect

Parameters
effect

The motion effect. Discussion Any affected presentation values animate to their post-removal values using the present UIView animation context. Availability Available in iOS 7.0 and later. Declared in
UIView.h

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:
Returns a snapshot view based on the specified contents of the current view, with stretchable insets.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

98

UIView Class Reference Instance Methods

- (UIView *)resizableSnapshotViewFromRect:(CGRect)rect

afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets

Parameters
rect

The portion of the view that you want to capture. The rectangle must be in the bounds coordinate space of the current view.
afterUpdates

A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value NO if you want to capture the screen in its current state, which might not include recent changes.
capInsets

The edge insets that define the stretchable portion of the returned views content. You can specify UIEdgeInsetsZero if you do not want the contents of the returned view to have a stretchable area. Return Value A new view object containing a snapshot of the current views rendered contents. Discussion This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view with stretchable insets. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself. Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot views layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content. You can call this method on a previously generated snapshot to obtain a new snapshot. For example, you could do so after you change properties of a previous snapshot (such as its alpha value) and want a new snapshot that includes those changes. If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: (page 82) method instead. If you specify nonzero edge insets in the capInsets parameter, those values determine the returned snapshots stretchable content area.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

99

UIView Class Reference Instance Methods

Availability Available in iOS 7.0 and later. See Also


drawViewHierarchyInRect:afterScreenUpdates: @property contentStretch

(page 82) (page 98)

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

(page 130)

Declared in
UIView.h

sendSubviewToBack:
Moves the specified subview so that it appears behind its siblings.
- (void)sendSubviewToBack:(UIView *)view

Parameters
view

The subview to move to the back. Discussion This method moves the specified view to the beginning of the array of views in the subviews (page 37) property. Availability Available in iOS 2.0 and later. See Also
bringSubviewToFront:

(page 73)

Related Sample Code

ZoomingPDFViewer Declared in
UIView.h

setContentCompressionResistancePriority:forAxis:
Sets the priority with which a view resists being made smaller than its intrinsic size.
- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority

forAxis:(UILayoutConstraintAxis)axis

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

100

UIView Class Reference Instance Methods

Parameters
priority

The new priority.


axis

The axis for which the compression resistance priority should be set. Discussion Custom views should set default values for both orientations on creation, based on their content, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface. Subclasses should not override this method. Availability Available in iOS 6.0 and later. See Also
contentCompressionResistancePriorityForAxis:

(page 74)

Declared in
UIView.h

setContentHuggingPriority:forAxis:
Sets the priority with which a view resists being made larger than its intrinsic size.
- (void)setContentHuggingPriority:(UILayoutPriority)priority

forAxis:(UILayoutConstraintAxis)axis

Parameters
priority

The new priority.


axis

The axis for which the content hugging priority should be set. Discussion Custom views should set default values for both orientations on creation, based on their content, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

101

UIView Class Reference Instance Methods

Subclasses should not override this method. Availability Available in iOS 6.0 and later. See Also
contentHuggingPriorityForAxis:

(page 75)

Declared in
UIView.h

setNeedsDisplay
Marks the receivers entire bounds rectangle as needing to be redrawn.
- (void)setNeedsDisplay

Discussion You can use this method or the setNeedsDisplayInRect: (page 103) to notify the system that your views contents need to be redrawn. This method makes a note of the request and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated. Note: If your view is backed by a CAEAGLLayer object, this method has no effect. It is intended for use only with views that use native drawing technologies (such as UIKit and Core Graphics) to render their content.

You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the views contentMode (page 29) property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed. Availability Available in iOS 2.0 and later. See Also
drawRect:

(page 81)

setNeedsDisplayInRect:

(page 103) @property contentMode (page 29)

Related Sample Code

PocketCoreImage

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

102

UIView Class Reference Instance Methods

SpeakHere Teslameter TheElements Declared in


UIView.h

setNeedsDisplayInRect:
Marks the specified rectangle of the receiver as needing to be redrawn.
- (void)setNeedsDisplayInRect:(CGRect)invalidRect

Parameters
invalidRect

The rectangular region of the receiver to mark as invalid; it should be specified in the coordinate system of the receiver. Discussion You can use this method or the setNeedsDisplay (page 102) to notify the system that your views contents need to be redrawn. This method adds the specified rectangle into the views current list of invalid rectangles and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated. Note: If your view is backed by a CAEAGLLayer object, this method has no effect. It is intended for use only with views that use native drawing technologies (such as UIKit and Core Graphics) to render their content.

You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the views contentMode (page 29) property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed. Availability Available in iOS 2.0 and later. See Also (page 81) setNeedsDisplay (page 102) @property contentMode (page 29)
drawRect:

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

103

UIView Class Reference Instance Methods

Declared in
UIView.h

setNeedsLayout
Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.
- (void)setNeedsLayout

Discussion Call this method on your applications main thread when you want to adjust the layout of a views subviews. This method makes a note of the request and returns immediately. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance. Availability Available in iOS 2.0 and later. See Also (page 94) layoutSubviews (page 94)
layoutIfNeeded

Related Sample Code

AVPlayerDemo Declared in
UIView.h

setNeedsUpdateConstraints
Controls whether the views constraints need updating.
- (void)setNeedsUpdateConstraints

Discussion When a property of your custom view changes in a way that would impact constraints, you can call this method to indicate that the constraints need to be updated at some point in the future. The system will then call updateConstraints (page 110) as part of its normal layout pass. Updating constraints all at once just before they are needed ensures that you dont needlessly recalculate constraints when multiple changes are made to your view in between layout passes.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

104

UIView Class Reference Instance Methods

Availability Available in iOS 6.0 and later. See Also


needsUpdateConstraints

(page 95)

Declared in
UIView.h

setTranslatesAutoresizingMaskIntoConstraints:
Sets whether the views autoresizing mask should be translated into constraints for the constraint-based layout system.
- (void)setTranslatesAutoresizingMaskIntoConstraints:(BOOL)flag

Parameters
flag YES if the views autoresizing mask should be translated into constraints for the constraint-based layout

system, NO otherwise. Discussion Because the autoresizing mask naturally gives rise to constraints that fully specify a views position, any view that you wish to apply more flexible constraints to must be set to ignore its autoresizing mask using this method. You should call this method yourself for programmatically created views. Views created using a tool that allows setting constraints should have this set already. Availability Available in iOS 6.0 and later. Declared in
UIView.h

sizeThatFits:
Asks the view to calculate and return the size that best fits its subviews.
- (CGSize)sizeThatFits:(CGSize)size

Parameters
size

The current size of the receiver.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

105

UIView Class Reference Instance Methods

Return Value A new size that fits the receivers subviews. Discussion The default implementation of this method returns the size portion of the views bounds rectangle. Subclasses can override this method to return a custom value based on the desired layout of any subviews. For example, a UISwitch object returns a fixed size value that represents the standard size of a switch view, and a UIImageView object returns the size of the image it is currently displaying. This method does not resize the receiver. Availability Available in iOS 2.0 and later. See Also
sizeToFit

(page 106) @property frame (page 31) @property bounds (page 26)

Declared in
UIView.h

sizeToFit
Resizes and moves the receiver view so it just encloses its subviews.
- (void)sizeToFit

Discussion Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method. You should not override this method. If you want to change the default sizing information for your view, override the sizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change. Availability Available in iOS 2.0 and later. See Also
sizeThatFits:

(page 105)

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

106

UIView Class Reference Instance Methods

Related Sample Code

BonjourWeb GeocoderDemo MapCallouts XMLPerformance Declared in


UIView.h

snapshotViewAfterScreenUpdates:
Returns a snapshot view based on the contents of the current view.
- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

Parameters
afterUpdates

A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the value NO to capture the screen in its current state, which might not include recent changes. Return Value A new view object based on a snapshot of the current views rendered contents. Discussion This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself. Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot views layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content. You can call this method on a previously generated snapshot to obtain a new snapshot. For example, you could do so after you change properties of a previous snapshot (such as its alpha value) and want a new snapshot that includes those changes. If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: (page 82) method instead.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

107

UIView Class Reference Instance Methods

Availability Available in iOS 7.0 and later. See Also


drawViewHierarchyInRect:afterScreenUpdates:

(page 82) (page 98)

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

Declared in
UIView.h

systemLayoutSizeFittingSize:
Returns the size of the view that satisfies the constraints it holds.
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize

Parameters
targetSize

Indicates whether you want the smallest or largest possible size that meets the constraints. See Fitting Size (page 125) for accepted values. Return Value The size of the view that satisfies the constraints it holds. Discussion Determines the best size of the view considering all constraints it holds and those of its subviews. Availability Available in iOS 6.0 and later. Declared in
UIView.h

tintColorDidChange
Called by the system when the tintColor property changes.
- (void)tintColorDidChange

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

108

UIView Class Reference Instance Methods

Discussion The system calls this method on a view when your code changes the value of the tintColor (page 39) property on that view. In addition, the system calls this method on a subview that inherits a changed interaction tint color. In your implementation, refresh the view rendering as needed. Availability Available in iOS 7.0 and later. See Also
@property tintColor

(page 39)

Declared in
UIView.h

translatesAutoresizingMaskIntoConstraints
Returns a Boolean value that indicates whether the views autoresizing mask is translated into constraints for the constraint-based layout system.
- (BOOL)translatesAutoresizingMaskIntoConstraints

Return Value YES if the views autoresizing mask is translated into constraints for the constraint-based layout system, NO otherwise. Discussion If this is value is YES, the views superview looks at the views autoresizing mask, produces constraints that implement it, and adds those constraints to itself (the superview). Availability Available in iOS 6.0 and later.
Related Sample Code

PrefsInCloud ViewTransitions Declared in


UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

109

UIView Class Reference Instance Methods

updateConstraints
Updates constraints for the view.
- (void)updateConstraints

Discussion Custom views that set up constraints themselves should do so by overriding this method. When your custom view notes that a change has been made to the view that invalidates one of its constraints, it should immediately remove that constraint, and then call setNeedsUpdateConstraints (page 104) to note that constraints need to be updated. Before layout is performed, your implementation of updateConstraints will be invoked, allowing you to verify that all necessary constraints for your content are in place at a time when your custom views properties are not changing. You must not invalidate any constraints as part of your constraint update phase. You also must not invoke a layout or drawing phase as part of constraint updating. Important: Call [super updateConstraints] as the final step in your implementation. Availability Available in iOS 6.0 and later. Declared in
UIView.h

updateConstraintsIfNeeded
Updates the constraints for the receiving view and its subviews.
- (void)updateConstraintsIfNeeded

Discussion Whenever a new layout pass is triggered for a view, the system invokes this method to ensure that any constraints for the view and its subviews are updated with information from the current view hierarchy and its constraints. This method is called automatically by the system, but may be invoked manually if you need to examine the most up to date constraints. Subclasses should not override this method. Availability Available in iOS 6.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

110

UIView Class Reference Instance Methods

Declared in
UIView.h

viewForBaselineLayout
Returns a view used to satisfy baseline constraints.
- (UIView *)viewForBaselineLayout

Return Value The view the constraint system should use to satisfy baseline constraints Discussion When you make a constraint on the NSLayoutAttributeBaseline of a view, the system aligns with the bottom of the view returned by this method. The default implementation returns the receiving view. If you override this method, the returned view must be a subview of the receiver. Availability Available in iOS 6.0 and later. Declared in
UIView.h

viewPrintFormatter
Returns a print formatter for the receiving view.
- (UIViewPrintFormatter *)viewPrintFormatter

Return Value A UIViewPrintFormatter object or nil if the object could not be created. If it is successfully created, the returned object is automatically associated with this view. Discussion When initiating a print job, you can call this method to obtain an appropriate view print formatter object for your view. You can use the formatter object to configure the page layout options for your view during printing. Each time you call this method, you get a unique view print formatter object. For more information about how to use print formatters to configure the printing behavior of your view, see Drawing and Printing Guide for iOS . Availability Available in iOS 4.2 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

111

UIView Class Reference Instance Methods

See Also
drawRect:forViewPrintFormatter:

(page 82)

Declared in
UIPrintFormatter.h

viewWithTag:
Returns the view whose tag matches the specified value.
- (UIView *)viewWithTag:(NSInteger)tag

Parameters
tag

The tag value to search for. Return Value The view in the receivers hierarchy whose tag property matches the value in the tag parameter. Discussion This method searches the current view and all of its subviews for the specified view. Availability Available in iOS 2.0 and later. See Also
@property tag

(page 38)

Related Sample Code

GenericKeychain UICatalog Declared in


UIView.h

willMoveToSuperview:
Tells the view that its superview is about to change to the specified superview.
- (void)willMoveToSuperview:(UIView *)newSuperview

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

112

UIView Class Reference Instance Methods

Parameters
newSuperview

A view object that will be the new superview of the receiver. This object may be nil. Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes. Availability Available in iOS 2.0 and later. See Also
didMoveToSuperview

(page 80)

Declared in
UIView.h

willMoveToWindow:
Tells the view that its window object is about to change.
- (void)willMoveToWindow:(UIWindow *)newWindow

Parameters
newWindow

The window object that will be at the root of the receiver's new view hierarchy. This parameter may be nil. Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes. Availability Available in iOS 2.0 and later. See Also
didMoveToWindow

(page 80)

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

113

UIView Class Reference Constants

willRemoveSubview:
Tells the view that a subview is about to be removed.
- (void)willRemoveSubview:(UIView *)subview

Parameters
subview

The subview that will be removed. Discussion The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever subviews are removed. This method is called when the subviews superview changes or when the subview is removed from the view hierarchy completely. Availability Available in iOS 2.0 and later. See Also (page 97) didAddSubview: (page 79)
removeFromSuperview

Declared in
UIView.h

Constants
UIViewAnimationOptions
Options for animating views using block objects.

enum { UIViewAnimationOptionLayoutSubviews UIViewAnimationOptionAllowUserInteraction UIViewAnimationOptionBeginFromCurrentState UIViewAnimationOptionRepeat UIViewAnimationOptionAutoreverse UIViewAnimationOptionOverrideInheritedDuration UIViewAnimationOptionOverrideInheritedCurve UIViewAnimationOptionAllowAnimatedContent UIViewAnimationOptionShowHideTransitionViews UIViewAnimationOptionOverrideInheritedOptions

= = = = = = = = = =

1 1 1 1 1 1 1 1 1 1

<< << << << << << << << << <<

0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

114

UIView Class Reference Constants

UIViewAnimationOptionCurveEaseInOut UIViewAnimationOptionCurveEaseIn UIViewAnimationOptionCurveEaseOut UIViewAnimationOptionCurveLinear UIViewAnimationOptionTransitionNone UIViewAnimationOptionTransitionFlipFromLeft UIViewAnimationOptionTransitionFlipFromRight UIViewAnimationOptionTransitionCurlUp UIViewAnimationOptionTransitionCurlDown UIViewAnimationOptionTransitionCrossDissolve UIViewAnimationOptionTransitionFlipFromTop UIViewAnimationOptionTransitionFlipFromBottom }; typedef NSUInteger UIViewAnimationOptions;

= = = = = = = = = = = =

0 1 2 3 0 1 2 3 4 5 6 7

<< << << << << << << << << << << <<

16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20, 20,

Constants
UIViewAnimationOptionLayoutSubviews

Lay out subviews at commit time so that they are animated along with their parent. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionAllowUserInteraction

Allow the user to interact with views while they are being animated. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionBeginFromCurrentState

Start the animation from the current setting associated with an already in-flight animation. If this key is not present, any in-flight animations are allowed to finish before the new animation is started. If another animation is not in flight, this key has no effect. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionRepeat

Repeat the animation indefinitely. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionAutoreverse

Run the animation backwards and forwards. Must be combined with the UIViewAnimationOptionRepeat option. Available in iOS 4.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

115

UIView Class Reference Constants

UIViewAnimationOptionOverrideInheritedDuration

Force the animation to use the original duration value specified when the animation was submitted. If this key is not present, the animation inherits the remaining duration of the in-flight animation, if any. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionOverrideInheritedCurve

Force the animation to use the original curve value specified when the animation was submitted. If this key is not present, the animation inherits the curve of the in-flight animation, if any. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionAllowAnimatedContent

Animate the views by changing the property values dynamically and redrawing the view. If this key is not present, the views are animated using a snapshot image. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionShowHideTransitionViews

When present, this key causes views to be hidden or shown (instead of removed or added) when performing a view transition. Both views must already be present in the parent views hierarchy when using this key. If this key is not present, the to-view in a transition is added to, and the from-view is removed from, the parent views list of subviews. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionOverrideInheritedOptions

The option to not inherit the animation type or any options. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewAnimationOptionCurveEaseInOut

An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionCurveEaseIn

An ease-in curve causes the animation to begin slowly, and then speed up as it progresses. Available in iOS 4.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

116

UIView Class Reference Constants

UIViewAnimationOptionCurveEaseOut

An ease-out curve causes the animation to begin quickly, and then slow as it completes. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionCurveLinear

A linear animation curve causes an animation to occur evenly over its duration. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionNone

No transition is specified. Available in iOS 4.0 and later. Declared in UIView.h.


UIViewAnimationOptionTransitionFlipFromLeft

A transition that flips a view around its vertical axis from left to right. The left side of the view moves toward the front and right side toward the back. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionFlipFromRight

A transition that flips a view around its vertical axis from right to left. The right side of the view moves toward the front and left side toward the back. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionCurlUp

A transition that curls a view up from the bottom. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionCurlDown

A transition that curls a view down from the top. Available in iOS 4.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionCrossDissolve

A transition that dissolves from one view to the next. Available in iOS 5.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

117

UIView Class Reference Constants

UIViewAnimationOptionTransitionFlipFromTop

A transition that flips a view around its horizontal axis from top to bottom. The top side of the view moves toward the front and the bottom side toward the back. Available in iOS 5.0 and later. Declared in UIView.h.
UIViewAnimationOptionTransitionFlipFromBottom

A transition that flips a view around its horizontal axis from bottom to top. The bottom side of the view moves toward the front and the top side toward the back. Available in iOS 5.0 and later. Declared in UIView.h. Availability Available in iOS 4.0 and later. Declared in
UIView.h

UIViewAnimationCurve
Specifies the supported animation curves.

typedef enum { UIViewAnimationCurveEaseInOut, UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveLinear } UIViewAnimationCurve;

Constants
UIViewAnimationCurveEaseInOut

An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationCurveEaseIn

An ease-in curve causes the animation to begin slowly, and then speed up as it progresses. Available in iOS 2.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

118

UIView Class Reference Constants

UIViewAnimationCurveEaseOut

An ease-out curve causes the animation to begin quickly, and then slow down as it completes. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationCurveLinear

A linear animation curve causes an animation to occur evenly over its duration. Available in iOS 2.0 and later. Declared in UIView.h. Availability Available in iOS 2.0 and later. Declared in
UIView.h

UIViewKeyframeAnimationOptions
Key frame animation options used with the
animateKeyframesWithDuration:delay:options:animations:completion:

(page 43) method.

typedef enum { UIViewKeyframeAnimationOptionLayoutSubviews UIViewAnimationOptionLayoutSubviews, UIViewKeyframeAnimationOptionAllowUserInteraction UIViewAnimationOptionAllowUserInteraction, UIViewKeyframeAnimationOptionBeginFromCurrentState UIViewAnimationOptionBeginFromCurrentState, UIViewKeyframeAnimationOptionRepeat UIViewKeyframeAnimationOptionAutoreverse

= = = = UIViewAnimationOptionRepeat, = UIViewAnimationOptionAutoreverse,

UIViewKeyframeAnimationOptionOverrideInheritedDuration = UIViewAnimationOptionOverrideInheritedDuration, UIViewKeyframeAnimationOptionOverrideInheritedOptions = UIViewAnimationOptionOverrideInheritedOptions, UIViewKeyframeAnimationOptionCalculationModeLinear UIViewKeyframeAnimationOptionCalculationModeDiscrete UIViewKeyframeAnimationOptionCalculationModePaced UIViewKeyframeAnimationOptionCalculationModeCubic UIViewKeyframeAnimationOptionCalculationModeCubicPaced } UIViewKeyframeAnimationOptions; = = = = = 0 1 2 3 4 << << << << << 9, 9, 9, 9, 9

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

119

UIView Class Reference Constants

Constants
UIViewKeyframeAnimationOptionLayoutSubviews

The option to lay out subviews at commit time so that they are animated along with their parent. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionAllowUserInteraction

The option that allows the user to interact with views while they are being animated. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionBeginFromCurrentState

The option to start an animation from the current setting associated with an already in-flight animation. If this option is not present, any in-flight animations are allowed to finish before the new animation is started. If another animation is not in flight, this option has no effect. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionRepeat

The option to repeat an animation indefinitely. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionAutoreverse

The option to run an animation backwards and forwards. Must be combined with the UIViewKeyframeAnimationOptionRepeat option. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionOverrideInheritedDuration

The option to force an animation to use the original duration value specified when the animation was submitted. If this option is not present, the animation inherits the remaining duration of the in-flight animation, if any. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionOverrideInheritedOptions

The option to not inherit the animation type or any options. Available in iOS 7.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

120

UIView Class Reference Constants

UIViewKeyframeAnimationOptionCalculationModeLinear

The option to use a simple linear calculation when interpolating between keyframe values. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionCalculationModeDiscrete

The option to not interpolate between keyframe values, but rather to jump directly to each new keyframe value. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionCalculationModePaced

The option to compute intermediate keyframe values using a simple pacing algorithm. This option results in an evenly paced animation. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionCalculationModeCubic

The option to compute intermediate frames using a default Catmull-Rom spline that passes through the keyframe values. You cannot adjust the parameters of this algorithm. Available in iOS 7.0 and later. Declared in UIView.h.
UIViewKeyframeAnimationOptionCalculationModeCubicPaced

The option to compute intermediate frames using the cubic scheme while ignoring the timing properties of the animation. Instead, timing parameters are calculated implicitly to give the animation a constant velocity. Available in iOS 7.0 and later. Declared in UIView.h.

UIViewContentMode
Options to specify how a view adjusts its content when its size changes.

typedef enum { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, UIViewContentModeCenter, UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft,

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

121

UIView Class Reference Constants

UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, } UIViewContentMode;

Constants
UIViewContentModeScaleToFill

The option to scale the content to fit the size of itself by changing the aspect ratio of the content if necessary. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeScaleAspectFit

The option to scale the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the views bounds is transparent. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeScaleAspectFill

The option to scale the content to fill the size of the view. Some portion of the content may be clipped to fill the views bounds. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeRedraw

The option to redisplay the view when the bounds change by invoking the setNeedsDisplay (page 102) method. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeCenter

The option to center the content in the views bounds, keeping the proportions the same. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeTop

The option to center the content aligned at the top in the views bounds. Available in iOS 2.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

122

UIView Class Reference Constants

UIViewContentModeBottom

The option to center the content aligned at the bottom in the views bounds. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeLeft

The option to align the content on the left of the view. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeRight

The option to align the content on the right of the view. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeTopLeft

The option to align the content in the top-left corner of the view. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeTopRight

The option to align the content in the top-right corner of the view. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeBottomLeft

The option to align the content in the bottom-left corner of the view. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewContentModeBottomRight

The option to align the content in the bottom-right corner of the view. Available in iOS 2.0 and later. Declared in UIView.h. Availability Available in iOS 2.0 and later. Declared in
UIView.h

UILayoutConstraintAxis
Keys that specify a horizontal or vertical layout constraint between objects.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

123

UIView Class Reference Constants

enum { UILayoutConstraintAxisHorizontal = 0, UILayoutConstraintAxisVertical = 1 }; typedef NSInteger UILayoutConstraintAxis;

Constants
UILayoutConstraintAxisHorizontal

The constraint applied when laying out the horizontal relationship between objects. Available in iOS 6.0 and later. Declared in UIView.h.
UILayoutConstraintAxisVertical

The constraint applied when laying out the vertical relationship between objects. Available in iOS 6.0 and later. Declared in UIView.h.

UIViewTintAdjustmentMode
The tint adjustment mode for the view.

typedef enum { UIViewTintAdjustmentModeAutomatic, UIViewTintAdjustmentModeNormal, UIViewTintAdjustmentModeDimmed, } UIViewTintAdjustmentMode;

Constants
UIViewTintAdjustmentModeAutomatic

The tint adjustment mode of the view is the same as its superview's tint adjustment mode (or UIViewTintAdjustmentModeNormal if the view has no superview). Available in iOS 7.0 and later. Declared in UIView.h.
UIViewTintAdjustmentModeNormal

The view's tintColor (page 39) property returns the completely unmodified tint color of the view. Available in iOS 7.0 and later. Declared in UIView.h.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

124

UIView Class Reference Constants

UIViewTintAdjustmentModeDimmed

The view's tintColor (page 39) property returns a desaturated, dimmed version of the view's original tint color. Available in iOS 7.0 and later. Declared in UIView.h. Availability Available in iOS 7.0 and later. Declared in
UIView.h

UISystemAnimation
Option to remove the views from the hierarchy when animation is complete.

typedef enum{ UISystemAnimationDelete, } UISystemAnimation;

Constants
UISystemAnimationDelete

Option to remove views from the view hierarchy when animation is complete. Available in iOS 7.0 and later. Declared in UIView.h. Availability Available in iOS 7.0 and later. Declared in
UIView.h

Fitting Size
View fitting options used in the systemLayoutSizeFittingSize: (page 108) method.

const CGSize UILayoutFittingCompressedSize; const CGSize UILayoutFittingExpandedSize;

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

125

UIView Class Reference Constants

Constants
UILayoutFittingCompressedSize

The option to use the smallest possible size. Available in iOS 6.0 and later. Declared in UIView.h.
UILayoutFittingExpandedSize

The option to use the largest possible size. Available in iOS 6.0 and later. Declared in UIView.h.

UIView Intrinsic Metric Constant


The option to indicate that a view has no intrinsic metric for a given numeric property.

const CGFloat UIViewNoIntrinsicMetric;

Constants
UIViewNoIntrinsicMetric

The absence of an intrinsic metric for a given numeric view property. Available in iOS 6.0 and later. Declared in UIView.h.

UIViewAutoresizing
Options for automatic view resizing.

enum { UIViewAutoresizingNone UIViewAutoresizingFlexibleLeftMargin UIViewAutoresizingFlexibleWidth UIViewAutoresizingFlexibleRightMargin UIViewAutoresizingFlexibleTopMargin UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleBottomMargin }; typedef NSUInteger UIViewAutoresizing;

= = = = = = =

0, 1 << 1 << 1 << 1 << 1 << 1 <<

0, 1, 2, 3, 4, 5

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

126

UIView Class Reference Constants

Constants
UIViewAutoresizingNone

The option for indicating that the view does not resize. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleLeftMargin

Resizing performed by expanding or shrinking a view in the direction of the left margin. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleWidth

Resizing performed by expanding or shrinking a views width. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleRightMargin

Resizing performed by expanding or shrinking a view in the direction of the right margin. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleTopMargin

Resizing performed by expanding or shrinking a view in the direction of the top margin. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleHeight

Resizing performed by expanding or shrinking a view's height. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAutoresizingFlexibleBottomMargin

Resizing performed by expanding or shrinking a view in the direction of the bottom margin. Available in iOS 2.0 and later. Declared in UIView.h. Availability Available in iOS 2.0 and later. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

127

UIView Class Reference Constants

UIViewAnimationTransition
Animation transition options for use in an animation block object.

typedef enum { UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, } UIViewAnimationTransition;

Constants
UIViewAnimationTransitionNone

The option for indicating that no transition is specified. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationTransitionFlipFromLeft

A transition that flips a view around a vertical axis from left to right. The left side of the view moves towards the front and right side towards the back. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationTransitionFlipFromRight

A transition that flips a view around a vertical axis from right to left. The right side of the view moves towards the front and left side towards the back. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationTransitionCurlUp

A transition that curls a view up from the bottom. Available in iOS 2.0 and later. Declared in UIView.h.
UIViewAnimationTransitionCurlDown

A transition that curls a view down from the top. Available in iOS 2.0 and later. Declared in UIView.h. Availability Available in iOS 2.0 and later.

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

128

UIView Class Reference Constants

Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

129

Deprecated UIView Methods

A method identified as deprecated has been superseded and may become unsupported in the future.

Deprecated in iOS 6.0


contentStretch
The rectangle that defines the stretchable and nonstretchable regions of a view. (Deprecated in iOS 6.0.)
@property(nonatomic) CGRect contentStretch

Discussion You use this property to control how a views content is stretched to fill its bounds when the view is resized. Content stretching is often used to animate the resizing of a view. For example, buttons and other controls use stretching to maintain crisp borders while allowing the middle portions of the control to stretch and fill the available space. Note: For stretching image-based content, it is simpler to use a UIImageView object with a stretchable image instead of setting this property. You can create a stretchable image using the stretchableImageWithLeftCapWidth:topCapHeight: method of UIImage.

The values you specify for this rectangle must be normalized to the range 0.0 to 1.0. These values are then scaled to the size of the views content to obtain the appropriate pixel values. The default value for this rectangle has an origin of (0.0, 0.0) and a size of (1.0, 1.0). This reflects a rectangle whose stretchable portion encompasses the entire content. Availability Available in iOS 3.0 and later. Deprecated in iOS 6.0. Declared in
UIView.h

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

130

Document Revision History

This table describes the changes to UIView Class Reference .

Date 2014-03-10 2013-12-16 2013-10-22 2013-09-18

Notes Updated layoutIfNeeded method description. Clarified the behavior of the UIViewTintAdjustmentMode constants. Updated advice about views that draw using OpenGL ES. Added descriptions for new properties in iOS 7: motionEffects (page 34), tintAdjustmentMode (page 38), and tintColor (page 39). Added descriptions for new instance methods in iOS 7: snapshotViewAfterScreenUpdates: (page 107),
resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: (page

98), drawViewHierarchyInRect:afterScreenUpdates: (page 82), addMotionEffect: (page 70), removeMotionEffect: (page 98), tintColorDidChange (page 108). Added descriptions for new class methods in iOS 7:
addKeyframeWithRelativeStartTime:relativeDuration:animations: (page

41),
animateKeyframesWithDuration:delay:options:animations:completion: (page

43),
animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options: animations:completion:

(page 47),

performSystemAnimation:onViews:options:animations:completion: (page

52), and performWithoutAnimation: (page 52).

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

131

Document Revision History

Date

Notes Added descriptions for new key-frame animation constants in iOS 7: UIViewKeyframeAnimationOptionLayoutSubviews (page 120), UIViewAnimationOptionAllowUserInteraction (page 115), UIViewAnimationOptionBeginFromCurrentState (page 115), UIViewAnimationOptionRepeat (page 115), UIViewAnimationOptionAutoreverse (page 115), UIViewAnimationOptionOverrideInheritedDuration (page 116), UIViewAnimationOptionOverrideInheritedOptions (page 116), UIViewKeyframeAnimationOptionCalculationModeCubic (page 121), UIViewKeyframeAnimationOptionCalculationModeCubicPaced (page 121), UIViewKeyframeAnimationOptionCalculationModeDiscrete (page 121), UIViewKeyframeAnimationOptionCalculationModeLinear (page 121), and UIViewKeyframeAnimationOptionCalculationModePaced (page 121). Added descriptions for new tit adjustment constants in iOS 7: UIViewTintAdjustmentModeAutomatic (page 124), UIViewTintAdjustmentModeDimmed (page 125), and UIViewTintAdjustmentModeNormal (page 124). Added a description for a new animation constant in iOS 7: UISystemAnimationDelete (page 125).

2012-09-19

Added methods and properties related to state preservation and restoration. Added methods related to autolayout. Fixed typo. Added new animation transition constants. Corrected the backgroundColor property description. Updated the class overview and added new methods related to printing. Updated to include symbols introduced in iOS 4.0. Added descriptions of property and methods related to gesture recognizers. Corrected description of the convertRect:toView: method.

2011-10-12 2011-03-08 2010-11-15 2010-06-04 2010-02-25

2009-11-17

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

132

Document Revision History

Date 2009-07-23

Notes Updated the information about view size restrictions to account for changes in iOS 3.0. Updated the description of caching behaviors for the setAnimationTransition:forView:cache: method. Also updated the description of the behavior of the layoutIfNeeded method. Updated for iOS 3.0. Updated animationDidEndSelector: documentation. Corrected description of background property. New document that describes the superclass providing concrete subclasses with a structure for drawing and handling events in views.

2009-06-15

2009-03-05 2008-11-13 2008-09-09 2008-07-05

2014-03-10 | Copyright 2014 Apple Inc. All Rights Reserved.

133

Apple Inc. Copyright 2014 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, Bonjour, iPhone, and Keychain are trademarks of Apple Inc., registered in the U.S. and other countries. AirDrop is a trademark of Apple Inc. iAd is a service mark of Apple Inc., registered in the U.S. and other countries. OpenGL is a registered trademark of Silicon Graphics, Inc. Times is a registered trademark of Heidelberger Druckmaschinen AG, available from Linotype Library GmbH. iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.

You might also like