MASConstraintMaker.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // MASConstraintBuilder.h
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 20/07/13.
  6. // Copyright (c) 2013 cloudling. All rights reserved.
  7. //
  8. #import "MASConstraint.h"
  9. #import "MASUtilities.h"
  10. typedef NS_OPTIONS(NSInteger, MASAttribute) {
  11. MASAttributeLeft = 1 << NSLayoutAttributeLeft,
  12. MASAttributeRight = 1 << NSLayoutAttributeRight,
  13. MASAttributeTop = 1 << NSLayoutAttributeTop,
  14. MASAttributeBottom = 1 << NSLayoutAttributeBottom,
  15. MASAttributeLeading = 1 << NSLayoutAttributeLeading,
  16. MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
  17. MASAttributeWidth = 1 << NSLayoutAttributeWidth,
  18. MASAttributeHeight = 1 << NSLayoutAttributeHeight,
  19. MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
  20. MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
  21. MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
  22. #if TARGET_OS_IPHONE
  23. MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
  24. MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
  25. MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
  26. MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
  27. MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
  28. MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
  29. MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
  30. MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,
  31. #endif
  32. };
  33. /**
  34. * Provides factory methods for creating MASConstraints.
  35. * Constraints are collected until they are ready to be installed
  36. *
  37. */
  38. @interface MASConstraintMaker : NSObject
  39. /**
  40. * The following properties return a new MASViewConstraint
  41. * with the first item set to the makers associated view and the appropriate MASViewAttribute
  42. */
  43. @property (nonatomic, strong, readonly) MASConstraint *left;
  44. @property (nonatomic, strong, readonly) MASConstraint *top;
  45. @property (nonatomic, strong, readonly) MASConstraint *right;
  46. @property (nonatomic, strong, readonly) MASConstraint *bottom;
  47. @property (nonatomic, strong, readonly) MASConstraint *leading;
  48. @property (nonatomic, strong, readonly) MASConstraint *trailing;
  49. @property (nonatomic, strong, readonly) MASConstraint *width;
  50. @property (nonatomic, strong, readonly) MASConstraint *height;
  51. @property (nonatomic, strong, readonly) MASConstraint *centerX;
  52. @property (nonatomic, strong, readonly) MASConstraint *centerY;
  53. @property (nonatomic, strong, readonly) MASConstraint *baseline;
  54. #if TARGET_OS_IPHONE
  55. @property (nonatomic, strong, readonly) MASConstraint *leftMargin;
  56. @property (nonatomic, strong, readonly) MASConstraint *rightMargin;
  57. @property (nonatomic, strong, readonly) MASConstraint *topMargin;
  58. @property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
  59. @property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
  60. @property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
  61. @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
  62. @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
  63. #endif
  64. /**
  65. * Returns a block which creates a new MASCompositeConstraint with the first item set
  66. * to the makers associated view and children corresponding to the set bits in the
  67. * MASAttribute parameter. Combine multiple attributes via binary-or.
  68. */
  69. @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
  70. /**
  71. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
  72. * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
  73. * with the first item set to the makers associated view
  74. */
  75. @property (nonatomic, strong, readonly) MASConstraint *edges;
  76. /**
  77. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
  78. * which generates the appropriate MASViewConstraint children (width, height)
  79. * with the first item set to the makers associated view
  80. */
  81. @property (nonatomic, strong, readonly) MASConstraint *size;
  82. /**
  83. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
  84. * which generates the appropriate MASViewConstraint children (centerX, centerY)
  85. * with the first item set to the makers associated view
  86. */
  87. @property (nonatomic, strong, readonly) MASConstraint *center;
  88. /**
  89. * Whether or not to check for an existing constraint instead of adding constraint
  90. */
  91. @property (nonatomic, assign) BOOL updateExisting;
  92. /**
  93. * Whether or not to remove existing constraints prior to installing
  94. */
  95. @property (nonatomic, assign) BOOL removeExisting;
  96. /**
  97. * initialises the maker with a default view
  98. *
  99. * @param view any MASConstrait are created with this view as the first item
  100. *
  101. * @return a new MASConstraintMaker
  102. */
  103. - (id)initWithView:(MAS_VIEW *)view;
  104. /**
  105. * Calls install method on any MASConstraints which have been created by this maker
  106. *
  107. * @return an array of all the installed MASConstraints
  108. */
  109. - (NSArray *)install;
  110. - (MASConstraint * (^)(dispatch_block_t))group;
  111. @end