uiview_class123

134
UIView Class Reference

Upload: qamar-saleem

Post on 20-Jan-2016

39 views

Category:

Documents


0 download

DESCRIPTION

Uiview reference file

TRANSCRIPT

Page 1: UIView_Class123

UIView Class Reference

Page 2: UIView_Class123

Contents

UIView Class Reference 7Overview 7

Creating a View 9The View Drawing Cycle 9Animations 10Threading Considerations 11Subclassing Notes 11

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

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

2

Page 3: UIView_Class123

Properties 24alpha 24autoresizesSubviews 24autoresizingMask 25backgroundColor 26bounds 26center 27clearsContextBeforeDrawing 28clipsToBounds 29contentMode 29contentScaleFactor 30exclusiveTouch 31frame 31gestureRecognizers 32hidden 33layer 34motionEffects 34multipleTouchEnabled 35opaque 35restorationIdentifier 36subviews 37superview 37tag 38tintAdjustmentMode 38tintColor 39transform 40userInteractionEnabled 40window 41

Class Methods 41addKeyframeWithRelativeStartTime:relativeDuration:animations: 41animateKeyframesWithDuration:delay:options:animations:completion: 43animateWithDuration:animations: 44animateWithDuration:animations:completion: 45animateWithDuration:delay:options:animations:completion: 46animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options: animations:completion:47areAnimationsEnabled 48beginAnimations:context: 49commitAnimations 50

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

3

Contents

Page 4: UIView_Class123

layerClass 51performSystemAnimation:onViews:options:animations:completion: 52performWithoutAnimation: 52requiresConstraintBasedLayout 53setAnimationBeginsFromCurrentState: 53setAnimationCurve: 54setAnimationDelay: 55setAnimationDelegate: 56setAnimationDidStopSelector: 57setAnimationDuration: 58setAnimationRepeatAutoreverses: 59setAnimationRepeatCount: 60setAnimationsEnabled: 61setAnimationStartDate: 62setAnimationTransition:forView:cache: 63setAnimationWillStartSelector: 64transitionFromView:toView:duration:options:completion: 65transitionWithView:duration:options:animations:completion: 67

Instance Methods 68addConstraint: 68addConstraints: 69addGestureRecognizer: 69addMotionEffect: 70addSubview: 71alignmentRectForFrame: 71alignmentRectInsets 72bringSubviewToFront: 73constraints 73constraintsAffectingLayoutForAxis: 74contentCompressionResistancePriorityForAxis: 74contentHuggingPriorityForAxis: 75convertPoint:fromView: 76convertPoint:toView: 76convertRect:fromView: 77convertRect:toView: 78decodeRestorableStateWithCoder: 78didAddSubview: 79didMoveToSuperview 80didMoveToWindow 80

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

4

Contents

Page 5: UIView_Class123

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

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

5

Contents

Page 6: UIView_Class123

systemLayoutSizeFittingSize: 108tintColorDidChange 108translatesAutoresizingMaskIntoConstraints 109updateConstraints 110updateConstraintsIfNeeded 110viewForBaselineLayout 111viewPrintFormatter 111viewWithTag: 112willMoveToSuperview: 112willMoveToWindow: 113willRemoveSubview: 114

Constants 114UIViewAnimationOptions 114UIViewAnimationCurve 118UIViewKeyframeAnimationOptions 119UIViewContentMode 121UILayoutConstraintAxis 123UIViewTintAdjustmentMode 124UISystemAnimation 125Fitting Size 125UIView Intrinsic Metric Constant 126UIViewAutoresizing 126UIViewAnimationTransition 128

Deprecated UIView Methods 130Deprecated in iOS 6.0 130

contentStretch 130

Document Revision History 131

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

6

Contents

Page 7: UIView_Class123

Inherits from UIResponder : NSObject

Conforms to NSCoding

UIAppearance

UIAppearanceContainer

UIDynamicItem

NSObject (NSObject)

Framework /System/Library/Frameworks/UIKit.framework

Availability Available in iOS 2.0 and later.

Declared in 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

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

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

7

UIView Class Reference

Page 8: UIView_Class123

the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standardsubclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabelobject 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 ofresponsibilities. Here are just a few:

● Drawing and animation

● Views draw content in their rectangular area using technologies such as UIKit, Core Graphics, andOpenGL 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 UIResponderclass.

● Views can use the addGestureRecognizer: (page 69) method to install gesture recognizers to handlecommon gestures.

Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationshipbetween the view being embedded (known as the subview) and the parent view doing the embedding (knownas the superview). Normally, a subview’s visible area is not clipped to the bounds of its superview, but in iOSyou can use the clipsToBounds (page 29) property to alter that behavior. A parent view may contain anynumber of subviews but each subview has only one superview, which is responsible for positioning its subviewsappropriately.

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 iscommonly used during layout to adjust the size or position of the view. The center property can be used toadjust the position of the view without changing its size. The bounds defines the internal dimensions of theview as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame andbounds 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 .

UIView Class ReferenceOverview

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

8

Page 9: UIView_Class123

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 memorythey consume. It is in your best interests to keep view sizes as small as possible. Regardless of whichversion of iOS is running, you should consider tiling any content that is significantly larger than thedimensions the screen.

Creating a ViewTo 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 superview’s coordinate system (once itis 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. TheaddSubview: (page 71) method places the specified view on top of other siblings. You can specify the relativez-order of a subview by adding it using the insertSubview:aboveSubview: (page 90) andinsertSubview:belowSubview: (page 91) methods. You can also exchange the position of already addedsubviews 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 yourapplication’s interface changes but it may happen at other times as well. For example, calling thesetNeedsLayout (page 104) method forces your view to update its layout.

The View Drawing CycleView drawing occurs on an as-needed basis. When a view is first shown, or when all or part of it becomes visibledue to layout changes, the system asks the view to draw its contents. For views that contain custom contentusing UIKit or Core Graphics, the system calls the view’s drawRect: (page 81) method. Your implementationof this method is responsible for drawing the view’s content into the current graphics context, which is set upby the system automatically prior to calling this method. This creates a static visual representation of yourview’s 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 viewneeds to be redrawn. You do this by calling your view’s setNeedsDisplay (page 102) orsetNeedsDisplayInRect: (page 103) method of the view. These methods let the system know that it shouldupdate the view during the next drawing cycle. Because it waits until the next drawing cycle to update theview, you can call these methods on multiple views to update them at the same time.

UIView Class ReferenceOverview

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

9

Page 10: UIView_Class123

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

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

AnimationsChanges to several view properties can be animated—that is, changing the property creates an animationthat conveys the change to the user over a short period of time. The UIView class does most of the work ofperforming 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 simplifythe creation of animations. With one method call, you specify the animations to be performed and the optionsfor the animation. However, block-based animations are available only in iOS 4 and later. If your applicationruns on earlier versions of iOS, you must use the beginAnimations:context: (page 49) andcommitAnimations (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)

@property bounds (page 26)

@property center (page 27)

@property transform (page 40)

@property alpha (page 24)

@property backgroundColor (page 26)

@property contentStretch (page 130)

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

UIView Class ReferenceOverview

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

10

Page 11: UIView_Class123

Threading ConsiderationsManipulations to your application’s user interface must occur on the main thread. Thus, you should always callthe methods of the UIView class from code running in the main thread of your application. The only time thismay not be strictly necessary is when creating the view object itself but all other manipulations should occuron the main thread.

Subclassing NotesThe UIView class is a key subclassing point for visual content that also requires user interactions. Althoughthere are many good reasons to subclass UIView, it is recommended that you do so only when the basicUIView class or the standard system views do not provide the capabilities that you need. Subclassing requiresmore 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 OverrideWhen subclassing UIView, there are only a handful of methods you should override and many methods thatyou might override depending on your needs. Because UIView is a highly configurable class, there are alsomany ways to implement sophisticated view behaviors without overriding custom methods, which are discussedin the Alternatives to Subclassing section. In the meantime, the following list includes the methods you mightconsider overriding in your UIView subclasses:

● Initialization:

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

● initWithCoder: - Implement this method if you load your view from an Interface Builder nib fileand your view requires custom initialization.

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

● Drawing and printing:

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

● drawRect:forViewPrintFormatter: (page 82) - Implement this method only if you want to drawyour view’s content differently during printing.

● Constraints:

● requiresConstraintBasedLayout (page 53) - Implement this class method if your view class requiresconstraints to work properly.

UIView Class ReferenceOverview

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

11

Page 12: UIView_Class123

● updateConstraints (page 110) - Implement this method if your view needs to create custom constraintsbetween your subviews.

● alignmentRectForFrame: (page 71), frameForAlignmentRect: (page 86) - Implement these methodsto override how your views are aligned to other views.

● Layout:

● sizeThatFits: (page 105) - Implement this method if you want your view to have a different defaultsize than it normally would during resizing operations. For example, you might use this method toprevent your view from shrinking to the point where subviews cannot be displayed correctly.

● layoutSubviews (page 94) - Implement this method if you need more precise control over the layoutof your subviews than either the constraint or autoresizing behaviors provide.

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

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

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

● Event Handling:

● touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:,touchesCancelled:withEvent: - Implement these methods if you need to handle touch eventsdirectly. (For gesture-based input, use gesture recognizers.)

● gestureRecognizerShouldBegin: (page 87) - Implement this method if your view handles touchevents directly and might want to prevent attached gesture recognizers from triggering additionalactions.

Alternatives to SubclassingMany 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.

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

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

UIView Class ReferenceOverview

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

12

Page 13: UIView_Class123

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

● hidden (page 33) or alpha (page 24) - Change the transparency of the view as a whole rather than hidingor applying alpha to your view’s rendered content.

● backgroundColor (page 26) - Set the view’s color rather than drawing that color yourself.

● Subviews - Rather than draw your content using a drawRect: (page 81) method, embed image and labelsubviews with the content you want to present.

● Gesture recognizers - Rather than subclass to intercept and handle touch events yourself, you can usegesture recognizers to send an action message to a target object.

● Animations - Use the built-in animation support rather than trying to animate changes yourself. Theanimation support provided by Core Animation is fast and easy to use.

● Image-based backgrounds - For views that display relatively static content, consider using a UIImageViewobject with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, youcan also use a generic UIView object and assign your image as the content of the view’s CALayer object.

Animations are another way to make visible changes to a view without requiring you to subclass and implementcomplex drawing code. Many properties of the UIView class are animatable, which means changes to thoseproperties can trigger system-generated animations. Starting animations requires as little as one line of codeto indicate that any changes that follow should be animated. For more information about animation supportfor views, see “Animations” (page 10).

For more information about appearance and behavior configuration, see “About Views” in UIKit User InterfaceCatalog .

Tasks

Initializing a View Object

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

Configuring a View’s Visual Appearance

backgroundColor (page 26) propertyThe view’s background color.

UIView Class ReferenceTasks

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

13

Page 14: UIView_Class123

hidden (page 33) propertyA Boolean value that determines whether the view is hidden.

alpha (page 24) propertyThe view’s alpha value.

opaque (page 35) propertyA Boolean value that determines whether the view is opaque.

tintColor (page 39) propertyThe first nondefault tint color value in the view’s hierarchy, ascending from and starting with the viewitself.

tintAdjustmentMode (page 38) propertyThe first non-default tint adjustment mode value in the view’s hierarchy, ascending from and startingwith the view itself.

clipsToBounds (page 29) propertyA Boolean value that determines whether subviews are confined to the bounds of the view.

clearsContextBeforeDrawing (page 28) propertyA Boolean value that determines whether the view’s bounds should be automatically cleared beforedrawing.

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

layer (page 34) propertyThe view’s Core Animation layer used for rendering. (read-only)

Configuring the Event-Related Behavior

userInteractionEnabled (page 40) propertyA Boolean value that determines whether user events are ignored and removed from the event queue.

multipleTouchEnabled (page 35) propertyA Boolean value that indicates whether the receiver handles multi-touch events.

exclusiveTouch (page 31) propertyA Boolean value that indicates whether the receiver handles touch events exclusively.

UIView Class ReferenceTasks

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

14

Page 15: UIView_Class123

Configuring the Bounds and Frame Rectangles

frame (page 31) propertyThe frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

bounds (page 26) propertyThe bounds rectangle, which describes the view’s location and size in its own coordinate system.

center (page 27) propertyThe center of the frame.

transform (page 40) propertySpecifies the transform applied to the receiver, relative to the center of its bounds.

Managing the View Hierarchy

superview (page 37) propertyThe receiver’s superview, or nil if it has none. (read-only)

subviews (page 37) propertyThe receiver’s immediate subviews. (read-only)

window (page 41) propertyThe receiver’s window object, or nil if it has none. (read-only)

– addSubview: (page 71)Adds a view to the end of the receiver’s list of subviews.

– bringSubviewToFront: (page 73)Moves the specified subview so that it appears on top of its siblings.

– sendSubviewToBack: (page 100)Moves the specified subview so that it appears behind its siblings.

– removeFromSuperview (page 97)Unlinks the view from its superview and its window, and removes it from the responder chain.

– insertSubview:atIndex: (page 91)Inserts a subview at the specified index.

– insertSubview:aboveSubview: (page 90)Inserts a view above another view in the view hierarchy.

– insertSubview:belowSubview: (page 91)Inserts a view below another view in the view hierarchy.

– exchangeSubviewAtIndex:withSubviewAtIndex: (page 85)Exchanges the subviews at the specified indices.

UIView Class ReferenceTasks

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

15

Page 16: UIView_Class123

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

Configuring the Resizing Behavior

autoresizingMask (page 25) propertyAn integer bit mask that determines how the receiver resizes itself when its superview’s bounds change.

autoresizesSubviews (page 24) propertyA Boolean value that determines whether the receiver automatically resizes its subviews when its boundschange.

contentMode (page 29) propertyA flag used to determine how a view lays out its content when its bounds change.

– sizeThatFits: (page 105)Asks the view to calculate and return the size that best fits its subviews.

– sizeToFit (page 106)Resizes and moves the receiver view so it just encloses its subviews.

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

Laying out Subviews

– layoutSubviews (page 94)Lays out subviews.

– setNeedsLayout (page 104)Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.

– layoutIfNeeded (page 94)Lays out the subviews immediately.

Opting in to Constraint-Based Layout

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

UIView Class ReferenceTasks

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

16

Page 17: UIView_Class123

– translatesAutoresizingMaskIntoConstraints (page 109)Returns a Boolean value that indicates whether the view’s autoresizing mask is translated into constraintsfor the constraint-based layout system.

– setTranslatesAutoresizingMaskIntoConstraints: (page 105)Sets whether the view’s autoresizing mask should be translated into constraints for the constraint-basedlayout system.

Managing Constraints

– constraints (page 73)Returns the constraints held by the view.

– addConstraint: (page 68)Adds a constraint on the layout of the receiving view or its subviews.

– addConstraints: (page 69)Adds multiple constraints on the layout of the receiving view or its subviews.

– removeConstraint: (page 96)Removes the specified constraint from the view.

– removeConstraints: (page 96)Removes the specified constraints from the view.

Measuring in Constraint-Based Layout

– systemLayoutSizeFittingSize: (page 108)Returns the size of the view that satisfies the constraints it holds.

– intrinsicContentSize (page 92)Returns the natural size for the receiving view, considering only properties of the view itself.

– invalidateIntrinsicContentSize (page 93)Invalidates the view’s intrinsic content size.

– contentCompressionResistancePriorityForAxis: (page 74)Returns the priority with which a view resists being made smaller than its intrinsic size.

– setContentCompressionResistancePriority:forAxis: (page 100)Sets the priority with which a view resists being made smaller than its intrinsic size.

– contentHuggingPriorityForAxis: (page 75)Returns the priority with which a view resists being made larger than its intrinsic size.

UIView Class ReferenceTasks

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

17

Page 18: UIView_Class123

– 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 view’s alignment rectangle for a given frame.

– frameForAlignmentRect: (page 86)Returns the view’s frame for a given alignment rectangle.

– alignmentRectInsets (page 72)Returns the insets from the view’s frame that define its alignment rectangle.

– viewForBaselineLayout (page 111)Returns a view used to satisfy baseline constraints.

Triggering Constraint-Based Layout

– needsUpdateConstraints (page 95)Returns whether the view’s constraints need updating.

– setNeedsUpdateConstraints (page 104)Controls whether the view’s constraints need updating.

– updateConstraints (page 110)Updates constraints for the view.

– updateConstraintsIfNeeded (page 110)Updates the constraints for the receiving view and its subviews.

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.

– hasAmbiguousLayout (page 88)Returns whether the constraints impacting the layout of the view incompletely specify the location ofthe view.

UIView Class ReferenceTasks

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

18

Page 19: UIView_Class123

– 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 receiver’s image within the passed-in rectangle.

– setNeedsDisplay (page 102)Marks the receiver’s entire bounds rectangle as needing to be redrawn.

– setNeedsDisplayInRect: (page 103)Marks the specified rectangle of the receiver as needing to be redrawn.

contentScaleFactor (page 30) propertyThe scale factor applied to the view.

– tintColorDidChange (page 108) Called by the system when the tintColor property changes.

Formatting Printed View Content

– viewPrintFormatter (page 111)Returns a print formatter for the receiving view.

– drawRect:forViewPrintFormatter: (page 82)Implemented to draw the view’s content for printing.

Managing Gesture Recognizers

– addGestureRecognizer: (page 69)Attaches a gesture recognizer to the view.

– removeGestureRecognizer: (page 97)Detaches a gesture recognizer from the receiving view.

gestureRecognizers (page 32) propertyThe gesture-recognizer objects currently attached to the view.

– gestureRecognizerShouldBegin: (page 87)Asks the view if the gesture recognizer should be allowed to continue tracking touch events.

UIView Class ReferenceTasks

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

19

Page 20: UIView_Class123

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 completionhandler.

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

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

+ transitionWithView:duration:options:animations:completion: (page 67)Creates a transition animation for the specified container view.

+ transitionFromView:toView:duration:options:completion: (page 65)Creates a transition animation between the specified views using the given parameters.

+ animateKeyframesWithDuration:delay:options:animations:completion: (page 43)Creates an animation block object that can be used to set up keyframe-based animations for the currentview.

+ addKeyframeWithRelativeStartTime:relativeDuration:animations: (page 41)Specifies the timing and animation values for a single frame of a keyframe animation.

+ performSystemAnimation:onViews:options:animations:completion: (page 52)Performs a specified system-provided animation on one or more views, along with optional parallelanimations that you define.

+ animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion: (page47)

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 methodsinstead.

+ beginAnimations:context: (page 49)Marks the beginning of a begin/commit animation block.

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

UIView Class ReferenceTasks

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

20

Page 21: UIView_Class123

+ setAnimationStartDate: (page 62)Sets the start time for the current animation block.

+ setAnimationsEnabled: (page 61)Sets whether animations are enabled.

+ setAnimationDelegate: (page 56)Sets the delegate for any animation messages.

+ setAnimationWillStartSelector: (page 64)Sets the message to send to the animation delegate when the animation starts.

+ setAnimationDidStopSelector: (page 57)Sets the message to send to the animation delegate when animation stops.

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

+ setAnimationDelay: (page 55)Sets the amount of time (in seconds) to wait before animating property changes within an animationblock.

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

+ setAnimationRepeatCount: (page 60)Sets the number of times animations within an animation block repeat.

+ setAnimationRepeatAutoreverses: (page 59)Sets whether the animations within an animation block automatically reverse themselves.

+ setAnimationBeginsFromCurrentState: (page 53)Sets whether the animation should begin playing from the current state.

+ setAnimationTransition:forView:cache: (page 63)Sets a transition to apply to a view during an animation block.

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

Using Motion Effects

– addMotionEffect: (page 70)Begins applying a motion effect to the view.

motionEffects (page 34) propertyThe array of motion effects for the view.

UIView Class ReferenceTasks

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

21

Page 22: UIView_Class123

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

Preserving and Restoring State

restorationIdentifier (page 36) propertyThe identifier that determines whether the view supports state restoration.

– encodeRestorableStateWithCoder: (page 83)Encodes state-related information for the view.

– decodeRestorableStateWithCoder: (page 78)Decodes and restores state-related information for the view.

Capturing a View Snapshot

– snapshotViewAfterScreenUpdates: (page 107)Returns a snapshot view based on the contents of the current view.

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

– drawViewHierarchyInRect:afterScreenUpdates: (page 82)Renders a snapshot of the complete view hierarchy as visible onscreen into the current context.

Identifying the View at Runtime

tag (page 38) propertyAn integer that you can use to identify view objects in your application.

– viewWithTag: (page 112)Returns the view whose tag matches the specified value.

Converting Between View Coordinate Systems

– convertPoint:toView: (page 76)Converts a point from the receiver’s coordinate system to that of the specified view.

UIView Class ReferenceTasks

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

22

Page 23: UIView_Class123

– convertPoint:fromView: (page 76)Converts a point from the coordinate system of a given view to that of the receiver.

– convertRect:toView: (page 78)Converts a rectangle from the receiver’s coordinate system to that of another view.

– convertRect:fromView: (page 77)Converts a rectangle from the coordinate system of another view to that of the receiver.

Hit Testing in a View

– hitTest:withEvent: (page 88)Returns the farthest descendant of the receiver in the view hierarchy (including itself ) that contains aspecified point.

– pointInside:withEvent: (page 95)Returns a Boolean value indicating whether the receiver contains the specified point.

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.

– willRemoveSubview: (page 114)Tells the view that a subview is about to be removed.

– willMoveToSuperview: (page 112)Tells the view that its superview is about to change to the specified superview.

– didMoveToSuperview (page 80)Tells the view that its superview changed.

– willMoveToWindow: (page 113)Tells the view that its window object is about to change.

– didMoveToWindow (page 80)Tells the view that its window object changed.

UIView Class ReferenceTasks

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

23

Page 24: UIView_Class123

Properties

alpha

The view’s alpha value.

@property(nonatomic) CGFloat alpha

DiscussionThe value of this property is a floating-point number in the range 0.0 to 1.0, where 0.0 represents totallytransparent and 1.0 represents totally opaque. This value affects only the current view and does not affectany of its embedded subviews.

Changes to this property can be animated.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property backgroundColor (page 26) @property opaque (page 35)

Related Sample CodeiPhoneCoreDataRecipesLocateMeSimpleNetworkStreamsUIImagePicker Video RecorderUnwindSegue

Declared inUIView.h

autoresizesSubviews

A Boolean value that determines whether the receiver automatically resizes its subviews when its bounds change.

@property(nonatomic) BOOL autoresizesSubviews

DiscussionWhen set to YES, the receiver adjusts the size of its subviews when its bounds change. The default value isYES.

UIView Class ReferenceProperties

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

24

Page 25: UIView_Class123

AvailabilityAvailable in iOS 2.0 and later.

See Also @property autoresizingMask (page 25)

Declared inUIView.h

autoresizingMask

An integer bit mask that determines how the receiver resizes itself when its superview’s bounds change.

@property(nonatomic) UIViewAutoresizing autoresizingMask

DiscussionWhen a view’s bounds change, that view automatically resizes its subviews according to each subview’sautoresizing mask. You specify the value of this mask by combining the constants described inUIViewAutoresizing (page 126) using the C bitwise OR operator. Combining these constants lets you specifywhich dimensions of the view should grow or shrink relative to the superview. The default value of this propertyis 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 differenceproportionally 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 theUIViewAutoresizingFlexibleWidth (page 127) and UIViewAutoresizingFlexibleRightMargin (page 127)constants but does not include the UIViewAutoresizingFlexibleLeftMargin constant, thus indicatingthat the width of the view’s left margin is fixed but that the view’s 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 rightof the view increase.

If the autoresizing behaviors do not offer the precise layout that you need for your views, you can use a customcontainer view and override its layoutSubviews (page 94) method to position your subviews more precisely.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property autoresizesSubviews (page 24)

Related Sample CodeMVCNetworkingNavBar

UIView Class ReferenceProperties

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

25

Page 26: UIView_Class123

PrintPhotoUICatalogXMLPerformance

Declared inUIView.h

backgroundColor

The view’s background color.

@property(nonatomic, copy) UIColor *backgroundColor

DiscussionChanges to this property can be animated. The default value is nil, which results in a transparent backgroundcolor.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property alpha (page 24) @property opaque (page 35)

Related Sample CodeiPhoneCoreDataRecipesMoviePlayerNavBarUICatalogXMLPerformance

Declared inUIView.h

bounds

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

UIView Class ReferenceProperties

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

26

Page 27: UIView_Class123

@property(nonatomic) CGRect bounds

DiscussionOn the screen, the bounds rectangle represents the same visible portion of the view as its frame rectangle. Bydefault, the origin of the bounds rectangle is set to (0, 0) but you can change this value to display differentportions of the view. The size of the bounds rectangle is coupled to the size of the frame rectangle, so thatchanges to one affect the other. Changing the bounds size grows or shrinks the view relative to its centerpoint. The coordinates of the bounds rectangle are always specified in points.

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: (page81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, setthe 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 rectangle’s size.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property frame (page 31) @property center (page 27) @property transform (page 40)

Related Sample CodeiAdInterstitialSuiteSpeakHereTeslameterUICatalogUIKit Dynamics Catalog

Declared inUIView.h

center

The center of the frame.

@property(nonatomic) CGPoint center

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

UIView Class ReferenceProperties

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

27

Page 28: UIView_Class123

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: (page81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, setthe contentMode (page 29) property to UIViewContentModeRedraw (page 122).

Changes to this property can be animated. Use the beginAnimations:context: (page 49) class method tobegin and the commitAnimations (page 50) class method to end an animation block.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property frame (page 31) @property bounds (page 26) @property transform (page 40)

Related Sample CodeAVLoupeHandling Touches Using Responder Methods and Gesture RecognizersiAdInterstitialSuiteiAdSuiteRosyWriter

Declared inUIView.h

clearsContextBeforeDrawing

A Boolean value that determines whether the view’s bounds should be automatically cleared before drawing.

@property(nonatomic) BOOL clearsContextBeforeDrawing

DiscussionWhen set to YES, the drawing buffer is automatically cleared to transparent black before the drawRect: (page81) method is called. This behavior ensures that there are no visual artifacts left over when the view’s contentsare redrawn. If the view’s opaque (page 35) property is also set to YES, the backgroundColor (page 26) propertyof 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 drawnproperly in your drawRect: method. If your drawing code is already heavily optimized, setting this propertyis NO can improve performance, especially during scrolling when only a portion of the view might need to beredrawn.

UIView Class ReferenceProperties

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

28

Page 29: UIView_Class123

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

clipsToBounds

A Boolean value that determines whether subviews are confined to the bounds of the view.

@property(nonatomic) BOOL clipsToBounds

DiscussionSetting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviewswhose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO.

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeUIKit Dynamics Catalog

Declared inUIView.h

contentMode

A flag used to determine how a view lays out its content when its bounds change.

@property(nonatomic) UIViewContentMode contentMode

DiscussionThe content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s boundschange. This property is often used to implement resizable controls, usually in conjunction with thecontentStretch (page 130) property. Instead of redrawing the contents of the view every time, you can usethis property to specify that you want to scale the contents (either with or without distortion) or pin them toa particular spot on the view.

UIView Class ReferenceProperties

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

29

Page 30: UIView_Class123

Note: You can always force the contents of a view to be redrawn by calling thesetNeedsDisplay (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 thisproperty is UIViewContentModeScaleToFill (page 122).

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeAirDrop ExamplesiPhoneCoreDataRecipesPrintPhotoWiTapZoomingPDFViewer

Declared inUIView.h

contentScaleFactor

The scale factor applied to the view.

@property(nonatomic) CGFloat contentScaleFactor

DiscussionThe scale factor determines how content in the view is mapped from the logical coordinate space (measuredin points) to the device coordinate space (measured in pixels). This value is typically either 1.0 or 2.0. Higherscale 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 topresent 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, orif 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 usingOpenGL ES, you may want to change the scale factor to trade image quality for rendering performance. Formore information on how to adjust your OpenGL ES rendering environment, see “Supporting High-ResolutionDisplays” in OpenGL ES Programming Guide for iOS .

UIView Class ReferenceProperties

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

30

Page 31: UIView_Class123

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodeGLCameraRippleLarge Image Downsizing

Declared inUIView.h

exclusiveTouch

A Boolean value that indicates whether the receiver handles touch events exclusively.

@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch

DiscussionSetting this property to YES causes the receiver to block the delivery of touch events to other views in thesame window. The default value of this property is NO.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property multipleTouchEnabled (page 35)

Declared inUIView.h

frame

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

@property(nonatomic) CGRect frame

DiscussionThis rectangle defines the size and position of the view in its superview’s coordinate system. You use thisrectangle during layout operations to size and position the view. Setting this property changes the pointspecified by the center (page 27) property and the size in the bounds (page 26) rectangle accordingly. Thecoordinates of the frame rectangle are always specified in points.

UIView Class ReferenceProperties

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

31

Page 32: UIView_Class123

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: (page81) method. If you want the drawRect: (page 81) method invoked when the frame rectangle changes, setthe 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-identitytransform, the value of the frame property is undefined and should not be modified. In that case, you canreposition the view using the center (page 27) property and adjust the size using the bounds (page 26)property instead.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property bounds (page 26) @property center (page 27) @property transform (page 40)

Related Sample CodePVRTextureLoaderSpeakHereStreetScrollerUICatalogXMLPerformance

Declared inUIView.h

gestureRecognizers

The gesture-recognizer objects currently attached to the view.

@property(nonatomic, copy) NSArray *gestureRecognizers

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

UIView Class ReferenceProperties

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

32

Page 33: UIView_Class123

AvailabilityAvailable in iOS 3.2 and later.

Declared inUIView.h

hidden

A Boolean value that determines whether the view is hidden.

@property(nonatomic, getter=isHidden) BOOL hidden

DiscussionSetting the value of this property to YES hides the receiver and setting it to NO shows the receiver. The defaultvalue is NO.

A hidden view disappears from its window and does not receive input events. It remains in its superview’s listof subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect ofhiding those subviews and any view descendants they might have. This effect is implicit and does not alterthe hidden state of the receiver’s descendants.

Hiding the view that is the window’s current first responder causes the view’s next valid key view to becomethe new first responder.

The value of this property reflects the state of the receiver only and does not account for the state of thereceiver’s ancestors in the view hierarchy. Thus this property can be NO but the receiver may still be hidden ifan ancestor is hidden.

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeCryptoExerciseGeocoderDemoiAdInterstitialSuiteRegionsUICatalog

Declared inUIView.h

UIView Class ReferenceProperties

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

33

Page 34: UIView_Class123

layer

The view’s Core Animation layer used for rendering. (read-only)

@property(nonatomic, readonly, retain) CALayer *layer

DiscussionThis property is never nil. The actual class of the object is determined by the value returned by the layerClassmethod. The view is the layer’s delegate.

Warning: Because the view is the layer’s delegate, never make the view the delegate of another

CALayer object. Additionally, never change the delegate of this layer object.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ layerClass (page 51)

Related Sample CodeGeocoderDemoHandling Touches Using Responder Methods and Gesture RecognizersMTAudioProcessingTap Audio ProcessorPhotosByLocationUnwindSegue

Declared inUIView.h

motionEffects

The array of motion effects for the view.

@property(copy, nonatomic) NSArray *motionEffects

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

UIView Class ReferenceProperties

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

34

Page 35: UIView_Class123

multipleTouchEnabled

A Boolean value that indicates whether the receiver handles multi-touch events.

@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled

DiscussionWhen 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 propertyis NO.

Other views in the same window can still receive touch events when this property is NO. If you want this viewto handle multi-touch events exclusively, set the values of both this property and the exclusiveTouch (page31) property to YES.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property exclusiveTouch (page 31)

Related Sample CodeaurioTouch2

Declared inUIView.h

opaque

A Boolean value that determines whether the view is opaque.

@property(nonatomic, getter=isOpaque) BOOL opaque

DiscussionThis property provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawingsystem treats the view as fully opaque, which allows the drawing system to optimize some drawing operationsand 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 content—that is, the content should havean alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partiallytransparent content, the results are unpredictable. You should always set the value of this property to NO ifthe view is fully or partially transparent.

UIView Class ReferenceProperties

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

35

Page 36: UIView_Class123

AvailabilityAvailable in iOS 2.0 and later.

See Also @property backgroundColor (page 26) @property alpha (page 24)

Related Sample CodeAVMovieExporterMapCalloutsNavBarpARkUICatalog

Declared inUIView.h

restorationIdentifier

The identifier that determines whether the view supports state restoration.

@property(nonatomic, copy) NSString *restorationIdentifier

DiscussionThis property indicates whether state information in the view should be preserved; it is also used to identifythe view during the restoration process. The value of this property is nil by default, which indicates that theview’s state does not need to be saved. Assigning a string object to the property lets the owning view controllerknow 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 theencodeRestorableStateWithCoder: (page 83) and decodeRestorableStateWithCoder: (page 78) methodsfor saving and restoring state. You use those methods to write any view-specific state information andsubsequently 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 preservedand restored. Its owning view controller, and all of that view controller's parent view controllers, must alsohave a restoration identifier. For more information about the preservation and restoration process, see iOSApp Programming Guide .

AvailabilityAvailable in iOS 6.0 and later.

UIView Class ReferenceProperties

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

36

Page 37: UIView_Class123

Declared inUIView.h

subviews

The receiver’s immediate subviews. (read-only)

@property(nonatomic, readonly, copy) NSArray *subviews

DiscussionYou can use this property to retrieve the subviews associated with your custom view hierarchies. The order ofthe subviews in the array reflects their visible order on the screen, with the view at index 0 being the back-mostview.

For complex views declared in UIKit and other system frameworks, any subviews of the view are generallyconsidered private and subject to change at any time. Therefore, you should not attempt to retrieve or modifysubviews for these types of system-supplied views. If you do, your code may break during a future systemupdate.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property superview (page 37)– removeFromSuperview (page 97)

Related Sample CodePageControlSimpleNetworkStreams

Declared inUIView.h

superview

The receiver’s superview, or nil if it has none. (read-only)

@property(nonatomic, readonly) UIView *superview

AvailabilityAvailable in iOS 2.0 and later.

See Also @property subviews (page 37)

UIView Class ReferenceProperties

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

37

Page 38: UIView_Class123

– removeFromSuperview (page 97)

Related Sample CodeDateCellHandling Touches Using Responder Methods and Gesture RecognizersWiTap

Declared inUIView.h

tag

An integer that you can use to identify view objects in your application.

@property(nonatomic) NSInteger tag

DiscussionThe default value is 0. You can set the value of this tag and use that value to identify the view later.

AvailabilityAvailable in iOS 2.0 and later.

See Also– viewWithTag: (page 112)

Related Sample CodeAudio Mixer (MixerHost)GenericKeychainiPhoneCoreDataRecipesiPhoneMultichannelMixerTestLocateMe

Declared inUIView.h

tintAdjustmentMode

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

UIView Class ReferenceProperties

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

38

Page 39: UIView_Class123

@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode

DiscussionWhen this property’s value is UIViewTintAdjustmentModeDimmed (page 125), the value of the tintColor (page39) 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 valueis UIViewTintAdjustmentModeNormal (page 124).

When this property’s value changes (either by the view’s value changing or by one of its superview’s valueschanging), -the system calls the tintColorDidChange (page 108) method to allow the view to refresh itsrendering.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

tintColor

The first nondefault tint color value in the view’s hierarchy, ascending from and starting with the view itself.

@property(nonatomic, retain) UIColor *tintColor

DiscussionIf the system cannot find a nondefault color in the hierarchy, this property’s value is a system-defined colorinstead.

If the view’s tintAdjustmentMode (page 38) property’s value is UIViewTintAdjustmentModeDimmed (page125), 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.

AvailabilityAvailable in iOS 7.0 and later.

See Also– tintColorDidChange (page 108)

UIView Class ReferenceProperties

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

39

Page 40: UIView_Class123

Declared inUIView.h

transform

Specifies the transform applied to the receiver, relative to the center of its bounds.

@property(nonatomic) CGAffineTransform transform

DiscussionThe origin of the transform is the value of the center (page 27) property, or the layer’s anchorPoint propertyif it was changed. (Use the layer (page 34) property to get the underlying Core Animation layer object.) Thedefault value is CGAffineTransformIdentity.

Changes to this property can be animated. Use the beginAnimations:context: (page 49) class method tobegin and the commitAnimations (page 50) class method to end an animation block. The default is whateverthe 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.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property frame (page 31) @property bounds (page 26) @property center (page 27)

Related Sample CodeaurioTouch2Handling Touches Using Responder Methods and Gesture RecognizersRosyWriterSquareCam

Declared inUIView.h

userInteractionEnabled

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

UIView Class ReferenceProperties

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

40

Page 41: UIView_Class123

@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled

DiscussionWhen set to NO, user events—such as touch and keyboard—intended for the view are ignored and removedfrom the event queue. When set to YES, events are delivered to the view normally. The default value of thisproperty is YES.

During an animation, user interactions are temporarily disabled for all views involved in the animation, regardlessof the value in this property. You can disable this behavior by specifying theUIViewAnimationOptionAllowUserInteraction (page 115) option when configuring the animation.

Note: Some UIKit subclasses override this property and return a different default value. See thedocumentation for that class to determine if it returns a different value.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

window

The receiver’s window object, or nil if it has none. (read-only)

@property(nonatomic, readonly) UIWindow *window

DiscussionThis property is nil if the view has not yet been added to a window.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

Class Methods

addKeyframeWithRelativeStartTime:relativeDuration:animations:

Specifies the timing and animation values for a single frame of a keyframe animation.

UIView Class ReferenceClass Methods

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

41

Page 42: UIView_Class123

+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTimerelativeDuration:(double)frameDuration animations:(void (^)(void))animations

ParametersframeStartTime

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

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

animationsA block object containing the animations you want to perform. This is where you programmaticallychange any animatable properties of the views in your view hierarchy. This block takes no parametersand has no return value. This parameter must not be nil.

DiscussionTo animate view properties during a keyframe animation, call this method from within the animation blockyou pass to theanimateKeyframesWithDuration:delay:options:animations:completion:method.To animate between different values, or to tweak the timing of your view property animations, you can callthis method multiple times within a block.

The view properties you change in the animations block animate over the timespan you specify inframeDuration parameter. The properties do not begin animating until the time you specify in theframeStartTime parameter. After the frame start time, the animation executes over its specified durationor until interrupted by another animation.

AvailabilityAvailable in iOS 7.0 and later.

See Also+ animateKeyframesWithDuration:delay:options:animations:completion: (page 43)

Declared inUIView.h

UIView Class ReferenceClass Methods

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

42

Page 43: UIView_Class123

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)durationdelay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)optionsanimations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

Parametersduration

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

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

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

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

completionA block object to be executed when the animation sequence ends. This block has no return value andtakes a single Boolean argument that indicates whether or not the animations finished before thecompletion handler was called. If the duration of the animation is 0, this block is performed at thebeginning of the next run loop cycle. You can use a nil value for this parameter.

DiscussionThis method creates an animation block that you can use to set up a keyframe-based animation. The keyframesthemselves are not part of the initial animation block you create using this method. Inside the animationsblock, you must add the keyframe time and animation data by calling theaddKeyframeWithRelativeStartTime: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 firstkeyframe, 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 astandard animation block. In other words, the system animates from the current view values to any new valuesover the specified duration.

UIView Class ReferenceClass Methods

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

43

Page 44: UIView_Class123

AvailabilityAvailable in iOS 7.0 and later.

See Also+ addKeyframeWithRelativeStartTime:relativeDuration:animations: (page 41)

Declared inUIView.h

animateWithDuration:animations:

Animate changes to one or more views using the specified duration.

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations

Parametersduration

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

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

DiscussionThis method performs the specified animations immediately using theUIViewAnimationOptionCurveEaseInOut (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.)

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodeHeadsUpUIiAdSuiteMoveMeSimple Gesture RecognizersUIImagePicker Video Recorder

UIView Class ReferenceClass Methods

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

44

Page 45: UIView_Class123

Declared inUIView.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

Parametersduration

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

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

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

DiscussionThis method performs the specified animations immediately using theUIViewAnimationOptionCurveEaseInOut (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.)

UIView Class ReferenceClass Methods

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

45

Page 46: UIView_Class123

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodeAVPlayerDemoDateCelliAdInterstitialSuiteSquareCamStitchedStreamPlayer

Declared inUIView.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)delayoptions:(UIViewAnimationOptions)options animations:(void (^)(void))animationscompletion:(void (^)(BOOL finished))completion

Parametersduration

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

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

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

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

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

UIView Class ReferenceClass Methods

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

46

Page 47: UIView_Class123

DiscussionThis method initiates a set of animations to perform on the view. The block object in the animations parametercontains 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.

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodeAirDrop ExamplesUIImagePicker Video RecorderUnwindSegue

Declared inUIView.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)delayusingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocityoptions:(UIViewAnimationOptions)options animations:(void (^)(void))animationscompletion:(void (^)(BOOL finished))completion

Parametersduration

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

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

dampingRatioThe 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 closerto zero to increase oscillation.

UIView Class ReferenceClass Methods

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

47

Page 48: UIView_Class123

velocityThe initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as itwas prior to attachment.

A value of 1 corresponds to the total animation distance traversed in one second. For example, if thetotal animation distance is 200 points and you want the start of the animation to match a view velocityof 100 pt/s, use a value of 0.5.

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

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

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

Discussion

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

areAnimationsEnabled

Returns a Boolean value indicating whether animations are enabled.

+ (BOOL)areAnimationsEnabled

Return ValueYES if animations are enabled; otherwise, NO.

AvailabilityAvailable in iOS 2.0 and later.

UIView Class ReferenceClass Methods

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

48

Page 49: UIView_Class123

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

Related Sample CodeiAdSuite

Declared inUIView.h

beginAnimations:context:

Marks the beginning of a begin/commit animation block.

+ (void)beginAnimations:(NSString *)animationID context:(void *)context

ParametersanimationID

An application-supplied identifier for the animations.

contextCustom data that you want to associate with this set of animations. information that is passed to theanimation delegate messages—the selectors set using the setAnimationWillStartSelector: (page64) and setAnimationDidStopSelector: (page 57) methods.

DiscussionThis method signals to the system that you want to specify one or more animations to perform. After callingthis method, configure the animation options (using the setAnimation… class methods) and then changethe desired animatable properties of your views. When you are done changing your view properties, call thecommitAnimations (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 forthe nested group.

If you install a start or stop selector using the setAnimationWillStartSelector: (page 64) orsetAnimationDidStopSelector: (page 57) method, the values you specify for the animationID and contextparameters are passed to your selectors at runtime. You can use these parameters to pass additional informationto those selectors.

Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods tospecify your animations instead.

UIView Class ReferenceClass Methods

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

49

Page 50: UIView_Class123

AvailabilityAvailable in iOS 2.0 and later.

See Also+ commitAnimations (page 50)+ setAnimationWillStartSelector: (page 64)+ setAnimationDidStopSelector: (page 57)+ setAnimationDelegate: (page 56)

Related Sample CodeAdvancedURLConnectionsHandling Touches Using Responder Methods and Gesture RecognizersKeyboardAccessoryLocateMeUICatalog

Declared inUIView.h

commitAnimations

Marks the end of a begin/commit animation block and schedules the animations for execution.

+ (void)commitAnimations

DiscussionIf the current animation set is the outermost set, this method starts the animations when the application returnsto the run loop. If the current animation set is nested inside another set, this method waits until the outermostset 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 bepiled on top of one another. See setAnimationBeginsFromCurrentState: (page 53) for how to start animationswhile others are in progress.

Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods tospecify your animations instead.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)

UIView Class ReferenceClass Methods

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

50

Page 51: UIView_Class123

Related Sample CodeAdvancedURLConnectionsHandling Touches Using Responder Methods and Gesture RecognizersKeyboardAccessoryLocateMeUICatalog

Declared inUIView.h

layerClass

Returns the class used to create the layer for instances of this class.

+ (Class)layerClass

Return ValueThe class used to create the view’s Core Animation layer.

DiscussionThis method returns the CALayer class object by default. Subclasses can override this method and return adifferent layer class as needed. For example, if your view uses tiling to display a large scrollable area, you mightwant 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 layerobject.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property layer (page 34)

Related Sample CodeGLES2SampleGLImageProcessingGLTextureAtlasPVRTextureLoaderSpeakHere

Declared inUIView.h

UIView Class ReferenceClass Methods

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

51

Page 52: UIView_Class123

performSystemAnimation:onViews:options:animations:completion:

Performs a specified system-provided animation on one or more views, along with optional parallel animationsthat you define.

+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)viewsoptions:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimationscompletion:(void (^)(BOOL finished))completion

Parametersanimation

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

viewsThe views to perform the animations on.

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

parallelAnimationsAdditional animations you specify to run alongside the system animation, with the same timing andduration that the system animation defines or inherits.

In your additional animations, do not modify properties of the view on which the system animation isbeing performed.

completionA block object to be executed when the animation sequence ends. The single Boolean argument indicateswhether or not the animations finished before the completion handler was called. If the animationduration is 0, this block is performed at the beginning of the next run-loop cycle. You can use a nil valuefor this parameter.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

performWithoutAnimation:

Disables a view transition animation.

+ (void)performWithoutAnimation:(void (^)(void))actionsWithoutAnimation

UIView Class ReferenceClass Methods

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

52

Page 53: UIView_Class123

ParametersactionsWithoutAnimation

The view transition code that you want to perform without animation.

AvailabilityAvailable in iOS 7.0 and later.

See Also+ setAnimationsEnabled: (page 61)+ areAnimationsEnabled (page 48)

Declared inUIView.h

requiresConstraintBasedLayout

Returns whether the receiver depends on the constraint-based layout system.

+ (BOOL)requiresConstraintBasedLayout

Return ValueYES if the view must be in a window using constraint-based layout to function properly, NO otherwise.

DiscussionCustom views should override this to return YES if they can not layout correctly using autoresizing.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

setAnimationBeginsFromCurrentState:

Sets whether the animation should begin playing from the current state.

+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState

ParametersfromCurrentState

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

UIView Class ReferenceClass Methods

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

53

Page 54: UIView_Class123

DiscussionIf set to YES when an animation is in flight, the current view position of the in-flight animation is used as thestarting state for the new animation. If set to NO, the in-flight animation ends before the new animation beginsusing the last view position as the starting state. This method does nothing if an animation is not in flight orinvoked outside of an animation block. Use the beginAnimations:context: (page 49) class method to startand 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 usetheanimateWithDuration:delay:options:animations:completion: (page 46) method to specify youranimations and the animation options.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDuration: (page 58)+ setAnimationDelay: (page 55)+ setAnimationCurve: (page 54)+ setAnimationRepeatCount: (page 60)+ setAnimationRepeatAutoreverses: (page 59)

Declared inUIView.h

setAnimationCurve:

Sets the curve to use when animating property changes within an animation block.

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve

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

UIView Class ReferenceClass Methods

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

54

Page 55: UIView_Class123

Use of this method is discouraged in iOS 4.0 and later. Instead, you should usetheanimateWithDuration:delay:options:animations:completion: (page 46) method to specify youranimations and the animation curve options.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDuration: (page 58)+ setAnimationDelay: (page 55)+ setAnimationRepeatCount: (page 60)+ setAnimationRepeatAutoreverses: (page 59)+ setAnimationBeginsFromCurrentState: (page 53)

Related Sample CodeAdvancedURLConnectionsMultipeerGroupChat

Declared inUIView.h

setAnimationDelay:

Sets the amount of time (in seconds) to wait before animating property changes within an animation block.

+ (void)setAnimationDelay:(NSTimeInterval)delay

DiscussionIf you specify your animations using begin/commit set of methods, you use this method to specify the amountof time to wait before starting the animations. This method does nothing if called from outside of an animationblock. It must be called between calls to the beginAnimations:context: (page 49) andcommitAnimations (page 50) methods. And you must call this method prior to changing the animatableproperties 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 usetheanimateWithDuration:delay:options:animations:completion: (page 46) method to specify youranimations and the starting delay.

AvailabilityAvailable in iOS 2.0 and later.

UIView Class ReferenceClass Methods

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

55

Page 56: UIView_Class123

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDuration: (page 58)+ setAnimationCurve: (page 54)+ setAnimationRepeatCount: (page 60)+ setAnimationRepeatAutoreverses: (page 59)+ setAnimationBeginsFromCurrentState: (page 53)

Declared inUIView.h

setAnimationDelegate:

Sets the delegate for any animation messages.

+ (void)setAnimationDelegate:(id)delegate

Parametersdelegate

An object that defines the methods registered using the setAnimationWillStartSelector: (page 64)and setAnimationDidStopSelector: (page 57) methods. The view maintains a strong reference to thisobject for the duration of the animation.

DiscussionYou can specify an animation delegate in cases where you want to receive messages when the animation startsor stops. After calling this method, you should call the setAnimationWillStartSelector: (page 64) andsetAnimationDidStopSelector: (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/commitanimation 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 delegate’s start and end code directly inside your block.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)

UIView Class ReferenceClass Methods

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

56

Page 57: UIView_Class123

+ commitAnimations (page 50)+ setAnimationWillStartSelector: (page 64)+ setAnimationDidStopSelector: (page 57)

Related Sample CodeAQOfflineRenderTestiPhoneMultichannelMixerTestMoveMeTheElements

Declared inUIView.h

setAnimationDidStopSelector:

Sets the message to send to the animation delegate when animation stops.

+ (void)setAnimationDidStopSelector:(SEL)selector

Parametersselector

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

animationID

An NSString containing an optional application-supplied identifier. This is the identifier that is passedto 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 completionbefore it stopped or NO if it did not.

context

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

UIView Class ReferenceClass Methods

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

57

Page 58: UIView_Class123

DiscussionIf you specify an animation delegate for a begin/commit set of animations, you use this method to specify theselector to call after the animations end. This method does nothing if called from outside of an animationblock. It must be called between calls to the beginAnimations:context: (page 49) andcommitAnimations (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 delegate’s end code directly inside your block.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationDelegate: (page 56)+ setAnimationWillStartSelector: (page 64)

Related Sample CodeAQOfflineRenderTestiPhoneMultichannelMixerTestMoveMeTheElements

Declared inUIView.h

setAnimationDuration:

Sets the duration (measured in seconds) of the animations in an animation block.

+ (void)setAnimationDuration:(NSTimeInterval)duration

Parametersduration

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

UIView Class ReferenceClass Methods

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

58

Page 59: UIView_Class123

DiscussionIf you specify your animations using begin/commit set of methods, you use this method to specify the durationof the animations. This method does nothing if called from outside of an animation block. It must be calledbetween calls to the beginAnimations:context: (page 49) and commitAnimations (page 50) methods. Andyou must call this method prior to changing the animatable properties of your views. The default value is 0.2seconds.

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use any of the block-based animationmethods to specify your animations and their duration.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDelay: (page 55)+ setAnimationCurve: (page 54)+ setAnimationRepeatCount: (page 60)+ setAnimationRepeatAutoreverses: (page 59)+ setAnimationBeginsFromCurrentState: (page 53)

Related Sample CodeKeyboardAccessoryLocateMeMoveMeTheElementsUICatalog

Declared inUIView.h

setAnimationRepeatAutoreverses:

Sets whether the animations within an animation block automatically reverse themselves.

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses

ParametersrepeatAutoreverses

Specify YES to enable autoreversing or NO to disable it.

UIView Class ReferenceClass Methods

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

59

Page 60: UIView_Class123

DiscussionIf you enable autoreversing, a single animation cycle changes the properties being animated to their newvalues and then back to their original values. At the end of the animations, the affected views are then updatedimmediately 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 specifiednumber of times. However, remember that the repeat count indicates the number of complete cycles. If youspecify an integral value such as 2.0, the animation ends on the old value, which is followed by the viewimmediately updating itself to show the new value, which might be jarring. If you want the animation to endon the new value (instead of the old value), add 0.5 to the repeat count value. This adds an extra half cycleto the animation.

Use of this method is discouraged in iOS 4.0 and later. Instead, you should usetheanimateWithDuration:delay:options:animations:completion: (page 46) method to specify youranimations and the animation options.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDuration: (page 58)+ setAnimationDelay: (page 55)+ setAnimationCurve: (page 54)+ setAnimationRepeatCount: (page 60)+ setAnimationBeginsFromCurrentState: (page 53)

Declared inUIView.h

setAnimationRepeatCount:

Sets the number of times animations within an animation block repeat.

+ (void)setAnimationRepeatCount:(float)repeatCount

UIView Class ReferenceClass Methods

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

60

Page 61: UIView_Class123

ParametersrepeatCount

The number of times animations repeat. This value can be a fraction. If you specify the value 0, theanimation is performed once without repeating.

DiscussionUse this method to specify the number of times to repeat the specified animations. This method does nothingif called from outside of an animation block. You can use this method in conjunction with either the block-basedmethods or the begin/commit methods for defining an animation block. If you do not explicitly set a repeatcount, the animation is not repeated.

If you pass the UIViewAnimationOptionRepeat (page 115) option to theanimateWithDuration:delay:options:animations:completion: (page 46) method without setting anexplicit repeat count, the animation repeats indefinitely. If you want the animation to repeat a finite numberof times, call this method from inside your block.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationStartDate: (page 62)+ setAnimationDuration: (page 58)+ setAnimationDelay: (page 55)+ setAnimationCurve: (page 54)+ setAnimationRepeatAutoreverses: (page 59)+ setAnimationBeginsFromCurrentState: (page 53)

Declared inUIView.h

setAnimationsEnabled:

Sets whether animations are enabled.

+ (void)setAnimationsEnabled:(BOOL)enabled

Parametersenabled

Specify YES to enable animations or NO to disable them.

UIView Class ReferenceClass Methods

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

61

Page 62: UIView_Class123

DiscussionAnimations are enabled by default. If you disable animations, code inside subsequent animation blocks is stillexecuted but no animations actually occur. Thus, any changes you make inside an animation block are reflectedimmediately instead of being animated. This is true whether you use the block-based animation methods orthe begin/commit animation methods.

This method affects only those animations that are submitted after it is called. If you call this method whileexisting animations are running, those animations continue running until they reach their natural end point.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ areAnimationsEnabled (page 48)+ performWithoutAnimation: (page 52)

Declared inUIView.h

setAnimationStartDate:

Sets the start time for the current animation block.

+ (void)setAnimationStartDate:(NSDate *)startTime

ParametersstartTime

The time to begin the animations.

DiscussionCall 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 theanimatable 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 CFAbsoluteTimeGetCurrentfunction, 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 tospecify your animations instead.

AvailabilityAvailable in iOS 2.0 and later.

UIView Class ReferenceClass Methods

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

62

Page 63: UIView_Class123

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationDuration: (page 58)+ setAnimationDelay: (page 55)+ setAnimationCurve: (page 54)+ setAnimationRepeatCount: (page 60)+ setAnimationRepeatAutoreverses: (page 59)+ setAnimationBeginsFromCurrentState: (page 53)

Declared inUIView.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

Parameterstransition

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

viewThe view to apply the transition to.

cacheIf YES, the before and after images of view are rendered once and used to create the frames in theanimation. Caching can improve performance but if you set this parameter to YES, you must not updatethe view or its subviews during the transition. Updating the view and its subviews may interfere with thecaching 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 maynoticeably affect the frame rate.

DiscussionIf you want to change the appearance of a view during a transition—for example, flip from one view toanother—then use a container view, an instance of UIView, as follows:

1. Begin an animation block.

2. Set the transition on the container view.

UIView Class ReferenceClass Methods

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

63

Page 64: UIView_Class123

3. Remove the subview from the container view.

4. Add the new subview to the container view.

5. Commit the animation block.

Use of this method is discouraged in iOS 4.0 and later. You should use thetransitionWithView:duration:options:animations:completion: (page 67) method to perform transitionsinstead.

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeAQOfflineRenderTestBreadcrumbiPhoneMultichannelMixerTestTheElementsUICatalog

Declared inUIView.h

setAnimationWillStartSelector:

Sets the message to send to the animation delegate when the animation starts.

+ (void)setAnimationWillStartSelector:(SEL)selector

Parametersselector

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

animationID

An NSString containing an optional application-supplied identifier. This is the identifier string that ispassed 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 thebeginAnimations:context: (page 49) method. This argument can be nil.

UIView Class ReferenceClass Methods

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

64

Page 65: UIView_Class123

DiscussionIf you specify an animation delegate for a begin/commit set of animations, you use this method to specify theselector to call before the animations begin. This method does nothing if called from outside of an animationblock. It must be called between calls to the beginAnimations:context: (page 49) andcommitAnimations (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 delegate’s start code directly inside your block.

AvailabilityAvailable in iOS 2.0 and later.

See Also+ beginAnimations:context: (page 49)+ commitAnimations (page 50)+ setAnimationDelegate: (page 56)+ setAnimationDidStopSelector: (page 57)

Declared inUIView.h

transitionFromView:toView:duration:options:completion:

Creates a transition animation between the specified views using the given parameters.

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toViewduration:(NSTimeInterval)duration options:(UIViewAnimationOptions)optionscompletion:(void (^)(BOOL finished))completion

ParametersfromView

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

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

UIView Class ReferenceClass Methods

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

65

Page 66: UIView_Class123

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

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

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

DiscussionThis method provides a simple way to transition from the view in the fromView parameter to the view in thetoView 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 theUIViewAnimationOptionShowHideTransitionViews (page 116) option in the options parameter to simplyhide or show them.

This method modifies the views in their view hierarchy only. It does not modify your application’s view controllersin any way. For example, if you use this method to change the root view displayed by a view controller, it isyour 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 startsimmediately 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.

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodePrefsInCloudViewTransitions

Declared inUIView.h

UIView Class ReferenceClass Methods

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

66

Page 67: UIView_Class123

transitionWithView:duration:options:animations:completion:

Creates a transition animation for the specified container view.

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)durationoptions:(UIViewAnimationOptions)options animations:(void (^)(void))animationscompletion:(void (^)(BOOL finished))completion

Parametersview

The container view that performs the transition.

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

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

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

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

DiscussionThis method applies a transition to the specified view so that you can make state changes to it. The block youspecify in the animations parameter contains whatever state changes you want to make. You can use thisblock to add, remove, show, or hide subviews of the specified view. If you want to incorporate other animatablechanges, you must include the UIViewAnimationOptionAllowAnimatedContent (page 116) key in the optionsparameter.

The following code creates a flip transition for the specified container view. At the appropriate point in thetransition, one subview is removed and another is added to the container view. This makes it look as if a newview was flipped into place with the new subview, but really it is just the same view animated back into placewith a new configuration.

[UIView transitionWithView:containerView

duration:0.2

UIView Class ReferenceClass Methods

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

67

Page 68: UIView_Class123

options:UIViewAnimationOptionTransitionFlipFromLeft

animations:^{ [fromView removeFromSuperview]; [containerViewaddSubview: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.

AvailabilityAvailable in iOS 4.0 and later.

Related Sample CodeAppPrefs

Declared inUIView.h

Instance Methods

addConstraint:

Adds a constraint on the layout of the receiving view or its subviews.

- (void)addConstraint:(NSLayoutConstraint *)constraint

Parametersconstraint

The constraint to be added to the view. The constraint may only reference the view itself or its subviews.

DiscussionThe constraint must involve only views that are within scope of the receiving view. Specifically, any viewsinvolved must be either the receiving view itself, or a subview of the receiving view. Constraints that are addedto a view are said to be held by that view. The coordinate system used when evaluating the constraint is thecoordinate system of the view that holds the constraint.

AvailabilityAvailable in iOS 6.0 and later.

UIView Class ReferenceInstance Methods

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

68

Page 69: UIView_Class123

Declared inUIView.h

addConstraints:

Adds multiple constraints on the layout of the receiving view or its subviews.

- (void)addConstraints:(NSArray *)constraints

Parametersconstraints

An array of constraints to be added to the view. All constraints may only reference the view itself or itssubviews.

DiscussionAll constraints must involve only views that are within scope of the receiving view. Specifically, any viewsinvolved must be either the receiving view itself, or a subview of the receiving view. Constraints that are addedto a view are said to be held by that view. The coordinate system used when evaluating each constraint is thecoordinate system of the view that holds the constraint.

AvailabilityAvailable in iOS 6.0 and later.

Related Sample CodePrefsInCloudViewTransitions

Declared inUIView.h

addGestureRecognizer:

Attaches a gesture recognizer to the view.

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

ParametersgestureRecognizer

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

UIView Class ReferenceInstance Methods

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

69

Page 70: UIView_Class123

DiscussionAttaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receivetouches hit-tested to that view and all of its subviews. The view establishes a strong reference to the gesturerecognizer.

AvailabilityAvailable in iOS 3.2 and later.

See Also– removeGestureRecognizer: (page 97) @property gestureRecognizers (page 32)

Related Sample CodeAVPlayerDemoDocInteractionPageControlStitchedStreamPlayer

Declared inUIView.h

addMotionEffect:

Begins applying a motion effect to the view.

- (void)addMotionEffect:(UIMotionEffect *)effect

Parameterseffect

The motion effect.

DiscussionThe system animates the transition to the motion effect's values using the present UIView animation context.The motion effect’s keyPath/value pairs are applied to the view’s presentation layer.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

70

Page 71: UIView_Class123

addSubview:

Adds a view to the end of the receiver’s list of subviews.

- (void)addSubview:(UIView *)view

Parametersview

The view to be added. After being added, this view appears on top of any other subviews.

DiscussionThis method establishes a strong reference to view and sets its next responder to the receiver, which is itsnew superview.

Views can have only one superview. If view already has a superview and that view is not the receiver, thismethod removes the previous superview before making the receiver its new superview.

AvailabilityAvailable in iOS 2.0 and later.

See Also– insertSubview:atIndex: (page 91)– insertSubview:aboveSubview: (page 90)– insertSubview:belowSubview: (page 91)– exchangeSubviewAtIndex:withSubviewAtIndex: (page 85)

Related Sample CodeGenericKeychainGeocoderDemoiAdSuiteiPhoneCoreDataRecipesUICatalog

Declared inUIView.h

alignmentRectForFrame:

Returns the view’s alignment rectangle for a given frame.

- (CGRect)alignmentRectForFrame:(CGRect)frame

UIView Class ReferenceInstance Methods

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

71

Page 72: UIView_Class123

Parametersframe

The frame whose corresponding alignment rectangle is desired.

Return ValueThe alignment rectangle for the specified frame.

DiscussionThe constraint-based layout system uses alignment rectangles to align views, rather than their frame. Thisallows custom views to be aligned based on the location of their content while still having a frame thatencompasses any ornamentation they need to draw around their content, such as shadows or reflections.

The default implementation returns the view’s frame modified by the view’s alignmentRectInsets (page 72).Most custom views can override alignmentRectInsets to specify the location of their content within theirframe. Custom views that require arbitrary transformations can override alignmentRectForFrame: andframeForAlignmentRect: (page 86) to describe the location of their content. These two methods must alwaysbe inverses of each other.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

alignmentRectInsets

Returns the insets from the view’s frame that define its alignment rectangle.

- (UIEdgeInsets)alignmentRectInsets

Return ValueThe insets from the view’s frame that define its alignment rectangle.

DiscussionThe default implementation of this method returns an NSEdgeInsets structure with zero values. Customviews that draw ornamentation around their content should override this method to return insets that alignwith the edges of the content, excluding the ornamentation. This allows the constraint-based layout systemto align views based on their content, rather than just their frame.

Custom views whose content location can’t be expressed by a simple set of insets should overridealignmentRectForFrame: (page 71) and frameForAlignmentRect: (page 86) to describe their customtransform between alignment rectangle and frame.

UIView Class ReferenceInstance Methods

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

72

Page 73: UIView_Class123

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

bringSubviewToFront:

Moves the specified subview so that it appears on top of its siblings.

- (void)bringSubviewToFront:(UIView *)view

Parametersview

The subview to move to the front.

DiscussionThis method moves the specified view to the end of the array of views in the subviews (page 37) property.

AvailabilityAvailable in iOS 2.0 and later.

See Also– sendSubviewToBack: (page 100)

Declared inUIView.h

constraints

Returns the constraints held by the view.

- (NSArray *)constraints

Return ValueThe constraints held by the view.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

73

Page 74: UIView_Class123

constraintsAffectingLayoutForAxis:

Returns the constraints impacting the layout of the view for a given axis.

- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis

Parametersaxis

The axis for which the constraints should be found.

Return ValueThe constraints impacting the layout of the view for the specified axis.

DiscussionThe returned set of constraints may not all include the view explicitly. Constraints that impact the location ofthe view implicitly may also be included. While this provides a good starting point for debugging, there is noguarantee that the returned set of constraints will include all of the constraints that have an impact on theview’s layout in the given orientation.

This method should only be used for debugging constraint-based layout. No application should ship with callsto this method as part of its operation.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

contentCompressionResistancePriorityForAxis:

Returns the priority with which a view resists being made smaller than its intrinsic size.

-(UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis

Parametersaxis

The axis of the view that might be reduced.

Return ValueThe priority with which the view should resist being compressed from its intrinsic size on the specified axis.

UIView Class ReferenceInstance Methods

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

74

Page 75: UIView_Class123

DiscussionThe constraint-based layout system uses these priorities when determining the best layout for views that areencountering 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 contenton creation, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh.

AvailabilityAvailable in iOS 6.0 and later.

See Also– setContentCompressionResistancePriority:forAxis: (page 100)

Declared inUIView.h

contentHuggingPriorityForAxis:

Returns the priority with which a view resists being made larger than its intrinsic size.

- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis

Parametersaxis

The axis of the view that might be enlarged.

Return ValueThe priority with which the view should resist being enlarged from its intrinsic size on the specified axis.

DiscussionThe constraint-based layout system uses these priorities when determining the best layout for views that areencountering constraints that would require them to be larger than their intrinsic size.

AvailabilityAvailable in iOS 6.0 and later.

See Also– setContentHuggingPriority:forAxis: (page 101)

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

75

Page 76: UIView_Class123

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

Parameterspoint

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

viewThe view with point in its coordinate system. If view is nil, this method instead converts from windowbase coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

Return ValueThe point converted to the local coordinate system (bounds) of the receiver.

AvailabilityAvailable in iOS 2.0 and later.

See Also– convertPoint:toView: (page 76)– convertRect:toView: (page 78)– convertRect:fromView: (page 77)

Declared inUIView.h

convertPoint:toView:

Converts a point from the receiver’s coordinate system to that of the specified view.

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view

Parameterspoint

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

viewThe view into whose coordinate system point is to be converted. If view is nil, this method insteadconverts to window base coordinates. Otherwise, both view and the receiver must belong to the sameUIWindow object.

UIView Class ReferenceInstance Methods

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

76

Page 77: UIView_Class123

Return ValueThe point converted to the coordinate system of view.

AvailabilityAvailable in iOS 2.0 and later.

See Also– convertPoint:fromView: (page 76)– convertRect:toView: (page 78)– convertRect:fromView: (page 77)

Related Sample CodeHandling Touches Using Responder Methods and Gesture Recognizers

Declared inUIView.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

Parametersrect

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

viewThe view with rect in its coordinate system. If view is nil, this method instead converts from windowbase coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

Return ValueThe converted rectangle.

AvailabilityAvailable in iOS 2.0 and later.

See Also– convertPoint:toView: (page 76)– convertPoint:fromView: (page 76)– convertRect:toView: (page 78)

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

77

Page 78: UIView_Class123

convertRect:toView:

Converts a rectangle from the receiver’s coordinate system to that of another view.

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view

Parametersrect

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

viewThe view that is the target of the conversion operation. If view is nil, this method instead converts towindow base coordinates. Otherwise, both view and the receiver must belong to the same UIWindowobject.

Return ValueThe converted rectangle.

AvailabilityAvailable in iOS 2.0 and later.

See Also– convertPoint:toView: (page 76)– convertPoint:fromView: (page 76)– convertRect:fromView: (page 77)

Declared inUIView.h

decodeRestorableStateWithCoder:

Decodes and restores state-related information for the view.

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder

Parameterscoder

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

UIView Class ReferenceInstance Methods

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

78

Page 79: UIView_Class123

DiscussionIf your app supports state restoration, you should override this method for any views for which you alsooverrode the encodeRestorableStateWithCoder: method. Your implementation of this method shoulduse any saved state information to restore the view to its previous configuration. If yourencodeRestorableStateWithCoder: method called super, this method should similarly call super atsome point in its implementation.

AvailabilityAvailable in iOS 6.0 and later.

See Also– encodeRestorableStateWithCoder: (page 83)

Declared inUIView.h

didAddSubview:

Tells the view that a subview was added.

- (void)didAddSubview:(UIView *)subview

Parameterssubview

The view that was added as a subview.

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions when subviews are added. This method is called in response to adding a subview using any of therelevant view methods.

AvailabilityAvailable 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 inUIView.h

UIView Class ReferenceInstance Methods

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

79

Page 80: UIView_Class123

didMoveToSuperview

Tells the view that its superview changed.

- (void)didMoveToSuperview

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions whenever the superview changes.

AvailabilityAvailable in iOS 2.0 and later.

See Also– willMoveToSuperview: (page 112)

Declared inUIView.h

didMoveToWindow

Tells the view that its window object changed.

- (void)didMoveToWindow

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions whenever the window changes.

The window (page 41) property may be nil by the time that this method is called, indicating that the receiverdoes not currently reside in any window. This occurs when the receiver has just been removed from its superviewor when the receiver has just been added to a superview that is not attached to a window. Overrides of thismethod may choose to ignore such cases if they are not of interest.

AvailabilityAvailable in iOS 2.0 and later.

See Also– willMoveToWindow: (page 113)

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

80

Page 81: UIView_Class123

drawRect:

Draws the receiver’s image within the passed-in rectangle.

- (void)drawRect:(CGRect)rect

Parametersrect

The portion of the view’s bounds that needs to be updated. The first time your view is drawn, this rectangleis typically the entire visible bounds of your view. However, during subsequent drawing operations, therectangle may specify only part of your view.

DiscussionThe default implementation of this method does nothing. Subclasses that use technologies such as CoreGraphics and UIKit to draw their view’s content should override this method and implement their drawingcode 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 itscontent directly using the underlying layer object.

By the time this method is called, UIKit has configured the drawing environment appropriately for your viewand 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 thatits origin matches the origin of your view’s bounds rectangle. You can get a reference to the graphics contextusing the UIGraphicsGetCurrentContext function, but do not establish a strong reference to the graphicscontext 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 EScontext appropriately for your view before calling this method (or the glkView:drawInRect: method ofyour GLKView delegate), so you can simply issue whatever OpenGL ES commands you need to render yourcontent. For more information about how to draw using OpenGL ES, see OpenGL ES Programming Guide foriOS .

You should limit any drawing to the rectangle specified in the rect parameter. In addition, if the opaque (page35) property of your view is set to YES, your drawRect: method must totally fill the specified rectangle withopaque 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 ofthe view. You should never call this method directly yourself. To invalidate part of your view, and thus causethat portion to be redrawn, call the setNeedsDisplay (page 102) or setNeedsDisplayInRect: (page 103)method instead.

UIView Class ReferenceInstance Methods

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

81

Page 82: UIView_Class123

AvailabilityAvailable in iOS 2.0 and later.

See Also– setNeedsDisplay (page 102)– setNeedsDisplayInRect: (page 103) @property contentMode (page 29)

Declared inUIView.h

drawRect:forViewPrintFormatter:

Implemented to draw the view’s content for printing.

- (void)drawRect:(CGRect)area forViewPrintFormatter:(UIViewPrintFormatter *)formatter

Parametersarea

A rectangle that defines the area for drawing printable content.

formatterAn instance ofUIViewPrintFormatterobtained by calling the viewPrintFormatter (page 111) method.

DiscussionYou implement this method if you want a view’s printed content to appear differently than its displayedcontent. If you add a view print formatter to a print job but do not implement this method, the view’sdrawRect: (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 Drawingand Printing Guide for iOS .

AvailabilityAvailable in iOS 4.2 and later.

Declared inUIPrintFormatter.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

UIView Class ReferenceInstance Methods

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

82

Page 83: UIView_Class123

Parametersrect

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

afterUpdatesA Boolean value that indicates whether the snapshot should be rendered after recent changes have beenincorporated. Specify the value NO if you want to render a snapshot in the view hierarchy’s current state,which might not include recent changes.

Return ValueReturns YES if the snapshot is complete, or NO if the snapshot is missing image data for any view in the hierarchy.

DiscussionUse this method when you want to apply a graphical effect, such as a blur, to a view snapshot. This methodis not as fast as the snapshotViewAfterScreenUpdates: (page 107) method.

AvailabilityAvailable in iOS 7.0 and later.

See Also– snapshotViewAfterScreenUpdates: (page 107)

Declared inUIView.h

encodeRestorableStateWithCoder:

Encodes state-related information for the view.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder

Parameterscoder

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

DiscussionIf your app supports state preservation, you can override this method for any views that have state informationthat should be saved between launches of your app. You should save only the data required to return the viewto its current configuration. Do not save the view object itself and do not save any data that could be determinedby other means at launch time.

UIView Class ReferenceInstance Methods

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

83

Page 84: UIView_Class123

Few views should need to save state information. Most views should just be configured using the data fromtheir view controller. However, this method is available for those views that have user-configurable state thatwould be otherwise lost between app launches.

Your implementation of this method can encode other restorable view and view controller objects that it needsto reference. Encoding a restorable view or view controller writes that object’s restoration identifier to thecoder. (That identifier is used during the decode process to locate the new version of the object.) If the viewor view controller defines its own own version of this method, that method is also called at some point so thatthe object can encode its own state.

Apart from views and view controllers, other objects follow the normal serialization process and must adoptthe NSCoding protocol before they can be encoded. Encoding such objects embeds the object’s contents inthe archive directly. During the decode process, a new object is created and initialized with the data from thearchive.

It is recommended that you call super at some point during your implementation to give parent classes anopportunity to save their state information.

AvailabilityAvailable in iOS 6.0 and later.

See Also– decodeRestorableStateWithCoder: (page 78)

Declared inUIView.h

endEditing:

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

- (BOOL)endEditing:(BOOL)force

Parametersforce

Specify YES to force the first responder to resign, regardless of whether it wants to do so.

Return ValueYES if the view resigned the first responder status or NO if it did not.

UIView Class ReferenceInstance Methods

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

84

Page 85: UIView_Class123

DiscussionThis method looks at the current view and its subview hierarchy for the text field that is currently the firstresponder. 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.

AvailabilityAvailable in iOS 2.0 and later.

Related Sample CodeMultipeerGroupChatSimple Core Data Relationships

Declared inUITextField.h

exchangeSubviewAtIndex:withSubviewAtIndex:

Exchanges the subviews at the specified indices.

- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2

Parametersindex1

The index of the first subview in the receiver.

index2The index of the second subview in the receiver.

DiscussionEach 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 changethe superview of either view but simply swaps their positions in the subviews (page 37) array.

AvailabilityAvailable in iOS 2.0 and later.

See Also– addSubview: (page 71)– insertSubview:atIndex: (page 91)– insertSubview:aboveSubview: (page 90)– insertSubview:belowSubview: (page 91)

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

85

Page 86: UIView_Class123

exerciseAmbiguityInLayout

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

- (void)exerciseAmbiguityInLayout

DiscussionThis method randomly changes the frame of a view with an ambiguous layout between its different validvalues, causing the view to move in the interface. This makes it easy to visually identify what the valid framesare and may enable the developer to discern what constraints need to be added to the layout to fully specifya location for the view.

This method should only be used for debugging constraint-based layout. No application should ship with callsto this method as part of its operation.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

frameForAlignmentRect:

Returns the view’s frame for a given alignment rectangle.

- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect

ParametersalignmentRect

The alignment rectangle whose corresponding frame is desired.

Return ValueThe frame for the specified alignment rectangle

DiscussionThe constraint-based layout system uses alignment rectangles to align views, rather than their frame. Thisallows custom views to be aligned based on the location of their content while still having a frame thatencompasses any ornamentation they need to draw around their content, such as shadows or reflections.

UIView Class ReferenceInstance Methods

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

86

Page 87: UIView_Class123

The default implementation returns alignmentRect modified by the view’s alignmentRectInsets (page72). Most custom views can override alignmentRectInsets to specify the location of their content withintheir frame. Custom views that require arbitrary transformations can override alignmentRectForFrame: (page71) and frameForAlignmentRect: to describe the location of their content. These two methods mustalways be inverses of each other.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

gestureRecognizerShouldBegin:

Asks the view if the gesture recognizer should be allowed to continue tracking touch events.

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

ParametersgestureRecognizer

The gesture recognizer that is attempting to transition out of theUIGestureRecognizerStatePossiblestate.

Return ValueYES if the gesture recognizer should continue tracking touch events and use them to trigger a gesture or NOif it should transition to the UIGestureRecognizerStateFailed state.

DiscussionSubclasses 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 slider’s travel direction and that startin the thumb.

At the time this method is called, the gesture recognizer is in the UIGestureRecognizerStatePossiblestate and thinks it has the events needed to move to the UIGestureRecognizerStateBegan state.

The default implementation of this method returns YES.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

87

Page 88: UIView_Class123

hasAmbiguousLayout

Returns whether the constraints impacting the layout of the view incompletely specify the location of the view.

- (BOOL)hasAmbiguousLayout

Return ValueYES if the view’s location is incompletely specified, NO otherwise.

DiscussionThis method checks to see if there is any other frame the view could have that would also satisfy the constraintson the view. This is an expensive operation and is not run as part of the normal layout process, but can beuseful when debugging whether a given interface has been specified with a sufficient number of constraintsto ensure consistent layout.

This method should only be used for debugging constraint-based layout. No application should ship with callsto this method as part of its operation.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

hitTest:withEvent:

Returns the farthest descendant of the receiver in the view hierarchy (including itself ) that contains a specifiedpoint.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

Parameterspoint

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

eventThe event that warranted a call to this method. If you are calling this method from outside yourevent-handling code, you may specify nil.

Return ValueThe view object that is the farthest descendent the current view and contains point. Returns nil if the pointlies completely outside the receiver’s view hierarchy.

UIView Class ReferenceInstance Methods

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

88

Page 89: UIView_Class123

DiscussionThis method traverses the view hierarchy by calling the pointInside:withEvent: (page 95) method of eachsubview to determine which subview should receive a touch event. If pointInside:withEvent: (page 95)returns YES, then the subview’s hierarchy is similarly traversed until the frontmost view containing the specifiedpoint is found. If a view does not contain the point, its branch of the view hierarchy is ignored. You rarely needto 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 levelless than 0.01. This method does not take the view’s content into account when determining a hit. Thus, aview can still be returned even if the specified point is in a transparent portion of that view’s content.

Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one ofthe receiver’s subviews. This can occur if the current view’s clipsToBounds (page 29) property is set to NO andthe affected subview extends beyond the view’s bounds.

AvailabilityAvailable in iOS 2.0 and later.

See Also– pointInside:withEvent: (page 95)

Declared inUIView.h

initWithFrame:

Initializes and returns a newly allocated view object with the specified frame rectangle.

- (id)initWithFrame:(CGRect)aRect

ParametersaRect

The frame rectangle for the view, measured in points. The origin of the frame is relative to the superviewin which you plan to add it. This method uses the frame rectangle to set the center (page 27) andbounds (page 26) properties accordingly.

Return ValueAn initialized view object or nil if the object couldn't be created.

UIView Class ReferenceInstance Methods

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

89

Page 90: UIView_Class123

DiscussionThe new view object must be inserted into the view hierarchy of a window before it can be used. If you createa view object programmatically, this method is the designated initializer for the UIView class. Subclasses canoverride this method to perform any custom initialization but must call super at the beginning of theirimplementation.

If you use Interface Builder to design your interface, this method is not called when your view objects aresubsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using theirinitWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nibfile. For detailed information about how views are loaded from a nib file, see Resource Programming Guide .

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

insertSubview:aboveSubview:

Inserts a view above another view in the view hierarchy.

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

Parametersview

The view to insert. It’s removed from its superview if it’s not a sibling of siblingSubview.

siblingSubviewThe sibling view that will be behind the inserted view.

DiscussionThis method establishes a strong reference to view and sets its next responder to the receiver, which is itsnew superview.

Views can have only one superview. If view already has a superview and that view is not the receiver, thismethod removes the previous superview before making the receiver its new superview.

AvailabilityAvailable in iOS 2.0 and later.

See Also– addSubview: (page 71)– insertSubview:atIndex: (page 91)

UIView Class ReferenceInstance Methods

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

90

Page 91: UIView_Class123

– insertSubview:belowSubview: (page 91)– exchangeSubviewAtIndex:withSubviewAtIndex: (page 85)

Declared inUIView.h

insertSubview:atIndex:

Inserts a subview at the specified index.

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index

Parametersview

The view to insert. This value cannot be nil.

indexThe index in the array of the subviews (page 37) property at which to insert the view. Subview indicesstart at 0 and cannot be greater than the number of subviews.

DiscussionThis method establishes a strong reference to view and sets its next responder to the receiver, which is itsnew superview.

Views can have only one superview. If view already has a superview and that view is not the receiver, thismethod removes the previous superview before making the receiver its new superview.

AvailabilityAvailable in iOS 2.0 and later.

See Also– addSubview: (page 71)– insertSubview:aboveSubview: (page 90)– insertSubview:belowSubview: (page 91)– exchangeSubviewAtIndex:withSubviewAtIndex: (page 85)

Declared inUIView.h

insertSubview:belowSubview:

Inserts a view below another view in the view hierarchy.

UIView Class ReferenceInstance Methods

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

91

Page 92: UIView_Class123

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

Parametersview

The view to insert below another view. It’s removed from its superview if it’s not a sibling ofsiblingSubview.

siblingSubviewThe sibling view that will be above the inserted view.

DiscussionThis method establishes a strong reference to view and sets its next responder to the receiver, which is itsnew superview.

Views can have only one superview. If view already has a superview and that view is not the receiver, thismethod removes the previous superview before making the receiver its new superview.

AvailabilityAvailable in iOS 2.0 and later.

See Also– addSubview: (page 71)– insertSubview:atIndex: (page 91)– insertSubview:aboveSubview: (page 90)– exchangeSubviewAtIndex:withSubviewAtIndex: (page 85)

Declared inUIView.h

intrinsicContentSize

Returns the natural size for the receiving view, considering only properties of the view itself.

- (CGSize)intrinsicContentSize

Return ValueA size indicating the natural size for the receiving view based on its intrinsic properties.

DiscussionCustom views typically have content that they display of which the layout system is unaware. Overriding thismethod allows a custom view to communicate to the layout system what size it would like to be based on itscontent. This intrinsic size must be independent of the content frame, because there’s no way to dynamicallycommunicate a changed width to the layout system based on a changed height, for example.

UIView Class ReferenceInstance Methods

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

92

Page 93: UIView_Class123

If a custom view has no intrinsic size for a given dimension, it can return UIViewNoIntrinsicMetric (page126) for that dimension.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

invalidateIntrinsicContentSize

Invalidates the view’s intrinsic content size.

- (void)invalidateIntrinsicContentSize

DiscussionCall this when something changes in your custom view that invalidates its intrinsic content size. This allowsthe constraint-based layout system to take the new intrinsic content size into account in its next layout pass.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.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

Parametersview

The view to test against the receiver’s view hierarchy.

Return ValueYES if the receiver is an immediate or distant subview of view or if view is the receiver itself; otherwise NO.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

93

Page 94: UIView_Class123

layoutIfNeeded

Lays out the subviews immediately.

- (void)layoutIfNeeded

DiscussionUse this method to force the layout of subviews before drawing. Using the view that receives the message asthe root view, this method lays out the view subtree starting at the root.

AvailabilityAvailable in iOS 2.0 and later.

See Also– setNeedsLayout (page 104)– layoutSubviews (page 94)

Declared inUIView.h

layoutSubviews

Lays out subviews.

- (void)layoutSubviews

DiscussionThe default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the defaultimplementation 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 shouldoverride this method only if the autoresizing and constraint-based behaviors of the subviews do not offer thebehavior 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 (page104) method instead to do so prior to the next drawing update. If you want to update the layout of your viewsimmediately, call the layoutIfNeeded (page 94) method.

AvailabilityAvailable in iOS 2.0 and later.

See Also– setNeedsLayout (page 104)

UIView Class ReferenceInstance Methods

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

94

Page 95: UIView_Class123

– layoutIfNeeded (page 94)

Related Sample CodeGLImageProcessingiPhoneCoreDataRecipesMVCNetworkingSpeakHereZoomingPDFViewer

Declared inUIView.h

needsUpdateConstraints

Returns whether the view’s constraints need updating.

- (BOOL)needsUpdateConstraints

Return ValueYES if the view’s constraints need updating, NO otherwise.

DiscussionThe constraint-based layout system uses the return value of this method to determine whether it needs to callupdateConstraints (page 110) on your view as part of its normal layout pass.

AvailabilityAvailable in iOS 6.0 and later.

See Also– setNeedsUpdateConstraints (page 104)

Declared inUIView.h

pointInside:withEvent:

Returns a Boolean value indicating whether the receiver contains the specified point.

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

Parameterspoint

A point that is in the receiver’s local coordinate system (bounds).

UIView Class ReferenceInstance Methods

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

95

Page 96: UIView_Class123

eventThe event that warranted a call to this method. If you are calling this method from outside yourevent-handling code, you may specify nil.

Return ValueYES if point is inside the receiver’s bounds; otherwise, NO.

AvailabilityAvailable in iOS 2.0 and later.

See Also– hitTest:withEvent: (page 88)

Declared inUIView.h

removeConstraint:

Removes the specified constraint from the view.

- (void)removeConstraint:(NSLayoutConstraint *)constraint

Parametersconstraint

The constraint to remove. Removing a constraint not held by the view has no effect.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

removeConstraints:

Removes the specified constraints from the view.

- (void)removeConstraints:(NSArray *)constraints

Parametersconstraints

The constraints to remove.

UIView Class ReferenceInstance Methods

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

96

Page 97: UIView_Class123

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

removeFromSuperview

Unlinks the view from its superview and its window, and removes it from the responder chain.

- (void)removeFromSuperview

DiscussionIf the view’s 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 viewin the subtree of the view you are removing.

Important: Never call this method from inside your view’s drawRect: (page 81) method.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property superview (page 37) @property subviews (page 37)

Related Sample CodeiPhoneCoreDataRecipesStreetScrollerUICatalogViewTransitionsZoomingPDFViewer

Declared inUIView.h

removeGestureRecognizer:

Detaches a gesture recognizer from the receiving view.

- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

UIView Class ReferenceInstance Methods

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

97

Page 98: UIView_Class123

ParametersgestureRecognizer

An object whose class descends from the UIGestureRecognizer class.

DiscussionThis method releases gestureRecognizer in addition to detaching it from the view.

AvailabilityAvailable in iOS 3.2 and later.

See Also– addGestureRecognizer: (page 69) @property gestureRecognizers (page 32)

Declared inUIView.h

removeMotionEffect:

Stops applying a motion effect to the view.

- (void)removeMotionEffect:(UIMotionEffect *)effect

Parameterseffect

The motion effect.

DiscussionAny affected presentation values animate to their post-removal values using the present UIView animationcontext.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

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

UIView Class ReferenceInstance Methods

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

98

Page 99: UIView_Class123

- (UIView *)resizableSnapshotViewFromRect:(CGRect)rectafterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets

Parametersrect

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

afterUpdatesA Boolean value that specifies whether the snapshot should be taken after recent changes have beenincorporated. Pass the value NO if you want to capture the screen in its current state, which might notinclude recent changes.

capInsetsThe edge insets that define the stretchable portion of the returned view’s content. You can specifyUIEdgeInsetsZero if you do not want the contents of the returned view to have a stretchable area.

Return ValueA new view object containing a snapshot of the current view’s rendered contents.

DiscussionThis method very efficiently captures the current rendered appearance of a view and uses it to build a newsnapshot view with stretchable insets. You can use the returned view as a visual stand-in for the current viewin your app. For example, you might use a snapshot view for animations where updating a large view hierarchymight be expensive. Because the content is captured from the already rendered content, this method reflectsthe current visual appearance of the view and is not updated to reflect animations that are scheduled or inprogress. However, calling this method is faster than trying to render the contents of the current view into abitmap 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 view’s layer; attempts to do so fail silently. If thecurrent view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visiblecontent.

You can call this method on a previously generated snapshot to obtain a new snapshot. For example, youcould do so after you change properties of a previous snapshot (such as its alpha value) and want a newsnapshot that includes those changes.

If you want to apply a graphical effect, such as blur, to a snapshot, use thedrawViewHierarchyInRect:afterScreenUpdates: (page 82) method instead.

If you specify nonzero edge insets in the capInsets parameter, those values determine the returned snapshot’sstretchable content area.

UIView Class ReferenceInstance Methods

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

99

Page 100: UIView_Class123

AvailabilityAvailable in iOS 7.0 and later.

See Also– drawViewHierarchyInRect:afterScreenUpdates: (page 82)– resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: (page 98) @property contentStretch (page 130)

Declared inUIView.h

sendSubviewToBack:

Moves the specified subview so that it appears behind its siblings.

- (void)sendSubviewToBack:(UIView *)view

Parametersview

The subview to move to the back.

DiscussionThis method moves the specified view to the beginning of the array of views in the subviews (page 37)property.

AvailabilityAvailable in iOS 2.0 and later.

See Also– bringSubviewToFront: (page 73)

Related Sample CodeZoomingPDFViewer

Declared inUIView.h

setContentCompressionResistancePriority:forAxis:

Sets the priority with which a view resists being made smaller than its intrinsic size.

- (void)setContentCompressionResistancePriority:(UILayoutPriority)priorityforAxis:(UILayoutConstraintAxis)axis

UIView Class ReferenceInstance Methods

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

100

Page 101: UIView_Class123

Parameterspriority

The new priority.

axisThe axis for which the compression resistance priority should be set.

DiscussionCustom views should set default values for both orientations on creation, based on their content, typically toNSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, thelayout designer can modify these priorities for specific views when the overall layout design requires differenttradeoffs than the natural priorities of the views being used in the interface.

Subclasses should not override this method.

AvailabilityAvailable in iOS 6.0 and later.

See Also– contentCompressionResistancePriorityForAxis: (page 74)

Declared inUIView.h

setContentHuggingPriority:forAxis:

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

- (void)setContentHuggingPriority:(UILayoutPriority)priorityforAxis:(UILayoutConstraintAxis)axis

Parameterspriority

The new priority.

axisThe axis for which the content hugging priority should be set.

DiscussionCustom views should set default values for both orientations on creation, based on their content, typically toNSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, thelayout designer can modify these priorities for specific views when the overall layout design requires differenttradeoffs than the natural priorities of the views being used in the interface.

UIView Class ReferenceInstance Methods

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

101

Page 102: UIView_Class123

Subclasses should not override this method.

AvailabilityAvailable in iOS 6.0 and later.

See Also– contentHuggingPriorityForAxis: (page 75)

Declared inUIView.h

setNeedsDisplay

Marks the receiver’s entire bounds rectangle as needing to be redrawn.

- (void)setNeedsDisplay

DiscussionYou can use this method or the setNeedsDisplayInRect: (page 103) to notify the system that your view’scontents need to be redrawn. This method makes a note of the request and returns immediately. The view isnot 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 foruse only with views that use native drawing technologies (such as UIKit and Core Graphics) to rendertheir content.

You should use this method to request that a view be redrawn only when the content or appearance of theview change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, itsexisting content is adjusted based on the value in the view’s contentMode (page 29) property. Redisplayingthe existing content improves performance by avoiding the need to redraw content that has not changed.

AvailabilityAvailable in iOS 2.0 and later.

See Also– drawRect: (page 81)– setNeedsDisplayInRect: (page 103) @property contentMode (page 29)

Related Sample CodePocketCoreImage

UIView Class ReferenceInstance Methods

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

102

Page 103: UIView_Class123

SpeakHereTeslameterTheElements

Declared inUIView.h

setNeedsDisplayInRect:

Marks the specified rectangle of the receiver as needing to be redrawn.

- (void)setNeedsDisplayInRect:(CGRect)invalidRect

ParametersinvalidRect

The rectangular region of the receiver to mark as invalid; it should be specified in the coordinate systemof the receiver.

DiscussionYou can use this method or the setNeedsDisplay (page 102) to notify the system that your view’s contentsneed to be redrawn. This method adds the specified rectangle into the view’s current list of invalid rectanglesand returns immediately. The view is not actually redrawn until the next drawing cycle, at which point allinvalidated views are updated.

Note: If your view is backed by a CAEAGLLayer object, this method has no effect. It is intended foruse only with views that use native drawing technologies (such as UIKit and Core Graphics) to rendertheir content.

You should use this method to request that a view be redrawn only when the content or appearance of theview change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, itsexisting content is adjusted based on the value in the view’s contentMode (page 29) property. Redisplayingthe existing content improves performance by avoiding the need to redraw content that has not changed.

AvailabilityAvailable in iOS 2.0 and later.

See Also– drawRect: (page 81)– setNeedsDisplay (page 102) @property contentMode (page 29)

UIView Class ReferenceInstance Methods

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

103

Page 104: UIView_Class123

Declared inUIView.h

setNeedsLayout

Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.

- (void)setNeedsLayout

DiscussionCall this method on your application’s main thread when you want to adjust the layout of a view’s subviews.This method makes a note of the request and returns immediately. Because this method does not force animmediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multipleviews before any of those views are updated. This behavior allows you to consolidate all of your layout updatesto one update cycle, which is usually better for performance.

AvailabilityAvailable in iOS 2.0 and later.

See Also– layoutIfNeeded (page 94)– layoutSubviews (page 94)

Related Sample CodeAVPlayerDemo

Declared inUIView.h

setNeedsUpdateConstraints

Controls whether the view’s constraints need updating.

- (void)setNeedsUpdateConstraints

DiscussionWhen a property of your custom view changes in a way that would impact constraints, you can call this methodto indicate that the constraints need to be updated at some point in the future. The system will then callupdateConstraints (page 110) as part of its normal layout pass. Updating constraints all at once just beforethey are needed ensures that you don’t needlessly recalculate constraints when multiple changes are madeto your view in between layout passes.

UIView Class ReferenceInstance Methods

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

104

Page 105: UIView_Class123

AvailabilityAvailable in iOS 6.0 and later.

See Also– needsUpdateConstraints (page 95)

Declared inUIView.h

setTranslatesAutoresizingMaskIntoConstraints:

Sets whether the view’s autoresizing mask should be translated into constraints for the constraint-based layoutsystem.

- (void)setTranslatesAutoresizingMaskIntoConstraints:(BOOL)flag

Parametersflag

YES if the view’s autoresizing mask should be translated into constraints for the constraint-based layoutsystem, NO otherwise.

DiscussionBecause the autoresizing mask naturally gives rise to constraints that fully specify a view’s position, any viewthat you wish to apply more flexible constraints to must be set to ignore its autoresizing mask using thismethod. You should call this method yourself for programmatically created views. Views created using a toolthat allows setting constraints should have this set already.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

sizeThatFits:

Asks the view to calculate and return the size that best fits its subviews.

- (CGSize)sizeThatFits:(CGSize)size

Parameterssize

The current size of the receiver.

UIView Class ReferenceInstance Methods

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

105

Page 106: UIView_Class123

Return ValueA new size that fits the receiver’s subviews.

DiscussionThe default implementation of this method returns the size portion of the view’s bounds rectangle. Subclassescan 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 aUIImageView object returns the size of the image it is currently displaying.

This method does not resize the receiver.

AvailabilityAvailable in iOS 2.0 and later.

See Also– sizeToFit (page 106) @property frame (page 31) @property bounds (page 26)

Declared inUIView.h

sizeToFit

Resizes and moves the receiver view so it just encloses its subviews.

- (void)sizeToFit

DiscussionCall this method when you want to resize the current view so that it uses the most appropriate amount ofspace. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a viewdoes not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itselfto 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 tothis method, which then makes the change.

AvailabilityAvailable in iOS 2.0 and later.

See Also– sizeThatFits: (page 105)

UIView Class ReferenceInstance Methods

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

106

Page 107: UIView_Class123

Related Sample CodeBonjourWebGeocoderDemoMapCalloutsXMLPerformance

Declared inUIView.h

snapshotViewAfterScreenUpdates:

Returns a snapshot view based on the contents of the current view.

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

ParametersafterUpdates

A Boolean value that specifies whether the snapshot should be taken after recent changes have beenincorporated. Pass the value NO to capture the screen in its current state, which might not include recentchanges.

Return ValueA new view object based on a snapshot of the current view’s rendered contents.

DiscussionThis method very efficiently captures the current rendered appearance of a view and uses it to build a newsnapshot 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 visualappearance 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 view’s layer; attempts to do so fail silently. If thecurrent view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visiblecontent.

You can call this method on a previously generated snapshot to obtain a new snapshot. For example, youcould do so after you change properties of a previous snapshot (such as its alpha value) and want a newsnapshot that includes those changes.

If you want to apply a graphical effect, such as blur, to a snapshot, use thedrawViewHierarchyInRect:afterScreenUpdates: (page 82) method instead.

UIView Class ReferenceInstance Methods

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

107

Page 108: UIView_Class123

AvailabilityAvailable in iOS 7.0 and later.

See Also– drawViewHierarchyInRect:afterScreenUpdates: (page 82)– resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: (page 98)

Declared inUIView.h

systemLayoutSizeFittingSize:

Returns the size of the view that satisfies the constraints it holds.

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize

ParameterstargetSize

Indicates whether you want the smallest or largest possible size that meets the constraints. See “FittingSize” (page 125) for accepted values.

Return ValueThe size of the view that satisfies the constraints it holds.

DiscussionDetermines the best size of the view considering all constraints it holds and those of its subviews.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

tintColorDidChange

Called by the system when the tintColor property changes.

- (void)tintColorDidChange

UIView Class ReferenceInstance Methods

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

108

Page 109: UIView_Class123

DiscussionThe system calls this method on a view when your code changes the value of the tintColor (page 39) propertyon that view. In addition, the system calls this method on a subview that inherits a changed interaction tintcolor.

In your implementation, refresh the view rendering as needed.

AvailabilityAvailable in iOS 7.0 and later.

See Also @property tintColor (page 39)

Declared inUIView.h

translatesAutoresizingMaskIntoConstraints

Returns a Boolean value that indicates whether the view’s autoresizing mask is translated into constraints for theconstraint-based layout system.

- (BOOL)translatesAutoresizingMaskIntoConstraints

Return ValueYES if the view’s autoresizing mask is translated into constraints for the constraint-based layout system, NOotherwise.

DiscussionIf this is value is YES, the view’s superview looks at the view’s autoresizing mask, produces constraints thatimplement it, and adds those constraints to itself (the superview).

AvailabilityAvailable in iOS 6.0 and later.

Related Sample CodePrefsInCloudViewTransitions

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

109

Page 110: UIView_Class123

updateConstraints

Updates constraints for the view.

- (void)updateConstraints

DiscussionCustom views that set up constraints themselves should do so by overriding this method. When your customview notes that a change has been made to the view that invalidates one of its constraints, it should immediatelyremove that constraint, and then call setNeedsUpdateConstraints (page 104) to note that constraints needto 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 customview’s properties are not changing.

You must not invalidate any constraints as part of your constraint update phase. You also must not invoke alayout or drawing phase as part of constraint updating.

Important: Call [super updateConstraints] as the final step in your implementation.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

updateConstraintsIfNeeded

Updates the constraints for the receiving view and its subviews.

- (void)updateConstraintsIfNeeded

DiscussionWhenever a new layout pass is triggered for a view, the system invokes this method to ensure that anyconstraints for the view and its subviews are updated with information from the current view hierarchy andits constraints. This method is called automatically by the system, but may be invoked manually if you needto examine the most up to date constraints.

Subclasses should not override this method.

AvailabilityAvailable in iOS 6.0 and later.

UIView Class ReferenceInstance Methods

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

110

Page 111: UIView_Class123

Declared inUIView.h

viewForBaselineLayout

Returns a view used to satisfy baseline constraints.

- (UIView *)viewForBaselineLayout

Return ValueThe view the constraint system should use to satisfy baseline constraints

DiscussionWhen you make a constraint on the NSLayoutAttributeBaseline of a view, the system aligns with the bottomof the view returned by this method. The default implementation returns the receiving view. If you overridethis method, the returned view must be a subview of the receiver.

AvailabilityAvailable in iOS 6.0 and later.

Declared inUIView.h

viewPrintFormatter

Returns a print formatter for the receiving view.

- (UIViewPrintFormatter *)viewPrintFormatter

Return ValueA UIViewPrintFormatter object or nil if the object could not be created. If it is successfully created, thereturned object is automatically associated with this view.

DiscussionWhen initiating a print job, you can call this method to obtain an appropriate view print formatter object foryour 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, seeDrawing and Printing Guide for iOS .

AvailabilityAvailable in iOS 4.2 and later.

UIView Class ReferenceInstance Methods

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

111

Page 112: UIView_Class123

See Also– drawRect:forViewPrintFormatter: (page 82)

Declared inUIPrintFormatter.h

viewWithTag:

Returns the view whose tag matches the specified value.

- (UIView *)viewWithTag:(NSInteger)tag

Parameterstag

The tag value to search for.

Return ValueThe view in the receiver’s hierarchy whose tag property matches the value in the tag parameter.

DiscussionThis method searches the current view and all of its subviews for the specified view.

AvailabilityAvailable in iOS 2.0 and later.

See Also @property tag (page 38)

Related Sample CodeGenericKeychainUICatalog

Declared inUIView.h

willMoveToSuperview:

Tells the view that its superview is about to change to the specified superview.

- (void)willMoveToSuperview:(UIView *)newSuperview

UIView Class ReferenceInstance Methods

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

112

Page 113: UIView_Class123

ParametersnewSuperview

A view object that will be the new superview of the receiver. This object may be nil.

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions whenever the superview changes.

AvailabilityAvailable in iOS 2.0 and later.

See Also– didMoveToSuperview (page 80)

Declared inUIView.h

willMoveToWindow:

Tells the view that its window object is about to change.

- (void)willMoveToWindow:(UIWindow *)newWindow

ParametersnewWindow

The window object that will be at the root of the receiver's new view hierarchy. This parameter may benil.

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions whenever the window changes.

AvailabilityAvailable in iOS 2.0 and later.

See Also– didMoveToWindow (page 80)

Declared inUIView.h

UIView Class ReferenceInstance Methods

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

113

Page 114: UIView_Class123

willRemoveSubview:

Tells the view that a subview is about to be removed.

- (void)willRemoveSubview:(UIView *)subview

Parameterssubview

The subview that will be removed.

DiscussionThe default implementation of this method does nothing. Subclasses can override it to perform additionalactions whenever subviews are removed. This method is called when the subview’s superview changes orwhen the subview is removed from the view hierarchy completely.

AvailabilityAvailable in iOS 2.0 and later.

See Also– removeFromSuperview (page 97)– didAddSubview: (page 79)

Declared inUIView.h

Constants

UIViewAnimationOptions

Options for animating views using block objects.

enum {UIViewAnimationOptionLayoutSubviews = 1 << 0,UIViewAnimationOptionAllowUserInteraction = 1 << 1,UIViewAnimationOptionBeginFromCurrentState = 1 << 2,UIViewAnimationOptionRepeat = 1 << 3,UIViewAnimationOptionAutoreverse = 1 << 4,UIViewAnimationOptionOverrideInheritedDuration = 1 << 5,UIViewAnimationOptionOverrideInheritedCurve = 1 << 6,UIViewAnimationOptionAllowAnimatedContent = 1 << 7,UIViewAnimationOptionShowHideTransitionViews = 1 << 8,UIViewAnimationOptionOverrideInheritedOptions = 1 << 9,

UIView Class ReferenceConstants

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

114

Page 115: UIView_Class123

UIViewAnimationOptionCurveEaseInOut = 0 << 16,UIViewAnimationOptionCurveEaseIn = 1 << 16,UIViewAnimationOptionCurveEaseOut = 2 << 16,UIViewAnimationOptionCurveLinear = 3 << 16,

UIViewAnimationOptionTransitionNone = 0 << 20,UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,UIViewAnimationOptionTransitionCurlUp = 3 << 20,UIViewAnimationOptionTransitionCurlDown = 4 << 20,UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,

};typedef NSUInteger UIViewAnimationOptions;

ConstantsUIViewAnimationOptionLayoutSubviews

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.

UIViewAnimationOptionAllowUserInteractionAllow the user to interact with views while they are being animated.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionBeginFromCurrentStateStart the animation from the current setting associated with an already in-flight animation. If this key isnot present, any in-flight animations are allowed to finish before the new animation is started. If anotheranimation is not in flight, this key has no effect.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionRepeatRepeat the animation indefinitely.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionAutoreverseRun the animation backwards and forwards. Must be combined with theUIViewAnimationOptionRepeat option.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIView Class ReferenceConstants

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

115

Page 116: UIView_Class123

UIViewAnimationOptionOverrideInheritedDurationForce the animation to use the original duration value specified when the animation was submitted. Ifthis 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.

UIViewAnimationOptionOverrideInheritedCurveForce the animation to use the original curve value specified when the animation was submitted. If thiskey 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.

UIViewAnimationOptionAllowAnimatedContentAnimate the views by changing the property values dynamically and redrawing the view. If this key isnot present, the views are animated using a snapshot image.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionShowHideTransitionViewsWhen present, this key causes views to be hidden or shown (instead of removed or added) whenperforming a view transition. Both views must already be present in the parent view’s hierarchy whenusing this key. If this key is not present, the to-view in a transition is added to, and the from-view isremoved from, the parent view’s list of subviews.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionOverrideInheritedOptionsThe option to not inherit the animation type or any options.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveEaseInOutAn ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of itsduration, and then slow again before completing.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveEaseInAn 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.

UIView Class ReferenceConstants

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

116

Page 117: UIView_Class123

UIViewAnimationOptionCurveEaseOutAn 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.

UIViewAnimationOptionCurveLinearA linear animation curve causes an animation to occur evenly over its duration.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionNoneNo transition is specified.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromLeftA transition that flips a view around its vertical axis from left to right. The left side of the view movestoward the front and right side toward the back.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromRightA transition that flips a view around its vertical axis from right to left. The right side of the view movestoward the front and left side toward the back.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCurlUpA transition that curls a view up from the bottom.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCurlDownA transition that curls a view down from the top.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCrossDissolveA transition that dissolves from one view to the next.

Available in iOS 5.0 and later.

Declared in UIView.h.

UIView Class ReferenceConstants

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

117

Page 118: UIView_Class123

UIViewAnimationOptionTransitionFlipFromTopA transition that flips a view around its horizontal axis from top to bottom. The top side of the view movestoward the front and the bottom side toward the back.

Available in iOS 5.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromBottomA transition that flips a view around its horizontal axis from bottom to top. The bottom side of the viewmoves toward the front and the top side toward the back.

Available in iOS 5.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 4.0 and later.

Declared inUIView.h

UIViewAnimationCurve

Specifies the supported animation curves.

typedef enum {UIViewAnimationCurveEaseInOut,UIViewAnimationCurveEaseIn,UIViewAnimationCurveEaseOut,UIViewAnimationCurveLinear

} UIViewAnimationCurve;

ConstantsUIViewAnimationCurveEaseInOut

An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of itsduration, 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.

UIViewAnimationCurveEaseInAn 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.

UIView Class ReferenceConstants

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

118

Page 119: UIView_Class123

UIViewAnimationCurveEaseOutAn 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.

UIViewAnimationCurveLinearA linear animation curve causes an animation to occur evenly over its duration.

Available in iOS 2.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

UIViewKeyframeAnimationOptions

Key frame animation options used with theanimateKeyframesWithDuration:delay:options:animations:completion: (page 43) method.

typedef enum {UIViewKeyframeAnimationOptionLayoutSubviews =

UIViewAnimationOptionLayoutSubviews,UIViewKeyframeAnimationOptionAllowUserInteraction =

UIViewAnimationOptionAllowUserInteraction,UIViewKeyframeAnimationOptionBeginFromCurrentState =

UIViewAnimationOptionBeginFromCurrentState,UIViewKeyframeAnimationOptionRepeat = UIViewAnimationOptionRepeat,UIViewKeyframeAnimationOptionAutoreverse = UIViewAnimationOptionAutoreverse,

UIViewKeyframeAnimationOptionOverrideInheritedDuration =UIViewAnimationOptionOverrideInheritedDuration,

UIViewKeyframeAnimationOptionOverrideInheritedOptions =UIViewAnimationOptionOverrideInheritedOptions,

UIViewKeyframeAnimationOptionCalculationModeLinear = 0 << 9,UIViewKeyframeAnimationOptionCalculationModeDiscrete = 1 << 9,UIViewKeyframeAnimationOptionCalculationModePaced = 2 << 9,UIViewKeyframeAnimationOptionCalculationModeCubic = 3 << 9,UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 9

} UIViewKeyframeAnimationOptions;

UIView Class ReferenceConstants

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

119

Page 120: UIView_Class123

ConstantsUIViewKeyframeAnimationOptionLayoutSubviews

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.

UIViewKeyframeAnimationOptionAllowUserInteractionThe 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.

UIViewKeyframeAnimationOptionBeginFromCurrentStateThe 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 isstarted. If another animation is not in flight, this option has no effect.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionRepeatThe option to repeat an animation indefinitely.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionAutoreverseThe option to run an animation backwards and forwards. Must be combined with theUIViewKeyframeAnimationOptionRepeat option.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionOverrideInheritedDurationThe option to force an animation to use the original duration value specified when the animation wassubmitted. If this option is not present, the animation inherits the remaining duration of the in-flightanimation, if any.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionOverrideInheritedOptionsThe option to not inherit the animation type or any options.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIView Class ReferenceConstants

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

120

Page 121: UIView_Class123

UIViewKeyframeAnimationOptionCalculationModeLinearThe option to use a simple linear calculation when interpolating between keyframe values.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeDiscreteThe option to not interpolate between keyframe values, but rather to jump directly to each new keyframevalue.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModePacedThe option to compute intermediate keyframe values using a simple pacing algorithm. This option resultsin an evenly paced animation.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeCubicThe option to compute intermediate frames using a default Catmull-Rom spline that passes through thekeyframe values. You cannot adjust the parameters of this algorithm.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeCubicPacedThe option to compute intermediate frames using the cubic scheme while ignoring the timing propertiesof the animation. Instead, timing parameters are calculated implicitly to give the animation a constantvelocity.

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,

UIView Class ReferenceConstants

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

121

Page 122: UIView_Class123

UIViewContentModeRight,UIViewContentModeTopLeft,UIViewContentModeTopRight,UIViewContentModeBottomLeft,UIViewContentModeBottomRight,

} UIViewContentMode;

ConstantsUIViewContentModeScaleToFill

The option to scale the content to fit the size of itself by changing the aspect ratio of the content ifnecessary.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeScaleAspectFitThe option to scale the content to fit the size of the view by maintaining the aspect ratio. Any remainingarea of the view’s bounds is transparent.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeScaleAspectFillThe option to scale the content to fill the size of the view. Some portion of the content may be clippedto fill the view’s bounds.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeRedrawThe 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.

UIViewContentModeCenterThe option to center the content in the view’s bounds, keeping the proportions the same.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeTopThe option to center the content aligned at the top in the view’s bounds.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIView Class ReferenceConstants

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

122

Page 123: UIView_Class123

UIViewContentModeBottomThe option to center the content aligned at the bottom in the view’s bounds.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeLeftThe option to align the content on the left of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeRightThe option to align the content on the right of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeTopLeftThe option to align the content in the top-left corner of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeTopRightThe option to align the content in the top-right corner of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeBottomLeftThe option to align the content in the bottom-left corner of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeBottomRightThe option to align the content in the bottom-right corner of the view.

Available in iOS 2.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

UILayoutConstraintAxis

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

UIView Class ReferenceConstants

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

123

Page 124: UIView_Class123

enum {UILayoutConstraintAxisHorizontal = 0,UILayoutConstraintAxisVertical = 1

};typedef NSInteger UILayoutConstraintAxis;

ConstantsUILayoutConstraintAxisHorizontal

The constraint applied when laying out the horizontal relationship between objects.

Available in iOS 6.0 and later.

Declared in UIView.h.

UILayoutConstraintAxisVerticalThe 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;

ConstantsUIViewTintAdjustmentModeAutomatic

The tint adjustment mode of the view is the same as its superview's tint adjustment mode (orUIViewTintAdjustmentModeNormal if the view has no superview).

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentModeNormalThe 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.

UIView Class ReferenceConstants

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

124

Page 125: UIView_Class123

UIViewTintAdjustmentModeDimmedThe view's tintColor (page 39) property returns a desaturated, dimmed version of the view's originaltint color.

Available in iOS 7.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

UISystemAnimation

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

typedef enum{UISystemAnimationDelete,

} UISystemAnimation;

ConstantsUISystemAnimationDelete

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

Available in iOS 7.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 7.0 and later.

Declared inUIView.h

Fitting Size

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

const CGSize UILayoutFittingCompressedSize;const CGSize UILayoutFittingExpandedSize;

UIView Class ReferenceConstants

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

125

Page 126: UIView_Class123

ConstantsUILayoutFittingCompressedSize

The option to use the smallest possible size.

Available in iOS 6.0 and later.

Declared in UIView.h.

UILayoutFittingExpandedSizeThe 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;

ConstantsUIViewNoIntrinsicMetric

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 = 0,UIViewAutoresizingFlexibleLeftMargin = 1 << 0,UIViewAutoresizingFlexibleWidth = 1 << 1,UIViewAutoresizingFlexibleRightMargin = 1 << 2,UIViewAutoresizingFlexibleTopMargin = 1 << 3,UIViewAutoresizingFlexibleHeight = 1 << 4,UIViewAutoresizingFlexibleBottomMargin = 1 << 5

};typedef NSUInteger UIViewAutoresizing;

UIView Class ReferenceConstants

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

126

Page 127: UIView_Class123

ConstantsUIViewAutoresizingNone

The option for indicating that the view does not resize.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleLeftMarginResizing 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.

UIViewAutoresizingFlexibleWidthResizing performed by expanding or shrinking a view’s width.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleRightMarginResizing 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.

UIViewAutoresizingFlexibleTopMarginResizing 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.

UIViewAutoresizingFlexibleHeightResizing performed by expanding or shrinking a view's height.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleBottomMarginResizing 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.

AvailabilityAvailable in iOS 2.0 and later.

Declared inUIView.h

UIView Class ReferenceConstants

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

127

Page 128: UIView_Class123

UIViewAnimationTransition

Animation transition options for use in an animation block object.

typedef enum {UIViewAnimationTransitionNone,UIViewAnimationTransitionFlipFromLeft,UIViewAnimationTransitionFlipFromRight,UIViewAnimationTransitionCurlUp,UIViewAnimationTransitionCurlDown,

} UIViewAnimationTransition;

ConstantsUIViewAnimationTransitionNone

The option for indicating that no transition is specified.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionFlipFromLeftA transition that flips a view around a vertical axis from left to right. The left side of the view movestowards the front and right side towards the back.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionFlipFromRightA transition that flips a view around a vertical axis from right to left. The right side of the view movestowards the front and left side towards the back.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionCurlUpA transition that curls a view up from the bottom.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionCurlDownA transition that curls a view down from the top.

Available in iOS 2.0 and later.

Declared in UIView.h.

AvailabilityAvailable in iOS 2.0 and later.

UIView Class ReferenceConstants

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

128

Page 129: UIView_Class123

Declared inUIView.h

UIView Class ReferenceConstants

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

129

Page 130: UIView_Class123

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

DiscussionYou use this property to control how a view’s 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 controlsuse stretching to maintain crisp borders while allowing the middle portions of the control to stretch and fillthe available space.

Note: For stretching image-based content, it is simpler to use a UIImageView object with astretchable image instead of setting this property. You can create a stretchable image using thestretchableImageWithLeftCapWidth: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 thenscaled to the size of the view’s content to obtain the appropriate pixel values. The default value for this rectanglehas an origin of (0.0, 0.0) and a size of (1.0, 1.0). This reflects a rectangle whose stretchable portionencompasses the entire content.

AvailabilityAvailable in iOS 3.0 and later.

Deprecated in iOS 6.0.

Declared inUIView.h

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

130

Deprecated UIView Methods

Page 131: UIView_Class123

This table describes the changes to UIView Class Reference .

NotesDate

Updated layoutIfNeeded method description.2014-03-10

Clarified the behavior of the UIViewTintAdjustmentMode constants.2013-12-16

Updated advice about views that draw using OpenGL ES.2013-10-22

Added descriptions for new properties in iOS 7: motionEffects (page34), tintAdjustmentMode (page 38), and tintColor (page 39).

2013-09-18

Added descriptions for new instance methods in iOS 7:snapshotViewAfterScreenUpdates: (page 107),resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: (page98), 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: (page41),animateKeyframesWithDuration:delay:options:animations:completion: (page43),animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:

animations:completion: (page 47),performSystemAnimation:onViews:options:animations:completion: (page52), and performWithoutAnimation: (page 52).

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

131

Document Revision History

Page 132: UIView_Class123

NotesDate

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 (page121), UIViewKeyframeAnimationOptionCalculationModeDiscrete (page121), UIViewKeyframeAnimationOptionCalculationModeLinear (page121), and UIViewKeyframeAnimationOptionCalculationModePaced (page121).

Added descriptions for new tit adjustment constants in iOS 7:UIViewTintAdjustmentModeAutomatic (page 124),UIViewTintAdjustmentModeDimmed (page 125), andUIViewTintAdjustmentModeNormal (page 124).

Added a description for a new animation constant in iOS 7:UISystemAnimationDelete (page 125).

Added methods and properties related to state preservation andrestoration. Added methods related to autolayout. Fixed typo.

2012-09-19

Added new animation transition constants.2011-10-12

Corrected the backgroundColor property description.2011-03-08

Updated the class overview and added new methods related to printing.2010-11-15

Updated to include symbols introduced in iOS 4.0.2010-06-04

Added descriptions of property and methods related to gesturerecognizers.

2010-02-25

Corrected description of the convertRect:toView: method.2009-11-17

Document Revision History

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

132

Page 133: UIView_Class123

NotesDate

Updated the information about view size restrictions to account forchanges in iOS 3.0.

2009-07-23

Updated the description of caching behaviors for thesetAnimationTransition:forView:cache: method. Also updated thedescription of the behavior of the layoutIfNeeded method.

2009-06-15

Updated for iOS 3.0.2009-03-05

Updated animationDidEndSelector: documentation.2008-11-13

Corrected description of background property.2008-09-09

New document that describes the superclass providing concrete subclasseswith a structure for drawing and handling events in views.

2008-07-05

Document Revision History

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

133

Page 134: UIView_Class123

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 anyform or by any means, mechanical, electronic,photocopying, recording, or otherwise, withoutprior written permission of Apple Inc., with thefollowing exceptions: Any person is herebyauthorized to store documentation on a singlecomputer for personal use only and to printcopies of documentation for personal useprovided that the documentation containsApple’s copyright notice.

No licenses, express or implied, are granted withrespect to any of the technology described in thisdocument. Apple retains all intellectual propertyrights associated with the technology describedin this document. This document is intended toassist application developers to developapplications only for Apple-labeled computers.

Apple Inc.1 Infinite LoopCupertino, CA 95014408-996-1010

Apple, the Apple logo, Bonjour, iPhone, andKeychain are trademarks of Apple Inc., registeredin the U.S. and other countries.

AirDrop is a trademark of Apple Inc.

iAd is a service mark of Apple Inc., registered inthe U.S. and other countries.

OpenGL is a registered trademark of SiliconGraphics, Inc.

Times is a registered trademark of HeidelbergerDruckmaschinen AG, available from LinotypeLibrary GmbH.

iOS is a trademark or registered trademark ofCisco in the U.S. and other countries and is usedunder license.

Even though Apple has reviewed this document,APPLE MAKES NO WARRANTY OR REPRESENTATION,EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THISDOCUMENT, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR A PARTICULARPURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED“AS IS,” AND YOU, THE READER, ARE ASSUMING THEENTIRE RISK AS TO ITS QUALITY AND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIALDAMAGES RESULTING FROM ANY DEFECT ORINACCURACY IN THIS DOCUMENT, even if advised ofthe possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVEARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORALOR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer,agent, or employee is authorized to make anymodification, extension, or addition to this warranty.

Some states do not allow the exclusion or limitationof implied warranties or liability for incidental orconsequential damages, so the above limitation orexclusion may not apply to you. This warranty givesyou specific legal rights, and you may also have otherrights which vary from state to state.