CAConstraint Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/QuartzCore.framework |
| Availability | Available in 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.
Tasks
Create a New Constraint
-
+ constraintWithAttribute:relativeTo:attribute:scale:offset: -
+ constraintWithAttribute:relativeTo:attribute:offset: -
+ constraintWithAttribute:relativeTo:attribute: -
– initWithAttribute:relativeTo:attribute:scale:offset:
Accessing Constraint Values
-
attributeproperty -
offsetproperty -
scaleproperty -
sourceAttributeproperty -
sourceNameproperty
Properties
attribute
The attribute the constraint affects. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
CAConstraintLayoutManager.hoffset
Offset value of the constraint attribute. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
CAConstraintLayoutManager.hscale
Scale factor of the constraint attribute. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
CAConstraintLayoutManager.hsourceAttribute
The constraint attribute of the layer the receiver is calculated relative to (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
CAConstraintLayoutManager.hsourceName
Name of the layer that the constraint is calculated relative to. (read-only)
Availability
- Available in OS X v10.6 and later.
Declared In
CAConstraintLayoutManager.hClass Methods
constraintWithAttribute:relativeTo:attribute:
Creates and returns an CAConstraint object with the specified parameters.
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
- Available in OS X v10.5 and later.
Declared In
CAConstraintLayoutManager.hconstraintWithAttribute:relativeTo:attribute:offset:
Creates and returns an CAConstraint object with the specified parameters.
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
- Available in OS X v10.5 and later.
Declared In
CAConstraintLayoutManager.hconstraintWithAttribute:relativeTo:attribute:scale:offset:
Creates and returns an CAConstraint object with the specified parameters.
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
- Available in OS X v10.5 and later.
Declared In
CAConstraintLayoutManager.hInstance Methods
initWithAttribute:relativeTo:attribute:scale:offset:
Returns an CAConstraint object with the specified parameters. Designated initializer.
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
- Available in OS X v10.5 and later.
Declared In
CAConstraintLayoutManager.hConstants
CAConstraintAttribute
These constants represent the geometric edge or axis of a constraint.
enum _CAConstraintAttribute
{
kCAConstraintMinX,
kCAConstraintMidX,
kCAConstraintMaxX,
kCAConstraintWidth,
kCAConstraintMinY,
kCAConstraintMidY,
kCAConstraintMaxY,
kCAConstraintHeight,
};
Constants
kCAConstraintMinXThe left edge of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintMidXThe horizontal location of the center of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintMaxXThe right edge of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintWidthThe width of a layer.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintMinYThe bottom edge of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintMidYThe vertical location of the center of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintMaxYThe top edge of a layer’s frame.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.kCAConstraintHeightThe height of a layer.
Available in OS X v10.5 and later.
Declared in
CAConstraintLayoutManager.h.
Declared In
CAConstraint.hConstraint Attribute Type
The constraint attribute type.
typedef int CAConstraintAttribute;
Availability
- Available in OS X v10.5 and later.
Declared In
CAConstraintLayoutManager.h© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-03-09)