MASConstraintMaker.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // MASConstraintMaker.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 (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  23. MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline,
  24. MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline,
  25. #endif
  26. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
  27. MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
  28. MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
  29. MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
  30. MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
  31. MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
  32. MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
  33. MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
  34. MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,
  35. #endif
  36. };
  37. /**
  38. * Provides factory methods for creating MASConstraints.
  39. * Constraints are collected until they are ready to be installed
  40. *
  41. */
  42. @interface MASConstraintMaker : NSObject
  43. /**
  44. * The following properties return a new MASViewConstraint
  45. * with the first item set to the makers associated view and the appropriate MASViewAttribute
  46. */
  47. @property (nonatomic, strong, readonly) MASConstraint *left;
  48. @property (nonatomic, strong, readonly) MASConstraint *top;
  49. @property (nonatomic, strong, readonly) MASConstraint *right;
  50. @property (nonatomic, strong, readonly) MASConstraint *bottom;
  51. @property (nonatomic, strong, readonly) MASConstraint *leading;
  52. @property (nonatomic, strong, readonly) MASConstraint *trailing;
  53. @property (nonatomic, strong, readonly) MASConstraint *width;
  54. @property (nonatomic, strong, readonly) MASConstraint *height;
  55. @property (nonatomic, strong, readonly) MASConstraint *centerX;
  56. @property (nonatomic, strong, readonly) MASConstraint *centerY;
  57. @property (nonatomic, strong, readonly) MASConstraint *baseline;
  58. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  59. @property (nonatomic, strong, readonly) MASConstraint *firstBaseline;
  60. @property (nonatomic, strong, readonly) MASConstraint *lastBaseline;
  61. #endif
  62. #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
  63. @property (nonatomic, strong, readonly) MASConstraint *leftMargin;
  64. @property (nonatomic, strong, readonly) MASConstraint *rightMargin;
  65. @property (nonatomic, strong, readonly) MASConstraint *topMargin;
  66. @property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
  67. @property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
  68. @property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
  69. @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
  70. @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
  71. #endif
  72. /**
  73. * Returns a block which creates a new MASCompositeConstraint with the first item set
  74. * to the makers associated view and children corresponding to the set bits in the
  75. * MASAttribute parameter. Combine multiple attributes via binary-or.
  76. */
  77. @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
  78. /**
  79. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
  80. * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
  81. * with the first item set to the makers associated view
  82. */
  83. @property (nonatomic, strong, readonly) MASConstraint *edges;
  84. /**
  85. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
  86. * which generates the appropriate MASViewConstraint children (width, height)
  87. * with the first item set to the makers associated view
  88. */
  89. @property (nonatomic, strong, readonly) MASConstraint *size;
  90. /**
  91. * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
  92. * which generates the appropriate MASViewConstraint children (centerX, centerY)
  93. * with the first item set to the makers associated view
  94. */
  95. @property (nonatomic, strong, readonly) MASConstraint *center;
  96. /**
  97. * Whether or not to check for an existing constraint instead of adding constraint
  98. */
  99. @property (nonatomic, assign) BOOL updateExisting;
  100. /**
  101. * Whether or not to remove existing constraints prior to installing
  102. */
  103. @property (nonatomic, assign) BOOL removeExisting;
  104. /**
  105. * initialises the maker with a default view
  106. *
  107. * @param view any MASConstraint are created with this view as the first item
  108. *
  109. * @return a new MASConstraintMaker
  110. */
  111. - (id)initWithView:(MAS_VIEW *)view;
  112. /**
  113. * Calls install method on any MASConstraints which have been created by this maker
  114. *
  115. * @return an array of all the installed MASConstraints
  116. */
  117. - (NSArray *)install;
  118. - (MASConstraint * (^)(dispatch_block_t))group;
  119. @end