UIView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Declared in
UIPrintFormatter.h
UITextField.h
UIView.h
Companion guides
Related sample code

Overview

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel object draws a text string and a UIImageView object draws an image.

Because view objects are the main way your application interacts with the user, they have a number of responsibilities. Here are just a few:

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

The geometry of a view is defined by its frame, bounds, and center properties. The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view. The center property can be used to adjust the position of the view without changing its size. The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both.

For detailed information about how to use the UIView class, see View Programming Guide for iOS.

Creating a View

To create a view programmatically, you can use code like the following:

CGRect  viewRect = CGRectMake(10, 10, 100, 100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];

This code creates the view and positions it at the point (10, 10) in its superview’s coordinate system (once it is added to that superview). To add a subview to another view, you use the addSubview: method. In iOS, sibling views may overlap each other without any issues, allowing complex view placement. The addSubview: method places the specified view on top of other siblings. You can specify the relative z-order of a subview by adding it using the insertSubview:aboveSubview: and insertSubview:belowSubview: methods. You can also exchange the position of already added subviews using the exchangeSubviewAtIndex:withSubviewAtIndex: method.

When creating a view, it is important to assign an appropriate value to the autoresizingMask property to ensure the view resizes correctly. View resizing primarily occurs when the orientation of your application’s interface changes but it may happen at other times as well. For example, calling the setNeedsLayout method forces your view to update its layout.

The View Drawing Cycle

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

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

Animations

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

  • In iOS 4 and later, use the block-based animation methods. (Recommended)

  • Use the begin/commit animation methods.

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

The following properties of the UIView class are animatable:

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

Threading Considerations

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

Subclassing Notes

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

For information about ways to avoid subclassing, see “Alternatives to Subclassing.”

Methods to Override

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

Alternatives to Subclassing

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

  • addConstraint: - Define automatic layout behavior for the view and its subviews.

  • autoresizingMask - Provides automatic layout behavior when the superview’s frame changes. These behaviors can be combined with constraints.

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

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

  • hidden or alpha - Change the transparency of the view as a whole rather than hiding or applying alpha to your view’s rendered content.

  • backgroundColor - Set the view’s color rather than drawing that color yourself.

  • Subviews - Rather than draw your content using a drawRect: method, embed image and label subviews with the content you want to present.

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

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

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

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

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

Tasks

Initializing a View Object

Configuring a View’s Visual Appearance

Configuring the Event-Related Behavior

Configuring the Bounds and Frame Rectangles

Managing the View Hierarchy

Configuring the Resizing Behavior

Laying out Subviews

Opting in to Constraint-Based Layout

Managing Constraints

Measuring in Constraint-Based Layout

Aligning Views with Constraint-Based Layout

Triggering Constraint-Based Layout

Debugging Constraint-Based Layout

See Auto Layout Guidefor more details on debugging constraint-based layout.

Drawing and Updating the View

Formatting Printed View Content

Managing Gesture Recognizers

Animating Views with Block Objects

Animating Views

Use of the methods in this section is discouraged in iOS 4 and later. Use the block-based animation methods instead.

Using Motion Effects

Preserving and Restoring State

Capturing a View Snapshot

Identifying the View at Runtime

Converting Between View Coordinate Systems

Hit Testing in a View

Ending a View Editing Session

Observing View-Related Changes

Properties

alpha

The view’s alpha value.

@property(nonatomic) CGFloat alpha
Discussion

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

Changes to this property can be animated.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

autoresizesSubviews

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

@property(nonatomic) BOOL autoresizesSubviews
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

autoresizingMask

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

@property(nonatomic) UIViewAutoresizing autoresizingMask
Discussion

When a view’s bounds change, that view automatically resizes its subviews according to each subview’s autoresizing mask. You specify the value of this mask by combining the constants described in UIViewAutoresizing using the C bitwise OR operator. Combining these constants lets you specify which dimensions of the view should grow or shrink relative to the superview. The default value of this property is UIViewAutoresizingNone, which indicates that the view should not be resized at all.

When more than one option along the same axis is set, the default behavior is to distribute the size difference proportionally among the flexible portions. The larger the flexible portion, relative to the other flexible portions, the more it is likely to grow. For example, suppose this property includes the UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin constants but does not include the UIViewAutoresizingFlexibleLeftMargin constant, thus indicating that 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 right of the view increase.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

backgroundColor

The view’s background color.

@property(nonatomic, copy) UIColor *backgroundColor
Discussion

Changes to this property can be animated. The default value is nil, which results in a transparent background color.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

bounds

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

@property(nonatomic) CGRect bounds
Discussion

On the screen, the bounds rectangle represents the same visible portion of the view as its frame rectangle. By default, the origin of the bounds rectangle is set to (0, 0) but you can change this value to display different portions of the view. The size of the bounds rectangle is coupled to the size of the frame rectangle, so that changes to one affect the other. Changing the bounds size grows or shrinks the view relative to its center point. The coordinates of the bounds rectangle are always specified in points.

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

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.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

center

The center of the frame.

@property(nonatomic) CGPoint center
Discussion

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

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

Changes to this property can be animated. Use the beginAnimations:context: class method to begin and the commitAnimations class method to end an animation block.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

clearsContextBeforeDrawing

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

@property(nonatomic) BOOL clearsContextBeforeDrawing
Discussion

When set to YES, the drawing buffer is automatically cleared to transparent black before the drawRect: method is called. This behavior ensures that there are no visual artifacts left over when the view’s contents are redrawn. If the view’s opaque property is also set to YES, the backgroundColor property of the view must not be nil or drawing errors may occur. The default value of this property is YES.

If you set the value of this property to NO, you are responsible for ensuring the contents of the view are drawn properly in your drawRect: method. If your drawing code is already heavily optimized, setting this property is NO can improve performance, especially during scrolling when only a portion of the view might need to be redrawn.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

clipsToBounds

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

@property(nonatomic) BOOL clipsToBounds
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIView.h

contentMode

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

@property(nonatomic) UIViewContentMode contentMode
Discussion

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

For a list of values you can assign to this property, see UIViewContentMode. The default value of this property is UIViewContentModeScaleToFill.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

contentScaleFactor

The scale factor applied to the view.

@property(nonatomic) CGFloat contentScaleFactor
Discussion

The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels). This value is typically either 1.0 or 2.0. Higher scale factors indicate that each point in the view is represented by more than one pixel in the underlying layer. For example, if the scale factor is 2.0 and the view frame size is 50 x 50 points, the size of the bitmap used to present that content is 100 x 100 pixels.

The default value for this property is the scale factor associated with the screen currently displaying the view. If your custom view implements a custom drawRect: method and is associated with a window, or if you use the GLKView class to draw OpenGL ES content, your view draws at the full resolution of the screen. For system views, the value of this property may be 1.0 even on high resolution screens.

In general, you should not need to modify the value in this property. However, if your application draws using OpenGL ES, you may want to change the scale factor to trade image quality for rendering performance. For more information on how to adjust your OpenGL ES rendering environment, see “Supporting High-Resolution Displays” in OpenGL ES Programming Guide for iOS.

Availability
  • Available in iOS 4.0 and later.
Declared In
UIView.h

exclusiveTouch

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

@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

frame

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

@property(nonatomic) CGRect frame
Discussion

This rectangle defines the size and position of the view in its superview’s coordinate system. You use this rectangle during layout operations to size and position the view. Setting this property changes the point specified by the center property and the size in the bounds rectangle accordingly. The coordinates of the frame rectangle are always specified in points.

Changing the frame rectangle automatically redisplays the receiver without invoking the drawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set the contentMode property to UIViewContentModeRedraw.

Changes to this property can be animated. However, if the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

gestureRecognizers

The gesture-recognizer objects currently attached to the view.

@property(nonatomic, copy) NSArray *gestureRecognizers
Discussion

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

Availability
  • Available in iOS 3.2 and later.
Declared In
UIView.h

hidden

A Boolean value that determines whether the view is hidden.

@property(nonatomic, getter=isHidden) BOOL hidden
Discussion

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

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

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

layer

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

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

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

Availability
  • Available in iOS 2.0 and later.
See Also
Declared In
UIView.h

motionEffects

The array of motion effects for the view.

@property(copy, nonatomic) NSArray *motionEffects
Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

multipleTouchEnabled

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

@property(nonatomic, getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled
Discussion

When set to YES, the receiver receives all touches associated with a multi-touch sequence. When set to NO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property is NO.

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

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
  • aurioTouch2
Declared In
UIView.h

opaque

A Boolean value that determines whether the view is opaque.

@property(nonatomic, getter=isOpaque) BOOL opaque
Discussion

This property provides a hint to the drawing system as to how it should treat the view. If set to YES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to NO, the drawing system composites the view normally with other content. The default value of this property is YES.

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

restorationIdentifier

The identifier that determines whether the view supports state restoration.

@property(nonatomic, copy) NSString *restorationIdentifier
Discussion

This property indicates whether state information in the view should be preserved; it is also used to identify the view during the restoration process. The value of this property is nil by default, which indicates that the view’s state does not need to be saved. Assigning a string object to the property lets the owning view controller know that the view has relevant state information to save.

Assign a value to this property only if you are implementing a custom view that implements the encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: methods for saving and restoring state. You use those methods to write any view-specific state information and subsequently use that data to restore the view to its previous configuration.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

subviews

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

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

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

superview

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

@property(nonatomic, readonly) UIView *superview
Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

tag

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

@property(nonatomic) NSInteger tag
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

tintAdjustmentMode

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

@property(nonatomic) UIViewTintAdjustmentMode tintAdjustmentMode
Discussion

When this property’s value is UIViewTintAdjustmentModeDimmed, the value of the tintColor property is modified to provide a dimmed appearance.

If the system cannot find a non-default value in the subview hierarchy when you query this property, the value is UIViewTintAdjustmentModeNormal.

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

tintColor

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

@property(nonatomic, retain) UIColor *tintColor
Discussion

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

If the view’s tintAdjustmentMode property’s value is UIViewTintAdjustmentModeDimmed, then the tintColor property value is automatically dimmed.

To refresh subview rendering when this property changes, override the tintColorDidChange method.

Colors that are pattern colors (as described in UIColor Class Reference) are not supported.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

transform

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

@property(nonatomic) CGAffineTransform transform
Discussion

The origin of the transform is the value of the center property, or the layer’s anchorPoint property if it was changed. (Use the layer property to get the underlying Core Animation layer object.) The default value is CGAffineTransformIdentity.

Changes to this property can be animated. Use the beginAnimations:context: class method to begin and the commitAnimations class method to end an animation block. The default is whatever the center value is (or anchor point if changed)

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

userInteractionEnabled

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

@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled
Discussion

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

During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying the UIViewAnimationOptionAllowUserInteraction option when configuring the animation.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

window

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

@property(nonatomic, readonly) UIWindow *window
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

Class Methods

addKeyframeWithRelativeStartTime:relativeDuration:animations:

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

+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime relativeDuration:(double)frameDuration animations:(void (^)(void))animations
Parameters
frameStartTime

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

frameDuration

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

animations

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

Discussion

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

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

animateKeyframesWithDuration:delay:options:animations:completion:

Creates an animation block object that can be used to set up keyframe-based animations for the current view.

+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewKeyframeAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Parameters
duration

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

delay

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

options

A mask of options indicating how you want to perform the animations. For a list of valid constants, see “UIViewKeyframeAnimationOptions”.

animations

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

completion

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

Discussion

This method creates an animation block that you can use to set up a keyframe-based animation. The keyframes themselves are not part of the initial animation block you create using this method. Inside the animations block, you must add the keyframe time and animation data by calling the addKeyframeWithRelativeStartTime:relativeDuration:animations: method one or more times. Adding keyframes causes the animation to animate the view from its current value to the value of the first keyframe, then to the value of the next keyframe, and so on at the times you specify.

If you do not add any keyframes in the animations block, the animation proceeds from start to end like a standard animation block. In other words, the system animates from the current view values to any new values over the specified duration.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

animateWithDuration:animations:

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

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

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

animations

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

Discussion

This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut and UIViewAnimationOptionTransitionNone animation options.

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

Availability
  • Available in iOS 4.0 and later.
Declared In
UIView.h

animateWithDuration:animations:completion:

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

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Parameters
duration

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

animations

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

completion

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

Discussion

This method performs the specified animations immediately using the UIViewAnimationOptionCurveEaseInOut and UIViewAnimationOptionTransitionNone 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.)

Availability
  • Available in iOS 4.0 and later.
Declared In
UIView.h

animateWithDuration:delay:options:animations:completion:

Animate changes to one or more views using the specified duration, delay, options, and completion handler.

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Parameters
duration

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

delay

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

options

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

animations

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

completion

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

Discussion

This method initiates a set of animations to perform on the view. The block object in the animations parameter contains the code for animating the properties of one or more views.

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability
  • Available in iOS 4.0 and later.
Declared In
UIView.h

animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:

Performs a view animation using a timing curve corresponding to the motion of a physical spring.

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Parameters
duration

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

delay

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

dampingRatio

The damping ratio for the spring animation as it approaches its quiescent state.

To smoothly decelerate the animation without oscillation, use a value of 1. Employ a damping ratio closer to zero to increase oscillation.

velocity

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

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

options

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

animations

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

completion

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

Discussion

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

areAnimationsEnabled

Returns a Boolean value indicating whether animations are enabled.

+ (BOOL)areAnimationsEnabled
Return Value

YES if animations are enabled; otherwise, NO.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIView.h

beginAnimations:context:

Marks the beginning of a begin/commit animation block.

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

An application-supplied identifier for the animations.

context

Custom data that you want to associate with this set of animations. information that is passed to the animation delegate messages—the selectors set using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods.

Discussion

This method signals to the system that you want to specify one or more animations to perform. After calling this method, configure the animation options (using the setAnimation… class methods) and then change the desired animatable properties of your views. When you are done changing your view properties, call the commitAnimations method to close the set and schedule the animations.

You can nest sets of animations (by calling this method again before committing a previous set of animations) as needed. Nesting animations groups them together and allows you to set different animation options for the nested group.

If you install a start or stop selector using the setAnimationWillStartSelector: or setAnimationDidStopSelector: method, the values you specify for the animationID and context parameters are passed to your selectors at runtime. You can use these parameters to pass additional information to those selectors.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

commitAnimations

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

+ (void)commitAnimations
Discussion

If the current animation set is the outermost set, this method starts the animations when the application returns to the run loop. If the current animation set is nested inside another set, this method waits until the outermost set of animations is committed, at which point it commits all of the animations together.

Animations run in a separate thread to avoid blocking the application. In this way, multiple animations can be piled on top of one another. See setAnimationBeginsFromCurrentState: for how to start animations while others are in progress.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

layerClass

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

+ (Class)layerClass
Return Value

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

Discussion

This method returns the CALayer class object by default. Subclasses can override this method and return a different layer class as needed. For example, if your view uses tiling to display a large scrollable area, you might want to override this method and return the CATiledLayer class.

This method is called only once early in the creation of the view in order to create the corresponding layer object.

Availability
  • Available in iOS 2.0 and later.
See Also
Declared In
UIView.h

performSystemAnimation:onViews:options:animations:completion:

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

+ (void)performSystemAnimation:(UISystemAnimation)animation onViews:(NSArray *)views options:(UIViewAnimationOptions)options animations:(void (^)(void))parallelAnimations completion:(void (^)(BOOL finished))completion
Parameters
animation

The system animation to perform; a constant from the UISystemAnimation enum.

views

The views to perform the animations on.

options

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

parallelAnimations

Additional animations you specify to run alongside the system animation, with the same timing and duration that the system animation defines or inherits.

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

completion

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

performWithoutAnimation:

Disables a view transition animation.

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

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

requiresConstraintBasedLayout

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

+ (BOOL)requiresConstraintBasedLayout
Return Value

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

setAnimationBeginsFromCurrentState:

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

+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState
Parameters
fromCurrentState

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

Discussion

If set to YES when an animation is in flight, the current view position of the in-flight animation is used as the starting state for the new animation. If set to NO, the in-flight animation ends before the new animation begins using the last view position as the starting state. This method does nothing if an animation is not in flight or invoked outside of an animation block. Use the beginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value is NO.

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: method to specify your animations and the animation options.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationCurve:

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

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve
Discussion

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

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: method to specify your animations and the animation curve options.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationDelay:

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

+ (void)setAnimationDelay:(NSTimeInterval)delay
Discussion

If you specify your animations using begin/commit set of methods, you use this method to specify the amount of time to wait before starting the animations. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: and commitAnimations methods. And you must call this method prior to changing the animatable properties of your views. The default value is 0.0 seconds.

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: method to specify your animations and the starting delay.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationDelegate:

Sets the delegate for any animation messages.

+ (void)setAnimationDelegate:(id)delegate
Parameters
delegate

An object that defines the methods registered using the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods. The view maintains a strong reference to this object for the duration of the animation.

Discussion

You can specify an animation delegate in cases where you want to receive messages when the animation starts or stops. After calling this method, you should call the setAnimationWillStartSelector: and setAnimationDidStopSelector: methods as needed to register appropriate selectors. By default, the animation delegate is set to nil.

You primarily use this method to set the delegate for animation blocks created using the begin/commit animation methods. Calling this method from outside an animation block does nothing.

Use of this method is discouraged in iOS 4.0 and later. If you are using the block-based animation methods, you can include your delegate’s start and end code directly inside your block.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationDidStopSelector:

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

+ (void)setAnimationDidStopSelector:(SEL)selector
Parameters
selector

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

  • animationID

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

  • finished

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

  • context

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

Discussion

If you specify an animation delegate for a begin/commit set of animations, you use this method to specify the selector to call after the animations end. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: and commitAnimations methods. This selector is set to NULL by default.

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.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationDuration:

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

+ (void)setAnimationDuration:(NSTimeInterval)duration
Parameters
duration

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

Discussion

If you specify your animations using begin/commit set of methods, you use this method to specify the duration of the animations. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: and commitAnimations methods. And you must call this method prior to changing the animatable properties of your views. The default value is 0.2 seconds.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationRepeatAutoreverses:

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

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses
Parameters
repeatAutoreverses

Specify YES to enable autoreversing or NO to disable it.

Discussion

If you enable autoreversing, a single animation cycle changes the properties being animated to their new values and then back to their original values. At the end of the animations, the affected views are then updated immediately to reflect the new values. This method does nothing if called from outside of an animation block. By default, autoreversing is disabled.

If you combine autoreversing with a repeat count (settable using the setAnimationRepeatCount: method), you can create animations that shift back and forth between the old and new values the specified number of times. However, remember that the repeat count indicates the number of complete cycles. If you specify an integral value such as 2.0, the animation ends on the old value, which is followed by the view immediately updating itself to show the new value, which might be jarring. If you want the animation to end on the new value (instead of the old value), add 0.5 to the repeat count value. This adds an extra half cycle to the animation.

Use of this method is discouraged in iOS 4.0 and later. Instead, you should use theanimateWithDuration:delay:options:animations:completion: method to specify your animations and the animation options.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationRepeatCount:

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

+ (void)setAnimationRepeatCount:(float)repeatCount
Parameters
repeatCount

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

Discussion

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

If you pass the UIViewAnimationOptionRepeat option to the animateWithDuration:delay:options:animations:completion: method without setting an explicit repeat count, the animation repeats indefinitely. If you want the animation to repeat a finite number of times, call this method from inside your block.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationsEnabled:

Sets whether animations are enabled.

+ (void)setAnimationsEnabled:(BOOL)enabled
Parameters
enabled

Specify YES to enable animations or NO to disable them.

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationStartDate:

Sets the start time for the current animation block.

+ (void)setAnimationStartDate:(NSDate *)startTime
Parameters
startTime

The time to begin the animations.

Discussion

Call this method between the beginAnimations:context: and commitAnimations methods to specify the start time for that set of animations. And call this method prior to changing the animatable properties of your views. (Do not call this method in conjunction with a block-based animation.) If you do not call this method, the start time is set to the value returned by the CFAbsoluteTimeGetCurrent function, which begins the animations as soon as possible.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationTransition:forView:cache:

Sets a transition to apply to a view during an animation block.

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
Parameters
transition

A transition to apply to view. Possible values are described in UIViewAnimationTransition.

view

The view to apply the transition to.

cache

If YES, the before and after images of view are rendered once and used to create the frames in the animation. Caching can improve performance but if you set this parameter to YES, you must not update the view or its subviews during the transition. Updating the view and its subviews may interfere with the caching behaviors and cause the view contents to be rendered incorrectly (or in the wrong location) during the animation. You must wait until the transition ends to update the view.

If NO, the view and its contents must be updated for each frame of the transition animation, which may noticeably affect the frame rate.

Discussion

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

  1. Begin an animation block.

  2. Set the transition on the container view.

  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 the transitionWithView:duration:options:animations:completion: method to perform transitions instead.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setAnimationWillStartSelector:

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

+ (void)setAnimationWillStartSelector:(SEL)selector
Parameters
selector

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

  • animationID

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

  • context

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

Discussion

If you specify an animation delegate for a begin/commit set of animations, you use this method to specify the selector to call before the animations begin. This method does nothing if called from outside of an animation block. It must be called between calls to the beginAnimations:context: and commitAnimations methods. This selector is set to NULL by default.

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.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

transitionFromView:toView:duration:options:completion:

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

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

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

toView

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

duration

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

options

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

completion

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

Discussion

This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. By default, the view in fromView is replaced in the view hierarchy by the view in toView. If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them.

This method modifies the views in their view hierarchy only. It does not modify your application’s view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change.

The view transition starts immediately unless another animation is already in-flight, in which case it starts immediately after the current animation finishes.

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
UIView.h

transitionWithView:duration:options:animations:completion:

Creates a transition animation for the specified container view.

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

The container view that performs the transition.

duration

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

options

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

animations

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

completion

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

Discussion

This method applies a transition to the specified view so that you can make state changes to it. The block you specify in the animations parameter contains whatever state changes you want to make. You can use this block to add, remove, show, or hide subviews of the specified view. If you want to incorporate other animatable changes, you must include the UIViewAnimationOptionAllowAnimatedContent key in the options parameter.

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

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

During an animation, user interactions are temporarily disabled for the views being animated. (Prior to iOS 5, user interactions are disabled for the entire application.) If you want users to be able to interact with the views, include the UIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
UIView.h

Instance Methods

addConstraint:

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

- (void)addConstraint:(NSLayoutConstraint *)constraint
Parameters
constraint

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

addConstraints:

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

- (void)addConstraints:(NSArray *)constraints
Parameters
constraints

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Related Sample Code
Declared In
UIView.h

addGestureRecognizer:

Attaches a gesture recognizer to the view.

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
Parameters
gestureRecognizer

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

Discussion

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

Availability
  • Available in iOS 3.2 and later.
Declared In
UIView.h

addMotionEffect:

Begins applying a motion effect to the view.

- (void)addMotionEffect:(UIMotionEffect *)effect
Parameters
effect

The motion effect.

Discussion

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

addSubview:

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

- (void)addSubview:(UIView *)view
Parameters
view

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

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

alignmentRectForFrame:

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

- (CGRect)alignmentRectForFrame:(CGRect)frame
Parameters
frame

The frame whose corresponding alignment rectangle is desired.

Return Value

The alignment rectangle for the specified frame.

Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

alignmentRectInsets

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

- (UIEdgeInsets)alignmentRectInsets
Return Value

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

Discussion

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

Custom views whose content location can’t be expressed by a simple set of insets should override alignmentRectForFrame: and frameForAlignmentRect: to describe their custom transform between alignment rectangle and frame.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

bringSubviewToFront:

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

- (void)bringSubviewToFront:(UIView *)view
Parameters
view

The subview to move to the front.

Discussion

This method moves the specified view to the end of the array of views in the subviews property.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

constraints

Returns the constraints held by the view.

- (NSArray *)constraints
Return Value

The constraints held by the view.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

constraintsAffectingLayoutForAxis:

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

- (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis
Parameters
axis

The axis for which the constraints should be found.

Return Value

The constraints impacting the layout of the view for the specified axis.

Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

contentCompressionResistancePriorityForAxis:

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

- (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis
Parameters
axis

The axis of the view that might be reduced.

Return Value

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

Discussion

The constraint-based layout system uses these priorities when determining the best layout for views that are encountering constraints that would require them to be smaller than their intrinsic size.

Subclasses should not override this method. Instead, custom views should set default values for their content on creation, typically to NSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

contentHuggingPriorityForAxis:

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

- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis
Parameters
axis

The axis of the view that might be enlarged.

Return Value

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

convertPoint:fromView:

Converts a point from the coordinate system of a given view to that of the receiver.

- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view
Parameters
point

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

view

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

Return Value

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.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
Parameters
point

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

view

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

Return Value

The point converted to the coordinate system of view.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

convertRect:fromView:

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

- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view
Parameters
rect

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

view

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

Return Value

The converted rectangle.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

convertRect:toView:

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

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

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

view

The view that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

Return Value

The converted rectangle.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

decodeRestorableStateWithCoder:

Decodes and restores state-related information for the view.

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
Parameters
coder

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

didAddSubview:

Tells the view that a subview was added.

- (void)didAddSubview:(UIView *)subview
Parameters
subview

The view that was added as a subview.

Discussion

The default implementation of this method does nothing. Subclasses can override it to perform additional actions when subviews are added. This method is called in response to adding a subview using any of the relevant view methods.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

didMoveToSuperview

Tells the view that its superview changed.

- (void)didMoveToSuperview
Discussion

The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

didMoveToWindow

Tells the view that its window object changed.

- (void)didMoveToWindow
Discussion

The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

drawRect:

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

- (void)drawRect:(CGRect)rect
Parameters
rect

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

Discussion

The default implementation of this method does nothing. Subclasses that use technologies such as Core Graphics and UIKit to draw their view’s content should override this method and implement their drawing code there. You do not need to override this method if your view sets its content in other ways. For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object.

By the time this method is called, UIKit has configured the drawing environment appropriately for your view and you can simply call whatever drawing methods and functions you need to render your content. Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that context so that its origin matches the origin of your view’s bounds rectangle. You can get a reference to the graphics context using the UIGraphicsGetCurrentContext function, but do not establish a strong reference to the graphics context because it can change between calls to the drawRect: method.

Similarly, if you draw using OpenGL ES and the GLKView class, GLKit configures the underlying OpenGL ES context appropriately for your view before calling this method (or the glkView:drawInRect: method of your GLKView delegate), so you can simply issue whatever OpenGL ES commands you need to render your content. For more information about how to draw using OpenGL ES, see OpenGL ES Programming Guide for iOS.

You should limit any drawing to the rectangle specified in the rect parameter. In addition, if the opaque property of your view is set to YES, your drawRect: method must totally fill the specified rectangle with opaque content.

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

drawRect:forViewPrintFormatter:

Implemented to draw the view’s content for printing.

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

A rectangle that defines the area for drawing printable content.

formatter

An instance of UIViewPrintFormatter obtained by calling the viewPrintFormatter method.

Discussion

You implement this method if you want a view’s printed content to appear differently than its displayed content. If you add a view print formatter to a print job but do not implement this method, the view’s drawRect: method is called to provide the content for printing.

For more information about how to implement a custom drawing routine for printed content, see Drawing and Printing Guide for iOS.

Availability
  • Available in iOS 4.2 and later.
Declared In
UIPrintFormatter.h

drawViewHierarchyInRect:afterScreenUpdates:

Renders a snapshot of the complete view hierarchy as visible onscreen into the current context.

- (BOOL)drawViewHierarchyInRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates
Parameters
rect

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

afterUpdates

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

Return Value

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

Discussion

Use this method when you want to apply a graphical effect, such as a blur, to a view snapshot. This method is not as fast as the snapshotViewAfterScreenUpdates: method.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

encodeRestorableStateWithCoder:

Encodes state-related information for the view.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
Parameters
coder

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

Discussion

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

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

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

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

endEditing:

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

- (BOOL)endEditing:(BOOL)force
Parameters
force

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

Return Value

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

Discussion

This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITextField.h

exchangeSubviewAtIndex:withSubviewAtIndex:

Exchanges the subviews at the specified indices.

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

The index of the first subview in the receiver.

index2

The index of the second subview in the receiver.

Discussion

Each index represents the position of the corresponding view in the array in the subviews property. Subview indices start at 0 and cannot be greater than the number of subviews. This method does not change the superview of either view but simply swaps their positions in the subviews array.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

exerciseAmbiguityInLayout

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

- (void)exerciseAmbiguityInLayout
Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

frameForAlignmentRect:

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

- (CGRect)frameForAlignmentRect:(CGRect)alignmentRect
Parameters
alignmentRect

The alignment rectangle whose corresponding frame is desired.

Return Value

The frame for the specified alignment rectangle

Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

gestureRecognizerShouldBegin:

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

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
Parameters
gestureRecognizer

The gesture recognizer that is attempting to transition out of the UIGestureRecognizerStatePossible state.

Return Value

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

Discussion

Subclasses may override this method and use it to prevent the recognition of particular gestures. For example, the UISlider class uses this method to prevent swipes parallel to the slider’s travel direction and that start in the thumb.

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

The default implementation of this method returns YES.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

hasAmbiguousLayout

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

- (BOOL)hasAmbiguousLayout
Return Value

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

Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

hitTest:withEvent:

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

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

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

event

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

Return Value

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

Discussion

This method traverses the view hierarchy by calling the pointInside:withEvent: method of each subview to determine which subview should receive a touch event. If pointInside:withEvent: returns YES, then the subview’s hierarchy is similarly traversed until the frontmost view containing the specified point is found. If a view does not contain the point, its branch of the view hierarchy is ignored. You rarely need to call this method yourself, but you might override it to hide touch events from subviews.

This method ignores view objects that are hidden, that have disabled user interactions, or have an alpha level less than 0.01. This method does not take the view’s content into account when determining a hit. Thus, a view can still be returned even if the specified point is in a transparent portion of that view’s content.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

initWithFrame:

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

- (id)initWithFrame:(CGRect)aRect
Parameters
aRect

The frame rectangle for the view, measured in points. The origin of the frame is relative to the superview in which you plan to add it. This method uses the frame rectangle to set the center and bounds properties accordingly.

Return Value

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

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

insertSubview:aboveSubview:

Inserts a view above another view in the view hierarchy.

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

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

siblingSubview

The sibling view that will be behind the inserted view.

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

insertSubview:atIndex:

Inserts a subview at the specified index.

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

The view to insert. This value cannot be nil.

index

The index in the array of the subviews property at which to insert the view. Subview indices start at 0 and cannot be greater than the number of subviews.

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

insertSubview:belowSubview:

Inserts a view below another view in the view hierarchy.

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

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

siblingSubview

The sibling view that will be above the inserted view.

Discussion

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

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

intrinsicContentSize

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

- (CGSize)intrinsicContentSize
Return Value

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

Discussion

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

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

invalidateIntrinsicContentSize

Invalidates the view’s intrinsic content size.

- (void)invalidateIntrinsicContentSize
Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

isDescendantOfView:

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

- (BOOL)isDescendantOfView:(UIView *)view
Parameters
view

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

Return Value

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

layoutIfNeeded

Lays out the subviews immediately.

- (void)layoutIfNeeded
Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

layoutSubviews

Lays out subviews.

- (void)layoutSubviews
Discussion

The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.

Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You can use your implementation to set the frame rectangles of your subviews directly.

You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the layoutIfNeeded method.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

needsUpdateConstraints

Returns whether the view’s constraints need updating.

- (BOOL)needsUpdateConstraints
Return Value

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

Discussion

The constraint-based layout system uses the return value of this method to determine whether it needs to call updateConstraints on your view as part of its normal layout pass.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

pointInside:withEvent:

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

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

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

event

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

Return Value

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

removeConstraint:

Removes the specified constraint from the view.

- (void)removeConstraint:(NSLayoutConstraint *)constraint
Parameters
constraint

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

removeConstraints:

Removes the specified constraints from the view.

- (void)removeConstraints:(NSArray *)constraints
Parameters
constraints

The constraints to remove.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

removeFromSuperview

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

- (void)removeFromSuperview
Discussion

If the 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 view in the subtree of the view you are removing.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

removeGestureRecognizer:

Detaches a gesture recognizer from the receiving view.

- (void)removeGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
Parameters
gestureRecognizer

An object whose class descends from the UIGestureRecognizer class.

Discussion

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

Availability
  • Available in iOS 3.2 and later.
Declared In
UIView.h

removeMotionEffect:

Stops applying a motion effect to the view.

- (void)removeMotionEffect:(UIMotionEffect *)effect
Parameters
effect

The motion effect.

Discussion

Any affected presentation values animate to their post-removal values using the present UIView animation context.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

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

- (UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets
Parameters
rect

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

afterUpdates

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

capInsets

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

Return Value

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

Discussion

This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view with stretchable insets. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself.

Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot view’s layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content.

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

If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: method instead.

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

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

sendSubviewToBack:

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

- (void)sendSubviewToBack:(UIView *)view
Parameters
view

The subview to move to the back.

Discussion

This method moves the specified view to the beginning of the array of views in the subviews property.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIView.h

setContentCompressionResistancePriority:forAxis:

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

- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis
Parameters
priority

The new priority.

axis

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

Discussion

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

Subclasses should not override this method.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

setContentHuggingPriority:forAxis:

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

- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis
Parameters
priority

The new priority.

axis

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

Discussion

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

Subclasses should not override this method.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

setNeedsDisplay

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

- (void)setNeedsDisplay
Discussion

You can use this method or the setNeedsDisplayInRect: to notify the system that your view’s contents need to be redrawn. This method makes a note of the request and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setNeedsDisplayInRect:

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

- (void)setNeedsDisplayInRect:(CGRect)invalidRect
Parameters
invalidRect

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

Discussion

You can use this method or the setNeedsDisplay to notify the system that your view’s contents need to be redrawn. This method adds the specified rectangle into the view’s current list of invalid rectangles and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

setNeedsLayout

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

- (void)setNeedsLayout
Discussion

Call this method on your 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 an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIView.h

setNeedsUpdateConstraints

Controls whether the view’s constraints need updating.

- (void)setNeedsUpdateConstraints
Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

setTranslatesAutoresizingMaskIntoConstraints:

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

- (void)setTranslatesAutoresizingMaskIntoConstraints:(BOOL)flag
Parameters
flag

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

sizeThatFits:

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

- (CGSize)sizeThatFits:(CGSize)size
Parameters
size

The current size of the receiver.

Return Value

A new size that fits the receiver’s subviews.

Discussion

The default implementation of this method returns the size portion of the view’s bounds rectangle. Subclasses can override this method to return a custom value based on the desired layout of any subviews. For example, a UISwitch object returns a fixed size value that represents the standard size of a switch view, and a UIImageView object returns the size of the image it is currently displaying.

This method does not resize the receiver.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

sizeToFit

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

- (void)sizeToFit
Discussion

Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.

You should not override this method. If you want to change the default sizing information for your view, override the sizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

snapshotViewAfterScreenUpdates:

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

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates
Parameters
afterUpdates

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

Return Value

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

Discussion

This method very efficiently captures the current rendered appearance of a view and uses it to build a new snapshot view. You can use the returned view as a visual stand-in for the current view in your app. For example, you might use a snapshot view for animations where updating a large view hierarchy might be expensive. Because the content is captured from the already rendered content, this method reflects the current visual appearance of the view and is not updated to reflect animations that are scheduled or in progress. However, calling this method is faster than trying to render the contents of the current view into a bitmap image yourself.

Because the returned snapshot is a view object, you can modify it and its layer object as needed. However, you cannot change the contents property of the snapshot view’s layer; attempts to do so fail silently. If the current view is not yet rendered, perhaps because it is not yet onscreen, the snapshot view has no visible content.

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

If you want to apply a graphical effect, such as blur, to a snapshot, use the drawViewHierarchyInRect:afterScreenUpdates: method instead.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

systemLayoutSizeFittingSize:

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

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize
Parameters
targetSize

Indicates whether you want the smallest or largest possible size that meets the constraints. See “Fitting Size” for accepted values.

Return Value

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

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

tintColorDidChange

Called by the system when the tintColor property changes.

- (void)tintColorDidChange
Discussion

The system calls this method on a view when your code changes the value of the tintColor property on that view. In addition, the system calls this method on a subview that inherits a changed interaction tint color.

In your implementation, refresh the view rendering as needed.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

translatesAutoresizingMaskIntoConstraints

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

- (BOOL)translatesAutoresizingMaskIntoConstraints
Return Value

YES if the view’s autoresizing mask is translated into constraints for the constraint-based layout system, NO otherwise.

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Related Sample Code
Declared In
UIView.h

updateConstraints

Updates constraints for the view.

- (void)updateConstraints
Discussion

Custom views that set up constraints themselves should do so by overriding this method. When your custom view notes that a change has been made to the view that invalidates one of its constraints, it should immediately remove that constraint, and then call setNeedsUpdateConstraints to note that constraints need to be updated. Before layout is performed, your implementation of updateConstraints will be invoked, allowing you to verify that all necessary constraints for your content are in place at a time when your custom view’s properties are not changing.

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

updateConstraintsIfNeeded

Updates the constraints for the receiving view and its subviews.

- (void)updateConstraintsIfNeeded
Discussion

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

Subclasses should not override this method.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

viewForBaselineLayout

Returns a view used to satisfy baseline constraints.

- (UIView *)viewForBaselineLayout
Return Value

The view the constraint system should use to satisfy baseline constraints

Discussion

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

Availability
  • Available in iOS 6.0 and later.
Declared In
UIView.h

viewPrintFormatter

Returns a print formatter for the receiving view.

- (UIViewPrintFormatter *)viewPrintFormatter
Return Value

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

Discussion

When initiating a print job, you can call this method to obtain an appropriate view print formatter object for your view. You can use the formatter object to configure the page layout options for your view during printing. Each time you call this method, you get a unique view print formatter object.

For more information about how to use print formatters to configure the printing behavior of your view, see Drawing and Printing Guide for iOS.

Availability
  • Available in iOS 4.2 and later.
Declared In
UIPrintFormatter.h

viewWithTag:

Returns the view whose tag matches the specified value.

- (UIView *)viewWithTag:(NSInteger)tag
Parameters
tag

The tag value to search for.

Return Value

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

Discussion

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

Availability
  • Available in iOS 2.0 and later.
See Also
Related Sample Code
Declared In
UIView.h

willMoveToSuperview:

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

- (void)willMoveToSuperview:(UIView *)newSuperview
Parameters
newSuperview

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

Discussion

The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the superview changes.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

willMoveToWindow:

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

- (void)willMoveToWindow:(UIWindow *)newWindow
Parameters
newWindow

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

Discussion

The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

willRemoveSubview:

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

- (void)willRemoveSubview:(UIView *)subview
Parameters
subview

The subview that will be removed.

Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.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,
   
   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;
Constants
UIViewAnimationOptionLayoutSubviews

Lay out subviews at commit time so that they are animated along with their parent.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionAllowUserInteraction

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionBeginFromCurrentState

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionRepeat

Repeat the animation indefinitely.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionAutoreverse

Run the animation backwards and forwards. Must be combined with the UIViewAnimationOptionRepeat option.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionOverrideInheritedDuration

Force the animation to use the original duration value specified when the animation was submitted. If this key is not present, the animation inherits the remaining duration of the in-flight animation, if any.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionOverrideInheritedCurve

Force the animation to use the original curve value specified when the animation was submitted. If this key is not present, the animation inherits the curve of the in-flight animation, if any.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionAllowAnimatedContent

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionShowHideTransitionViews

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionOverrideInheritedOptions

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

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveEaseInOut

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveEaseIn

An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveEaseOut

An ease-out curve causes the animation to begin quickly, and then slow as it completes.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionCurveLinear

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionNone

No transition is specified.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromLeft

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromRight

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

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCurlUp

A transition that curls a view up from the bottom.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCurlDown

A transition that curls a view down from the top.

Available in iOS 4.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionCrossDissolve

A transition that dissolves from one view to the next.

Available in iOS 5.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromTop

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

Available in iOS 5.0 and later.

Declared in UIView.h.

UIViewAnimationOptionTransitionFlipFromBottom

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

Available in iOS 5.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 4.0 and later.
Declared In
UIView.h

UIViewAnimationCurve

Specifies the supported animation curves.

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

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationCurveEaseIn

An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationCurveEaseOut

An ease-out curve causes the animation to begin quickly, and then slow down as it completes.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationCurveLinear

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

Available in iOS 2.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

UIViewKeyframeAnimationOptions

Key frame animation options used with the animateKeyframesWithDuration:delay:options:animations:completion: 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;
Constants
UIViewKeyframeAnimationOptionLayoutSubviews

The option to lay out subviews at commit time so that they are animated along with their parent.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionAllowUserInteraction

The option that allows the user to interact with views while they are being animated.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionBeginFromCurrentState

The option to start an animation from the current setting associated with an already in-flight animation. If this option is not present, any in-flight animations are allowed to finish before the new animation is started. If another animation is not in flight, this option has no effect.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionRepeat

The option to repeat an animation indefinitely.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionAutoreverse

The option to run an animation backwards and forwards. Must be combined with the UIViewKeyframeAnimationOptionRepeat option.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionOverrideInheritedDuration

The option to force an animation to use the original duration value specified when the animation was submitted. If this option is not present, the animation inherits the remaining duration of the in-flight animation, if any.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionOverrideInheritedOptions

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

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeLinear

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

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeDiscrete

The option to not interpolate between keyframe values, but rather to jump directly to each new keyframe value.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModePaced

The option to compute intermediate keyframe values using a simple pacing algorithm. This option results in an evenly paced animation.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeCubic

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

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewKeyframeAnimationOptionCalculationModeCubicPaced

The option to compute intermediate frames using the cubic scheme while ignoring the timing properties of the animation. Instead, timing parameters are calculated implicitly to give the animation a constant velocity.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewContentMode

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

typedef enum {
   UIViewContentModeScaleToFill,
   UIViewContentModeScaleAspectFit,
   UIViewContentModeScaleAspectFill,
   UIViewContentModeRedraw,
   UIViewContentModeCenter,
   UIViewContentModeTop,
   UIViewContentModeBottom,
   UIViewContentModeLeft,
   UIViewContentModeRight,
   UIViewContentModeTopLeft,
   UIViewContentModeTopRight,
   UIViewContentModeBottomLeft,
   UIViewContentModeBottomRight,
} UIViewContentMode;
Constants
UIViewContentModeScaleToFill

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeScaleAspectFit

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeScaleAspectFill

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeRedraw

The option to redisplay the view when the bounds change by invoking the setNeedsDisplay method.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeCenter

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

UIViewContentModeTop

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

UIViewContentModeBottom

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

UIViewContentModeLeft

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeRight

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeTopLeft

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeTopRight

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeBottomLeft

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewContentModeBottomRight

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

Available in iOS 2.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

UILayoutConstraintAxis

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

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

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

Available in iOS 6.0 and later.

Declared in UIView.h.

UILayoutConstraintAxisVertical

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

Available in iOS 6.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentMode

The tint adjustment mode for the view.

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

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

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentModeNormal

The view's tintColor property returns the completely unmodified tint color of the view.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentModeDimmed

The view's tintColor property returns a desaturated, dimmed version of the view's original tint color.

Available in iOS 7.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

UISystemAnimation

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

typedef enum{
   UISystemAnimationDelete,
} UISystemAnimation;
Constants
UISystemAnimationDelete

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

Available in iOS 7.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIView.h

Fitting Size

View fitting options used in the systemLayoutSizeFittingSize: method.

const CGSize UILayoutFittingCompressedSize;
const CGSize UILayoutFittingExpandedSize;
Constants
UILayoutFittingCompressedSize

The option to use the smallest possible size.

Available in iOS 6.0 and later.

Declared in UIView.h.

UILayoutFittingExpandedSize

The option to use the largest possible size.

Available in iOS 6.0 and later.

Declared in UIView.h.

UIView Intrinsic Metric Constant

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

const CGFloat UIViewNoIntrinsicMetric;
Constants
UIViewNoIntrinsicMetric

The absence of an intrinsic metric for a given numeric view property.

Available in iOS 6.0 and later.

Declared in UIView.h.

UIViewAutoresizing

Options for automatic view resizing.

enum {
   UIViewAutoresizingNone                 = 0,
   UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
   UIViewAutoresizingFlexibleWidth        = 1 << 1,
   UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
   UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
   UIViewAutoresizingFlexibleHeight       = 1 << 4,
   UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
Constants
UIViewAutoresizingNone

The option for indicating that the view does not resize.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleLeftMargin

Resizing performed by expanding or shrinking a view in the direction of the left margin.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleWidth

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleRightMargin

Resizing performed by expanding or shrinking a view in the direction of the right margin.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleTopMargin

Resizing performed by expanding or shrinking a view in the direction of the top margin.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleHeight

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

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAutoresizingFlexibleBottomMargin

Resizing performed by expanding or shrinking a view in the direction of the bottom margin.

Available in iOS 2.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h

UIViewAnimationTransition

Animation transition options for use in an animation block object.

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

The option for indicating that no transition is specified.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionFlipFromLeft

A transition that flips a view around a vertical axis from left to right. The left side of the view moves towards the front and right side towards the back.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionFlipFromRight

A transition that flips a view around a vertical axis from right to left. The right side of the view moves towards the front and left side towards the back.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionCurlUp

A transition that curls a view up from the bottom.

Available in iOS 2.0 and later.

Declared in UIView.h.

UIViewAnimationTransitionCurlDown

A transition that curls a view down from the top.

Available in iOS 2.0 and later.

Declared in UIView.h.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIView.h