MASConstraintMaker.h 5.2 KB

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