Functions
The following functions are available globally.
-
Suppose you need to contrain a view so its center divides its container in certain ratio different from 1:1 (e.g. golden section):
┌─────────┐ ◆ │ │ │ │ │ │ a │┌───────┐│ │ ─│┼ ─ ─ ─ ┼│─◆ ratio = a / b │└───────┘│ │ │ │ │ │ │ │ │ │ │ b │ │ │ │ │ │ │ │ │ └─────────┘ ◆
You cannot put this ratio directly into the
multiplier
parameter of the corresponding NSLayoutConstraints relating the centers of the views, because themultiplier
would be the ratio between the distance to the center of the view (h
) and the distance to the center of the container (H
) instead:◆ ┌─────────┐ ◆ │ │ │ │ │ │ │ │ a = h H │ │┌───────┐│ │ │ │├ ─ ─ ─ ┼│─◆ multiplier = h / H │ │└───────┘│ │ ratio = a / b = h / (2 * H - h) ◆─│─ ─ ─ ─ ─│ │ │ │ │ │ │ │ b = 2 * H - h │ │ │ │ │ │ │ │ │ └─────────┘ ◆
I.e. the
multiplier
is h / H (assuming the view is the first in the definition of the constraint), but the ratio we are interested would be h / (2 * H - h) if expressed in the distances to centers.If you have a desired ratio and want to get a
multiplier
, which when applied, results in the layout dividing the container in this ratio, then you can use this function as shortcut.Detailed calculations: ratio = h / (2 * H - h) ==> 2 * H * ratio - h * ratio = h ==> 2 * H * ratio / h - ratio = 1 ==> 1 + ratio = 2 * H * ratio / h ==> (1 + ratio) / (2 * ratio) = H / h where H / h is the inverse of our
multiplier
, so the actual multiplier is (2 * ratio) / (1 + ratio).Declaration
Objective-C
static inline CGFloat MMMCenterMultiplierForRatio(CGFloat ratio)
Swift
class func centerMultiplier(forRatio ratio: CGFloat) -> CGFloat
-
Animation curve opposite to the given one, e.g. EaseIn for EaseOut.
Declaration
Objective-C
extern MMMAnimationCurve MMMReverseAnimationCurve(MMMAnimationCurve curve)
Swift
func MMMReverseAnimationCurve(_ curve: MMMAnimationCurve) -> MMMAnimationCurve
-
Undocumented
Declaration
Objective-C
static inline MMMLayoutAlignment MMMLayoutAlignmentFromHorizontalAlignment(MMMLayoutHorizontalAlignment alignment) { return (MMMLayoutAlignment)alignment; }
Swift
func MMMLayoutAlignmentFromHorizontalAlignment(_ alignment: MMMLayoutHorizontalAlignment) -> MMMLayoutAlignment
-
Undocumented
Declaration
Objective-C
static inline MMMLayoutAlignment MMMLayoutAlignmentFromVerticalAlignment(MMMLayoutVerticalAlignment alignment) { return (MMMLayoutAlignment)alignment; }
Swift
func MMMLayoutAlignmentFromVerticalAlignment(_ alignment: MMMLayoutVerticalAlignment) -> MMMLayoutAlignment
-
A dictionary built from UIEdgeInsets suitable for AutoLayout metrics. The dictionary will have 4 values under the keys named “
Top”, “ Left”, “ Bottom”, “ Right”. Declaration
Objective-C
extern NSDictionary<NSString *, NSNumber *> *_Nonnull MMMDictionaryFromUIEdgeInsets(NSString *_Nonnull prefix, UIEdgeInsets insets)
Swift
func MMMDictionaryFromUIEdgeInsets(_ prefix: String, _ insets: UIEdgeInsets) -> [String : NSNumber]