Next Page > Hide TOC

CAConstraint Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/QuartzCore.framework
Availability
Available in Mac OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h
Companion guides

Overview

CAConstraint represents a single layout constraint between two layers. Each CAConstraint instance encapsulates one geometry relationship between two layers on the same axis.

Sibling layers are referenced by name, using the name property of each layer. The special name superlayer is used to refer to the layer's superlayer.

For example, to specify that a layer should be horizontally centered in its superview you would use the following:

theConstraint=[CAConstraint constraintWithAttribute:kCAConstraintMidX
                                         relativeTo:@"superlayer"
                                          attribute:kCAConstraintMidX];

A maximum of two relationships must be specified per axis. If you specify constraints for the left and right edges of a layer, the width will vary. If you specify constraints for the left edge and the width, the right edge of the layer will move relative to the superlayer’s frame. Often you’ll specify only a single edge constraint, the layer’s size in the same axis will be used as the second relationship.

Important: It is possible to create constraints that result in circular references to the same attributes. In cases where the layout is unable to be computed the behavior is undefined.

Tasks

Create a New Constraint

Class Methods

constraintWithAttribute:relativeTo:attribute:

Creates and returns an CAConstraint object with the specified parameters.

+ (id)constraintWithAttribute:(CAConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CAConstraintAttribute)srcAttr

Parameters
attr

The attribute of the layer for which to create a new constraint.

srcLayer

The name of the layer that this constraint is calculated relative to.

srcAttr

The attribute of srcLayer the constraint is calculated relative to.

Return Value

A new CAConstraint object with the specified parameters. The scale of the constraint is set to 1.0. The offset of the constraint is set to 0.0.

Discussion

The value for the constraint is calculated is srcAttr.

Availability
Declared In
CAConstraintLayoutManager.h

constraintWithAttribute:relativeTo:attribute:offset:

Creates and returns an CAConstraint object with the specified parameters.

+ (id)constraintWithAttribute:(CAConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CAConstraintAttribute)srcAttr offset:(CGFloat)offset

Parameters
attr

The attribute of the layer for which to create a new constraint.

srcLayer

The name of the layer that this constraint is calculated relative to.

srcAttr

The attribute of srcLayer the constraint is calculated relative to.

offset

The offset added to the value of srcAttr.

Return Value

A new CAConstraint object with the specified parameters. The scale of the constraint is set to 1.0.

Discussion

The value for the constraint is calculated as (srcAttr + offset).

Availability
Declared In
CAConstraintLayoutManager.h

constraintWithAttribute:relativeTo:attribute:scale:offset:

Creates and returns an CAConstraint object with the specified parameters.

+ (id)constraintWithAttribute:(CAConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CAConstraintAttribute)srcAttr scale:(CGFloat)scale offset:(CGFloat)offset

Parameters
attr

The attribute of the layer for which to create a new constraint.

srcLayer

The name of the layer that this constraint is calculated relative to.

srcAttr

The attribute of srcLayer the constraint is calculated relative to.

scale

The amount to scale the value of srcAttr.

offset

The offset from the srcAttr.

Return Value

A new CAConstraint object with the specified parameters.

Discussion

The value for the constraint is calculated as (srcAttr * scale) + offset).

Availability
Declared In
CAConstraintLayoutManager.h

Instance Methods

initWithAttribute:relativeTo:attribute:scale:offset:

Returns an CAConstraint object with the specified parameters. Designated initializer.

- (id)initWithAttribute:(CAConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CAConstraintAttribute)srcAttr scale:(CGFloat)scale offset:(CGFloat)offset

Parameters
attr

The attribute of the layer for which to create a new constraint.

srcLayer

The name of the layer that this constraint is calculated relative to.

srcAttr

The attribute of srcLayer the constraint is calculated relative to.

scale

The amount to scale the value of srcAttr.

offset

The offset added to the value of srcAttr.

Return Value

An initialized constraint object using the specified parameters.

Discussion

The value for the constraint is calculated as (srcAttr * scale) + offset).

Availability
Declared In
CAConstraintLayoutManager.h

Constants

CAConstraintAttribute

These constants represent the geometric edge or axis of a constraint.

enum _CAConstraintAttribute
{
   kCAConstraintMinX,
   kCAConstraintMidX,
   kCAConstraintMaxX,
   kCAConstraintWidth,
   kCAConstraintMinY,
   kCAConstraintMidY,
   kCAConstraintMaxY,
   kCAConstraintHeight,
};

Constants
kCAConstraintMinX

The left edge of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintMidX

The horizontal location of the center of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintMaxX

The right edge of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintWidth

The width of a layer.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintMinY

The bottom edge of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintMidY

The vertical location of the center of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintMaxY

The top edge of a layer’s frame.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

kCAConstraintHeight

The height of a layer.

Available in Mac OS X v10.5 and later.

Declared in CAConstraintLayoutManager.h.

Declared In
CAConstraint.h

Constraint Attribute Type

The constraint attribute type.

typedef int CAConstraintAttribute;

Availability
Declared In
CAConstraintLayoutManager.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.