UIView

来源:互联网 发布:网络监控用什么软件 编辑:程序博客网 时间:2024/06/07 03:43

Next

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 subclassingUIView 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, aUILabel object draws a text string and a UIImageView object draws an image.

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

  • Drawing and animation
    • Views draw content in their rectangular area using technologies such as UIKit, Core Graphics, and OpenGL ES.
    • Some view properties can be animated to new values.
  • Layout and subview management
    • A view may contain zero or more subviews.
    • Each view defines its own default resizing behavior in relation to its parent view.
    • A view can define the size and position of its subviews as needed.
  • Event handling
    • A view is a responder and can handle touch events and other events defined by theUIResponder class.
    • Views can use the addGestureRecognizer: method to install gesture recognizers to handle common gestures.

Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationship between the view being embedded (known as thesubview) 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 theclipsToBounds 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. Theframe 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. Thecenter 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, seeView Programming Guide for iOS.

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


Creating a View


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

CGRect  viewRect = CGRectMake(10, 10, 100, 100);


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


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

When creating a view, it is important to assign an appropriate value to theautoresizingMask 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 thesetNeedsLayout 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’ssetNeedsDisplay 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.

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


For detailed information about the view drawing cycle and the role your views have in this cycle, seeView 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. TheUIView 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 thebeginAnimations:context: and commitAnimations class methods to mark the beginning and ending of your animations.

The following properties of the UIView class are animatable:

  •   @property frame
  •   @property bounds
  •   @property center
  •   @property transform
  •   @property alpha
  •   @property backgroundColor
  •   @property contentStretch

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 theUIView 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 subclassUIView, it is recommended that you do so only when the basicUIView class or the standard system views do not provide the capabilities that you need. Subclassing 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. BecauseUIView is a highly configurable class, there are also many ways to implement sophisticated view behaviors without overriding custom methods, which are discussed in the Alternatives to Subclassing section. In the meantime, the following list includes the methods you might consider overriding in your UIView subclasses:

  • Initialization:
    • initWithFrame: - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.
    • initWithCoder: - Implement this method if you load your view from an Interface Builder nib file and your view requires custom initialization.
    • layerClass - Implement this method only if you want your view to use a different Core Animation layer for its backing store. For example, if your view uses tiling to display a large scrollable area, you might want to override this method and return the CATiledLayer class.
  • Drawing and printing:
    • drawRect: - Implement this method if your view draws custom content. If your view does not do any custom drawing, avoid overriding this method.
    • drawRect:forViewPrintFormatter: - Implement this method only if you want to draw your view’s content differently during printing.
  • Constraints:
    • requiresConstraintBasedLayout - Implement this class method if your view class requires constraints to work properly.
    • updateConstraints - Implement this method if your view needs to create custom constraints between your subviews.
    • alignmentRectForFrame:, frameForAlignmentRect: - Implement these methods to override how your views are aligned to other views.
  • Layout:
    • sizeThatFits: - Implement this method if you want your view to have a different default size than it normally would during resizing operations. For example, you might use this method to prevent your view from shrinking to the point where subviews cannot be displayed correctly.
    • layoutSubviews - Implement this method if you need more precise control over the layout of your subviews than either the constraint or autoresizing behaviors provide.
    • didAddSubview:, willRemoveSubview: - Implement these methods as needed to track the additions and removals of subviews.
    • willMoveToSuperview:, didMoveToSuperview - Implement these methods as needed to track the movement of the current view in your view hierarchy.
    • willMoveToWindow:, didMoveToWindow - Implement these methods as needed to track the movement of your view to a different window.
  • Event Handling:
    • touchesBegan:withEvent:,touchesMoved:withEvent:, touchesEnded:withEvent:, touchesCancelled:withEvent: - Implement these methods if you need to handle touch events directly. (For gesture-based input, use gesture recognizers.)
    • gestureRecognizerShouldBegin: - Implement this method if your view handles touch events directly and might want to prevent attached gesture recognizers from triggering additional actions.

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 theframe 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 anaction 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 aUIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a genericUIView object and assign your image as the content of the view’sCALayer 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 theUIView 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


  • – initWithFrame:

Configuring a View’s Visual Appearance


  •    backgroundColor  property
  •    hidden  property
  •    alpha  property
  •    opaque  property
  •    tintColor  property
  •    tintAdjustmentMode  property
  •    clipsToBounds  property
  •    clearsContextBeforeDrawing  property
  • + layerClass
  •    layer  property

Configuring the Event-Related Behavior


  •    userInteractionEnabled  property
  •    multipleTouchEnabled  property
  •    exclusiveTouch  property

Configuring the Bounds and Frame Rectangles


  •    frame  property
  •    bounds  property
  •    center  property
  •    transform  property

Managing the View Hierarchy


  •    superview  property
  •    subviews  property
  •    window  property
  • – addSubview:
  • – bringSubviewToFront:
  • – sendSubviewToBack:
  • – removeFromSuperview
  • – insertSubview:atIndex:
  • – insertSubview:aboveSubview:
  • – insertSubview:belowSubview:
  • – exchangeSubviewAtIndex:withSubviewAtIndex:
  • – isDescendantOfView:

Configuring the Resizing Behavior


  •    autoresizingMask  property
  •    autoresizesSubviews  property
  •    contentMode  property
  • – sizeThatFits:
  • – sizeToFit
  •    contentStretch  propertyDeprecated in iOS 6.0

Laying out Subviews


  • – layoutSubviews
  • – setNeedsLayout
  • – layoutIfNeeded

Opting in to Constraint-Based Layout


  • + requiresConstraintBasedLayout
  • – translatesAutoresizingMaskIntoConstraints
  • – setTranslatesAutoresizingMaskIntoConstraints:

Managing Constraints


  • – constraints
  • – addConstraint:
  • – addConstraints:
  • – removeConstraint:
  • – removeConstraints:

Measuring in Constraint-Based Layout


  • – systemLayoutSizeFittingSize:
  • – intrinsicContentSize
  • – invalidateIntrinsicContentSize
  • – contentCompressionResistancePriorityForAxis:
  • – setContentCompressionResistancePriority:forAxis:
  • – contentHuggingPriorityForAxis:
  • – setContentHuggingPriority:forAxis:

Aligning Views with Constraint-Based Layout


  • – alignmentRectForFrame:
  • – frameForAlignmentRect:
  • – alignmentRectInsets
  • – viewForBaselineLayout

Triggering Constraint-Based Layout


  • – needsUpdateConstraints
  • – setNeedsUpdateConstraints
  • – updateConstraints
  • – updateConstraintsIfNeeded

Debugging Constraint-Based Layout


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

  • – constraintsAffectingLayoutForAxis:
  • – hasAmbiguousLayout
  • – exerciseAmbiguityInLayout

Drawing and Updating the View


  • – drawRect:
  • – setNeedsDisplay
  • – setNeedsDisplayInRect:
  •    contentScaleFactor  property
  • – tintColorDidChange

Formatting Printed View Content


  • – viewPrintFormatter
  • – drawRect:forViewPrintFormatter:

Managing Gesture Recognizers


  • – addGestureRecognizer:
  • – removeGestureRecognizer:
  •    gestureRecognizers  property
  • – gestureRecognizerShouldBegin:

Animating Views with Block Objects


  • + animateWithDuration:delay:options:animations:completion:
  • + animateWithDuration:animations:completion:
  • + animateWithDuration:animations:
  • + transitionWithView:duration:options:animations:completion:
  • + transitionFromView:toView:duration:options:completion:
  • + animateKeyframesWithDuration:delay:options:animations:completion:
  • + addKeyframeWithRelativeStartTime:relativeDuration:animations:
  • + performSystemAnimation:onViews:options:animations:completion:
  • + animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
  • + performWithoutAnimation:

Animating Views


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

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationsEnabled:
  • + setAnimationDelegate:
  • + setAnimationWillStartSelector:
  • + setAnimationDidStopSelector:
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:
  • + setAnimationTransition:forView:cache:
  • + areAnimationsEnabled

Using Motion Effects


  • – addMotionEffect:
  •    motionEffects  property
  • – removeMotionEffect:

Preserving and Restoring State


  •    restorationIdentifier  property
  • – encodeRestorableStateWithCoder:
  • – decodeRestorableStateWithCoder:

Capturing a View Snapshot


  • – snapshotViewAfterScreenUpdates:
  • – resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:
  • – drawViewHierarchyInRect:afterScreenUpdates:

Identifying the View at Runtime


  •    tag  property
  • – viewWithTag:

Converting Between View Coordinate Systems


  • – convertPoint:toView:
  • – convertPoint:fromView:
  • – convertRect:toView:
  • – convertRect:fromView:

Hit Testing in a View


  • – hitTest:withEvent:
  • – pointInside:withEvent:

Ending a View Editing Session


  • – endEditing:

Observing View-Related Changes


  • – didAddSubview:
  • – willRemoveSubview:
  • – willMoveToSuperview:
  • – didMoveToSuperview
  • – willMoveToWindow:
  • – didMoveToWindow

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 and1.0 represents totally opaque. This value affects only the current view and does not affect any of its embedded subviews.

Changes to this property can be animated.

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property backgroundColor
  •   @property opaque

Related Sample Code

  • iPhoneCoreDataRecipes
  • LocateMe
  • SimpleNetworkStreams
  • UIImagePicker Video Recorder
  • UnwindSegue

Declared In

UIView.h

autoresizesSubviews


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

@property(nonatomic) BOOL autoresizesSubviews

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property autoresizingMask

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 inUIViewAutoresizing 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 isUIViewAutoresizingNone, 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 theUIViewAutoresizingFlexibleLeftMargin 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 itslayoutSubviews method to position your subviews more precisely.

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property autoresizesSubviews

Related Sample Code

  • MVCNetworking
  • NavBar
  • PrintPhoto
  • UICatalog
  • XMLPerformance

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.

See Also

  •   @property alpha
  •   @property opaque

Related Sample Code

  • CoreTextPageViewer
  • iPhoneCoreDataRecipes
  • Reflection
  • UICatalog
  • XMLPerformance

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 thedrawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set thecontentMode 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.

See Also

  •   @property frame
  •   @property center
  •   @property transform

Related Sample Code

  • CoreTextPageViewer
  • iAdInterstitialSuite
  • SpeakHere
  • Teslameter
  • UICatalog

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 theframe properties accordingly.

Changing the frame rectangle automatically redisplays the receiver without invoking thedrawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set thecontentMode 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.

See Also

  •   @property frame
  •   @property bounds
  •   @property transform

Related Sample Code

  • AVLoupe
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • iAdInterstitialSuite
  • iAdSuite with Storyboards
  • RosyWriter

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 thedrawRect: method is called. This behavior ensures that there are no visual artifacts left over when the view’s contents are redrawn. If the view’sopaque property is also set to YES, thebackgroundColor 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 yourdrawRect: method. If your drawing code is already heavily optimized, setting this property isNO 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 toNO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value isNO.

Availability

  • Available in iOS 2.0 and later.

Related Sample Code

  • UIKit Dynamics Catalog

Declared In

UIView.h

contentMode


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

@property(nonatomic) UIViewContentMode contentMode

Discussion

The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change. This property is often used to implement resizable controls, usually in conjunction with thecontentStretch 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.

Note: You can always force the contents of a view to be redrawn by calling thesetNeedsDisplay or setNeedsDisplayInRect: method.


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.

Related Sample Code

  • iPhoneCoreDataRecipes
  • PrintPhoto
  • UIKit Dynamics Catalog
  • WiTap
  • ZoomingPDFViewer

Declared In

UIView.h

contentScaleFactor


The scale factor applied to the view.

@property(nonatomic) CGFloat contentScaleFactor

Discussion

The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels). This value is typically either1.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 is2.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 customdrawRect: method and is associated with a window, or if you use theGLKView 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 be1.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.

Related Sample Code

  • GLCameraRipple
  • Large Image Downsizing

Declared In

UIView.h

exclusiveTouch


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

@property(nonatomic, getter=isExclusiveTouch) BOOL exclusiveTouch

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property multipleTouchEnabled

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 thecenter property and the size in the bounds rectangle accordingly. The coordinates of the frame rectangle are always specified in points.

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.



Changing the frame rectangle automatically redisplays the receiver without invoking thedrawRect: method. If you want the drawRect: method invoked when the frame rectangle changes, set thecontentMode 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 thecenter property and adjust the size using the bounds property instead.

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property bounds
  •   @property center
  •   @property transform

Related Sample Code

  • CoreTextPageViewer
  • PVRTextureLoader
  • StreetScroller
  • UICatalog
  • XMLPerformance

Declared In

UIView.h

gestureRecognizers


The gesture-recognizer objects currently attached to the view.

@property(nonatomic, copy) NSArray *gestureRecognizers

Discussion

Each of these objects is an instance of a subclass of the abstract base classUIGestureRecognizer. 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 toNO 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 beNO but the receiver may still be hidden if an ancestor is hidden.

Availability

  • Available in iOS 2.0 and later.

Related Sample Code

  • CryptoExercise
  • iAdInterstitialSuite
  • Regions
  • Tabster
  • UICatalog

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 thelayerClass method. The view is the layer’s delegate.

Warning: Because the view is the layer’s delegate, never make the view the delegate of anotherCALayer object. Additionally, never change the delegate of this layer object.



Availability

  • Available in iOS 2.0 and later.

See Also

  • + layerClass

Related Sample Code

  • CoreTextPageViewer
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • MTAudioProcessingTap Audio Processor
  • PhotosByLocation
  • UnwindSegue

Declared In

UIView.h

motionEffects


The array of motion effects for the view.

@property(copy, nonatomic) NSArray *motionEffects

Availability

  • Available in iOS 7.0 and later.

Declared In

UIView.h

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 toNO, the receiver receives only the first touch event in a multi-touch sequence. The default value of this property isNO.

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

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property exclusiveTouch

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 toYES, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set toNO, the drawing system composites the view normally with other content. The default value of this property isYES.

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of1.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 toNO if the view is fully or partially transparent.

Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property backgroundColor
  •   @property alpha

Related Sample Code

  • AVMovieExporter
  • MapCallouts
  • NavBar
  • pARk
  • UICatalog

Declared In

UIView.h

restorationIdentifier


The identifier that determines whether the view supports state restoration.

@property(nonatomic, copy) NSString *restorationIdentifier

Discussion

This property indicates whether state information in the view should be preserved; it is also used to identify the view during the restoration process. The value of this property isnil 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 theencodeRestorableStateWithCoder: 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.

Important: Simply setting the value of this property is not enough to ensure that the view is preserved and restored. Its owning view controller, and all of that view controller's parent view controllers, must also have a restoration identifier. For more information about the preservation and restoration process, seeiOS App Programming Guide.


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.

See Also

  •   @property superview
  • – removeFromSuperview

Related Sample Code

  • PageControl
  • SimpleNetworkStreams

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.

See Also

  •   @property subviews
  • – removeFromSuperview

Related Sample Code

  • DateCell
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • WiTap

Declared In

UIView.h

tag


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

@property(nonatomic) NSInteger tag

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – viewWithTag:

Related Sample Code

  • Audio Mixer (MixerHost)
  • iPhoneCoreDataRecipes
  • iPhoneMixerEQGraphTest
  • iPhoneMultichannelMixerTest
  • LocateMe

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 thetintColor 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 isUIViewTintAdjustmentModeNormal.

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 thetintColorDidChange 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 isUIViewTintAdjustmentModeDimmed, then the tintColor property value is automatically dimmed.

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

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

Important: If you attempt to use a pattern color as a tint color, the system raises an exception.


Availability

  • Available in iOS 7.0 and later.

See Also

  • – tintColorDidChange

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’sanchorPoint property if it was changed. (Use the layer property to get the underlying Core Animation layer object.) The default value isCGAffineTransformIdentity.

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)

Warning: If this property is not the identity transform, the value of theframe property is undefined and therefore should be ignored.



Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property frame
  •   @property bounds
  •   @property center

Related Sample Code

  • aurioTouch2
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • RosyWriter
  • SquareCam

Declared In

UIView.h

userInteractionEnabled


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

@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 toYES, events are delivered to the view normally. The default value of this property isYES.

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 theUIViewAnimationOptionAllowUserInteraction option when configuring the animation.

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


Availability

  • Available in iOS 2.0 and later.

Declared In

UIView.h

window


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

Related Sample Code

  • AVCam
  • CoreTextPageViewer
  • iAdSuite with Storyboards

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 range0 to 1, where 0 represents the start of the overall animation and1 represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of0.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 range0 to 1 and indicates the amount of time relative to the overall animation length. If you specify a value of0, 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 theanimateKeyframesWithDuration:delay:options:animations:completion: method. To animate between different values, or to tweak the timing of your view property animations, you can call this method multiple times within a block.

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


Availability

  • Available in iOS 7.0 and later.

See Also

  • + animateKeyframesWithDuration:delay:options:animations:completion:

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 or0, 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 theaddKeyframeWithRelativeStartTime: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 anil 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.

See Also

  • + addKeyframeWithRelativeStartTime:relativeDuration:animations:

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 or0, 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 theUIViewAnimationOptionCurveEaseInOut 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.

Related Sample Code

  • iAdSuite
  • iAdSuite with Storyboards
  • MoveMe
  • Simple Gesture Recognizers
  • UIImagePicker Video Recorder

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 or0, 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 beNULL.

Discussion

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

Related Sample Code

  • AVPlayerDemo
  • DateCell
  • iAdInterstitialSuite
  • SquareCam
  • StitchedStreamPlayer

Declared In

UIView.h

animateWithDuration:delay:options:animations:completion:


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

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

Parameters

duration

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

delay

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

options

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

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

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 theUIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability

  • Available in iOS 4.0 and later.

Related Sample Code

  • UIImagePicker Video Recorder
  • UnwindSegue

Declared In

UIView.h

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


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

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

Parameters

duration

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

delay

The amount of time (measured in seconds) to wait before beginning the animations. Specify a value of0 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 of1. 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, seeUIViewAnimationOptions.

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

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.

See Also

  • + setAnimationsEnabled:
  • + performWithoutAnimation:

Related Sample Code

  • iAdSuite
  • iAdSuite with Storyboards
  • Table View Animations and Gestures

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 thesetAnimationWillStartSelector: 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 thesetAnimation… class methods) and then change the desired animatable properties of your views. When you are done changing your view properties, call thecommitAnimations 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.

See Also

  • + commitAnimations
  • + setAnimationWillStartSelector:
  • + setAnimationDidStopSelector:
  • + setAnimationDelegate:

Related Sample Code

  • AdvancedURLConnections
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • KeyboardAccessory
  • LocateMe
  • UICatalog

Declared In

UIView.h

commitAnimations


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

+ (void)commitAnimations

Discussion

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

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

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • + beginAnimations:context:

Related Sample Code

  • AdvancedURLConnections
  • Handling Touches Using Responder Methods and Gesture Recognizers
  • KeyboardAccessory
  • LocateMe
  • UICatalog

Declared In

UIView.h

layerClass


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

+ (Class)layerClass

Return Value

The class used to create the 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

  •   @property layer

Related Sample Code

  • GLES2Sample
  • GLImageProcessing
  • GLTextureAtlas
  • PVRTextureLoader
  • SpeakHere

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, seeUIViewAnimationOptions.

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 is0, this block is performed at the beginning of the next run-loop cycle. You can use anil 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.

See Also

  • + setAnimationsEnabled:
  • + areAnimationsEnabled

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 toNO, 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 thebeginAnimations:context: class method to start and the commitAnimations class method to end an animation block. The default value isNO.

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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:

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

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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:

Related Sample Code

  • AdvancedURLConnections
  • MultipeerGroupChat

Declared In

UIView.h

setAnimationDelay:


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

+ (void)setAnimationDelay:(NSTimeInterval)delay

Discussion

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

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDuration:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:

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 thesetAnimationWillStartSelector: and setAnimationDidStopSelector: methods as needed to register appropriate selectors. By default, the animation delegate is set tonil.

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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationWillStartSelector:
  • + setAnimationDidStopSelector:

Related Sample Code

  • AQOfflineRenderTest
  • iPhoneACFileConvertTest
  • iPhoneExtAudioFileConvertTest
  • iPhoneMultichannelMixerTest
  • TheElements

Declared In

UIView.h

setAnimationDidStopSelector:


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

+ (void)setAnimationDidStopSelector:(SEL)selector

Parameters

selector

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

  • animationIDAn NSString containing an optional application-supplied identifier. This is the identifier that is passed to thebeginAnimations:context: method. This argument can be nil.
  • finishedAn NSNumber object containing a Boolean value. The value isYES if the animation ran to completion before it stopped orNO if it did not.
  • contextAn optional application-supplied context. This is the context data passed to thebeginAnimations: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.

Note: Your stop selector is still called even if animations are disabled.


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

Availability

  • Available in iOS 2.0 and later.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationDelegate:
  • + setAnimationWillStartSelector:

Related Sample Code

  • AQOfflineRenderTest
  • iPhoneExtAudioFileConvertTest
  • iPhoneMultichannelMixerTest
  • MoveMe
  • TheElements

Declared In

UIView.h

setAnimationDuration:


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

+ (void)setAnimationDuration:(NSTimeInterval)duration

Parameters

duration

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

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 thebeginAnimations:context: and commitAnimations methods. And you must call this method prior to changing the animatable properties of your views. The default value is0.2 seconds.

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:

Related Sample Code

  • KeyboardAccessory
  • LocateMe
  • MoveMe
  • TheElements
  • UICatalog

Declared In

UIView.h

setAnimationRepeatAutoreverses:


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

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses

Parameters

repeatAutoreverses

Specify YES to enable autoreversing or NO to disable it.

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 thesetAnimationRepeatCount: 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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationBeginsFromCurrentState:

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 value0, 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 theanimateWithDuration: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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationStartDate:
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:

Declared In

UIView.h

setAnimationsEnabled:


Sets whether animations are enabled.

+ (void)setAnimationsEnabled:(BOOL)enabled

Parameters

enabled

Specify YES to enable animations or NO to disable them.

Discussion

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

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • + areAnimationsEnabled
  • + performWithoutAnimation:

Related Sample Code

  • Table View Animations and Gestures

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: andcommitAnimations 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.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationDuration:
  • + setAnimationDelay:
  • + setAnimationCurve:
  • + setAnimationRepeatCount:
  • + setAnimationRepeatAutoreverses:
  • + setAnimationBeginsFromCurrentState:

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 toYES, 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 ofUIView, 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 thetransitionWithView:duration:options:animations:completion: method to perform transitions instead.

Availability

  • Available in iOS 2.0 and later.

Related Sample Code

  • AQOfflineRenderTest
  • Breadcrumb
  • iPhoneMultichannelMixerTest
  • TheElements
  • UICatalog

Declared In

UIView.h

setAnimationWillStartSelector:


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

+ (void)setAnimationWillStartSelector:(SEL)selector

Parameters

selector

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

  • animationIDAn NSString containing an optional application-supplied identifier. This is the identifier string that is passed to thebeginAnimations:context: method. This argument can be nil.
  • contextAn optional application-supplied context. This is the context data passed to thebeginAnimations: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.

Note: Your start selector is not called if animations are disabled.


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

Availability

  • Available in iOS 2.0 and later.

See Also

  • + beginAnimations:context:
  • + commitAnimations
  • + setAnimationDelegate:
  • + setAnimationDidStopSelector:

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 or0, 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, seeUIViewAnimationOptions.

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

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 UIViewAnimationOptionOverrideInheritedOptions 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 theUIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability

  • Available in iOS 4.0 and later.

Related Sample Code

  • iPhoneMixerEQGraphTest
  • PrefsInCloud
  • ViewTransitions

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 or0, 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, seeUIViewAnimationOptions.

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

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

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 theUIViewAnimationOptionAllowAnimatedContent 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 theUIViewAnimationOptionAllowUserInteraction constant in the options parameter.

Availability

  • Available in iOS 4.0 and later.

Related Sample Code

  • AppPrefs

Declared In

UIView.h

Instance Methods


addConstraint:


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

- (void)addConstraint:(NSLayoutConstraint *)constraint

Parameters

constraint

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

Discussion

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

Availability

  • Available in iOS 6.0 and later.

Declared In

UIView.h

addConstraints:


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

- (void)addConstraints:(NSArray *)constraints

Parameters

constraints

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

Discussion

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

Availability

  • Available in iOS 6.0 and later.

Related Sample Code

  • PrefsInCloud
  • ViewTransitions

Declared In

UIView.h

addGestureRecognizer:


Attaches a gesture recognizer to the view.

- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer

Parameters

gestureRecognizer

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

Discussion

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

Availability

  • Available in iOS 3.2 and later.

See Also

  • – removeGestureRecognizer:
  •   @property gestureRecognizers

Related Sample Code

  • AVCam
  • AVPlayerDemo
  • DocInteraction
  • PageControl
  • StitchedStreamPlayer

Declared In

UIView.h

addMotionEffect:


Begins applying a motion effect to the view.

- (void)addMotionEffect:(UIMotionEffect *)effect

Parameters

effect

The motion effect.

Discussion

The system animates the transition to the motion effect's values using the presentUIView 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.

See Also

  • – insertSubview:atIndex:
  • – insertSubview:aboveSubview:
  • – insertSubview:belowSubview:
  • – exchangeSubviewAtIndex:withSubviewAtIndex:

Related Sample Code

  • GenericKeychain
  • GeocoderDemo
  • iAdSuite
  • iPhoneCoreDataRecipes
  • UICatalog

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’salignmentRectInsets. Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can overridealignmentRectForFrame: 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 overridealignmentRectForFrame: 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 thesubviews property.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – sendSubviewToBack:

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 toNSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh.

Availability

  • Available in iOS 6.0 and later.

See Also

  • – setContentCompressionResistancePriority:forAxis:

Declared In

UIView.h

contentHuggingPriorityForAxis:


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

- (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis

Parameters

axis

The axis of the view that might be enlarged.

Return Value

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

Discussion

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

Availability

  • Available in iOS 6.0 and later.

See Also

  • – setContentHuggingPriority:forAxis:

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 sameUIWindow object.

Return Value

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – convertPoint:toView:
  • – convertRect:toView:
  • – convertRect:fromView:

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 isnil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the sameUIWindow object.

Return Value

The point converted to the coordinate system of view.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – convertPoint:fromView:
  • – convertRect:toView:
  • – convertRect:fromView:

Related Sample Code

  • Handling Touches Using Responder Methods and Gesture Recognizers

Declared In

UIView.h

convertRect:fromView:


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

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

Parameters

rect

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

view

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

Return Value

The converted rectangle.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – convertPoint:toView:
  • – convertPoint:fromView:
  • – convertRect:toView:

Related Sample Code

  • CoreTextPageViewer

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 isnil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the sameUIWindow object.

Return Value

The converted rectangle.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – convertPoint:toView:
  • – convertPoint:fromView:
  • – convertRect:fromView:

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 theencodeRestorableStateWithCoder: method. Your implementation of this method should use any saved state information to restore the view to its previous configuration. If yourencodeRestorableStateWithCoder: method called super, this method should similarly call super at some point in its implementation.

Availability

  • Available in iOS 6.0 and later.

See Also

  • – encodeRestorableStateWithCoder:

Declared In

UIView.h

didAddSubview:


Tells the view that a subview was added.

- (void)didAddSubview:(UIView *)subview

Parameters

subview

The view that was added as a subview.

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – willRemoveSubview:
  • – addSubview:
  • – insertSubview:atIndex:
  • – insertSubview:aboveSubview:
  • – insertSubview:belowSubview:

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.

See Also

  • – willMoveToSuperview:

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.

See Also

  • – willMoveToWindow:

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 theUIGraphicsGetCurrentContext function, but do not establish a strong reference to the graphics context because it can change between calls to thedrawRect: 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 theglkView: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, seeOpenGL ES Programming Guide for iOS.

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

If you subclass UIView directly, your implementation of this method does not need to callsuper. However, if you are subclassing a different view class, you should callsuper 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.

See Also

  • – setNeedsDisplay
  • – setNeedsDisplayInRect:
  •   @property contentMode

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’sdrawRect: method is called to provide the content for printing.

For more information about how to implement a custom drawing routine for printed content, seeDrawing 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 valueNO 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, orNO 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 thesnapshotViewAfterScreenUpdates: method.

Availability

  • Available in iOS 7.0 and later.

See Also

  • – snapshotViewAfterScreenUpdates:

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

See Also

  • – decodeRestorableStateWithCoder:

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 orNO 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 toYES, the text field is never even asked; it is forced to resign.

Availability

  • Available in iOS 2.0 and later.

Related Sample Code

  • MultipeerGroupChat
  • Simple Core Data Relationships

Declared In

UITextField.h

exchangeSubviewAtIndex:withSubviewAtIndex:


Exchanges the subviews at the specified indices.

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

Parameters

index1

The index of the first subview in the receiver.

index2

The index of the second subview in the receiver.

Discussion

Each index represents the position of the corresponding view in the array in thesubviews 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 thesubviews array.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – addSubview:
  • – insertSubview:atIndex:
  • – insertSubview:aboveSubview:
  • – insertSubview:belowSubview:

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’salignmentRectInsets. Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can overridealignmentRectForFrame: 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 theUIGestureRecognizerStatePossible state.

Return Value

YES if the gesture recognizer should continue tracking touch events and use them to trigger a gesture orNO 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, theUISlider 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 theUIGestureRecognizerStatePossible state and thinks it has the events needed to move to theUIGestureRecognizerStateBegan 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 specifynil.

Return Value

The view object that is the farthest descendent the current view and contains point. Returnsnil 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. IfpointInside: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 than0.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’sclipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – pointInside:withEvent:

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 thecenter 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 theUIView class. Subclasses can override this method to perform any custom initialization but must callsuper 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 theirinitWithCoder: 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, seeResource Programming Guide.

Availability

  • Available in iOS 2.0 and later.

Related Sample Code

  • CoreTextPageViewer

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.

See Also

  • – addSubview:
  • – insertSubview:atIndex:
  • – insertSubview:belowSubview:
  • – exchangeSubviewAtIndex:withSubviewAtIndex:

Declared In

UIView.h

insertSubview:atIndex:


Inserts a subview at the specified index.

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

Parameters

view

The view to insert. This value cannot be nil.

index

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

Discussion

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

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – addSubview:
  • – insertSubview:aboveSubview:
  • – insertSubview:belowSubview:
  • – exchangeSubviewAtIndex:withSubviewAtIndex:

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.

See Also

  • – addSubview:
  • – insertSubview:atIndex:
  • – insertSubview:aboveSubview:
  • – exchangeSubviewAtIndex:withSubviewAtIndex:

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 returnUIViewNoIntrinsicMetric 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; otherwiseNO.

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. Starting with the receiver, this method traverses upward through the view hierarchy as long as superviews require layout. Then it lays out the entire tree beneath that ancestor. Therefore, calling this method can potentially force the layout of your entire view hierarchy. TheUIView implementation of this calls the equivalent CALayer method and so has the same behavior as CALayer.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – setNeedsLayout
  • – layoutSubviews

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 thesetNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call thelayoutIfNeeded method.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – setNeedsLayout
  • – layoutIfNeeded

Related Sample Code

  • GLImageProcessing
  • iPhoneCoreDataRecipes
  • MVCNetworking
  • SpeakHere
  • ZoomingPDFViewer

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 callupdateConstraints on your view as part of its normal layout pass.

Availability

  • Available in iOS 6.0 and later.

See Also

  • – setNeedsUpdateConstraints

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

Return Value

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – hitTest:withEvent:

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.

Important: Never call this method from inside your view’sdrawRect: method.


Availability

  • Available in iOS 2.0 and later.

See Also

  •   @property superview
  •   @property subviews

Related Sample Code

  • avTouch
  • CoreTextPageViewer
  • iPhoneCoreDataRecipes
  • StreetScroller
  • UICatalog

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.

See Also

  • – addGestureRecognizer:
  •   @property gestureRecognizers

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 presentUIView 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 valueNO 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 specifyUIEdgeInsetsZero 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 thecontents 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 thedrawViewHierarchyInRect: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.

See Also

  • – drawViewHierarchyInRect:afterScreenUpdates:
  • – resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:
  •   @property contentStretch

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 thesubviews property.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – bringSubviewToFront:

Related Sample Code

  • ZoomingPDFViewer

Declared In

UIView.h

setContentCompressionResistancePriority:forAxis:


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

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

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 toNSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface.

Subclasses should not override this method.

Availability

  • Available in iOS 6.0 and later.

See Also

  • – contentCompressionResistancePriorityForAxis:

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 toNSLayoutPriorityDefaultLow or NSLayoutPriorityDefaultHigh. When creating user interfaces, the layout designer can modify these priorities for specific views when the overall layout design requires different tradeoffs than the natural priorities of the views being used in the interface.

Subclasses should not override this method.

Availability

  • Available in iOS 6.0 and later.

See Also

  • – contentHuggingPriorityForAxis:

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.

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


You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the 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.

See Also

  • – drawRect:
  • – setNeedsDisplayInRect:
  •   @property contentMode

Related Sample Code

  • avTouch
  • CoreTextPageViewer
  • PocketCoreImage
  • SpeakHere
  • Teslameter

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.

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


You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the 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.

See Also

  • – drawRect:
  • – setNeedsDisplay
  •   @property contentMode

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.

See Also

  • – layoutIfNeeded
  • – layoutSubviews

Related Sample Code

  • AVPlayerDemo

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

See Also

  • – needsUpdateConstraints

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, aUISwitch object returns a fixed size value that represents the standard size of a switch view, and aUIImageView object returns the size of the image it is currently displaying.

This method does not resize the receiver.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – sizeToFit
  •   @property frame
  •   @property bounds

Related Sample Code

  • iAdSuite with Storyboards

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 thesizeThatFits: instead. That method performs any needed calculations and returns them to this method, which then makes the change.

Availability

  • Available in iOS 2.0 and later.

See Also

  • – sizeThatFits:

Related Sample Code

  • BonjourWeb
  • GeocoderDemo
  • MapCallouts
  • XMLPerformance

Declared In

UIView.h

snapshotViewAfterScreenUpdates:


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

- (UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates

Parameters

afterUpdates

A Boolean value that specifies whether the snapshot should be taken after recent changes have been incorporated. Pass the valueNO 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 thecontents 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 thedrawViewHierarchyInRect:afterScreenUpdates: method instead.

Availability

  • Available in iOS 7.0 and later.

See Also

  • – drawViewHierarchyInRect:afterScreenUpdates:
  • – resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

Declared In

UIView.h

systemLayoutSizeFittingSize:


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

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize

Parameters

targetSize

Indicates whether you want the smallest or largest possible size that meets the constraints. See“Fitting Size” 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 thetintColor property on that view. In addition, the system calls this method on a subview that inherits a changed interaction tint color.

In your implementation, refresh the view rendering as needed.


Availability

  • Available in iOS 7.0 and later.

See Also

  •   @property tintColor

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

  • PrefsInCloud
  • ViewTransitions

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

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


Availability

  • Available in iOS 6.0 and later.

Declared In

UIView.h

updateConstraintsIfNeeded


Updates the constraints for the receiving view and its subviews.

- (void)updateConstraintsIfNeeded

Discussion

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

Subclasses should not override this method.

Availability

  • Available in iOS 6.0 and later.

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, seeDrawing and Printing Guide for iOS.

Availability

  • Available in iOS 4.2 and later.

See Also

  • – drawRect:forViewPrintFormatter:

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

  •   @property tag

Related Sample Code

  • GenericKeychain
  • UICatalog

Declared In

UIView.h

willMoveToSuperview:


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

- (void)willMoveToSuperview:(UIView *)newSuperview

Parameters

newSuperview

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

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – didMoveToSuperview

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

Discussion

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

Availability

  • Available in iOS 2.0 and later.

See Also

  • – didMoveToWindow

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.

See Also

  • – removeFromSuperview
  • – didAddSubview:

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 theUIViewAnimationOptionRepeat 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 theUIViewKeyframeAnimationOptionRepeat 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 thesetNeedsDisplay 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

Option for automatic tint adjustment.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentModeNormal

Option for normal tint adjustment.

Available in iOS 7.0 and later.

Declared in UIView.h.

UIViewTintAdjustmentModeDimmed

Option for dimmed tint adjustment.

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

Next




Copyright © 2013 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2013-10-22



Provide Feedback

0 0