/* NSLayoutAnchor.h

 Copyright (c) 2015, Apple Inc. All rights reserved.
*/

#import <Foundation/Foundation.h>

@class NSLayoutConstraint, NSLayoutAnchor;


/* An NSLayoutAnchor represents an edge or dimension of a layout item. Its concrete
 subclasses allow concise creation of constraints.

   一个布局锚点代表一个布局 item 的 边界 和 维度(大小)。

 Instead of invoking

 +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]

 directly, you can instead do something like this:

 [myView.topAnchor constraintEqualToAnchor:otherView.topAnchor constant:10];

 The -constraint* methods are available in multiple flavors to support use of different

 relations and omission of unused options.

 */

NS_CLASS_AVAILABLE_IOS(9_0)      // iOS9 才开始用



// 约束锚点分类
@interface NSLayoutAnchor<AnchorType> : NSObject

// thisAnchor = otherAnchor
/* These methods return an inactive constraint of the form thisAnchor = otherAnchor.
   这个方法会创建一个不活跃的约束。 格式是  thisAnchor = otherAnchor
 */
// 一个 view 的锚点等于另一 view 的锚点
- (NSLayoutConstraint *)constraintEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor;

// 一个 view 的锚点大于等于另一 view 的锚点
- (NSLayoutConstraint *)constraintGreaterThanOrEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor;

// 一个 view 的锚点小于等于另一 view 的锚点
- (NSLayoutConstraint *)constraintLessThanOrEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor;







// thisAnchor = otherAnchor + constant.
/* These methods return an inactive constraint of the form thisAnchor = otherAnchor + constant.
   这个方法会返回一个激活的约束。 thisAnchor = otherAnchor + constant.
 */

- (NSLayoutConstraint *)constraintEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor constant:(CGFloat)c;

- (NSLayoutConstraint *)constraintGreaterThanOrEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor constant:(CGFloat)c;

- (NSLayoutConstraint *)constraintLessThanOrEqualToAnchor:(NSLayoutAnchor<AnchorType> *)anchor constant:(CGFloat)c;

@end





/* Axis-specific subclasses for location anchors: top/bottom, leading/trailing, baseline, etc.

 */

@class NSLayoutXAxisAnchor, NSLayoutYAxisAnchor;

NS_CLASS_AVAILABLE_IOS(9_0)

@interface NSLayoutXAxisAnchor : NSLayoutAnchor<NSLayoutXAxisAnchor *>

@end

NS_CLASS_AVAILABLE_IOS(9_0)

@interface NSLayoutYAxisAnchor : NSLayoutAnchor<NSLayoutYAxisAnchor *>

@end




// 这些约束是用来设置宽度和高度的
/* This layout anchor subclass is used for sizes (width & height).

 */

@class NSLayoutDimension;

NS_CLASS_AVAILABLE_IOS(9_0)

@interface NSLayoutDimension : NSLayoutAnchor<NSLayoutDimension *>



/* These methods return an inactive constraint of the form

 thisVariable = constant.

*/

- (NSLayoutConstraint *)constraintEqualToConstant:(CGFloat)c;
- (NSLayoutConstraint *)constraintGreaterThanOrEqualToConstant:(CGFloat)c;
- (NSLayoutConstraint *)constraintLessThanOrEqualToConstant:(CGFloat)c;





/* These methods return an inactive constraint of the form

 thisAnchor = otherAnchor * multiplier.

*/

- (NSLayoutConstraint *)constraintEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m;
- (NSLayoutConstraint *)constraintGreaterThanOrEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m;
- (NSLayoutConstraint *)constraintLessThanOrEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m;



/* These methods return an inactive constraint of the form

 thisAnchor = otherAnchor * multiplier + constant.

*/

- (NSLayoutConstraint *)constraintEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m constant:(CGFloat)c;
- (NSLayoutConstraint *)constraintGreaterThanOrEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m constant:(CGFloat)c;
- (NSLayoutConstraint *)constraintLessThanOrEqualToAnchor:(NSLayoutDimension *)anchor multiplier:(CGFloat)m constant:(CGFloat)c;

@end

results matching ""

    No results matching ""