Upgrade to Pro — share decks privately, control downloads, hide ads and more …

header-comment

kameike
August 23, 2018
1.3k

 header-comment

kameike

August 23, 2018
Tweet

Transcript

  1.  

  2. /* If there aren't enough constraints in the system to

    uniquely determine layout, we say the layout is ambiguous. For example, if the only constraint in the system was x = y + 100, then there are lots of different possible values for x and y. This situation is not automatically detected by UIKit, due to performance considerations and details of the algorithm used for layout. The symptom of ambiguity is that views sometimes jump from place to place, or possibly are just in the wrong place. -hasAmbiguousLayout runs a check for whether there is another center and bounds the receiver could have that could also satisfy the constraints. -exerciseAmbiguousLayout does more. It randomly changes the view layout to a different valid layout. Making the UI jump back and forth can be helpful for figuring out where you're missing a constraint. */ #if UIKIT_DEFINE_AS_PROPERTIES @property(nonatomic, readonly) BOOL hasAmbiguousLayout NS_AVAILABLE_IOS(6_0); #else - (BOOL)hasAmbiguousLayout NS_AVAILABLE_IOS(6_0); #endif @end   υΩϡϝϯτ͸ϔομΛஸೡʹࢀর͍ͯ͠Δ *GUIFSFBSFOUFOPVHIDPOTUSBJOUTJOUIFTZTUFNUP VOJRVFMZEFUFSNJOFMBZPVU UIFMBZPVUJTDPOTJEFSFE BNCJHVPVT'PSFYBNQMF JGUIFPOMZDPOTUSBJOUJOUIF TZTUFNJTx = y + 100 UIFMBZPVUJTBNCJHVPVTCFDBVTF UIFSFBSFNBOZQPTTJCMFWBMVFTGPSxBOEy6*,JUEPFTOPU BVUPNBUJDBMMZEFUFDUFWFSZBNCJHVPVTMBZPVU TPZPVNBZ OFFEUPMPPLGPSTZNQUPNTPGBNCJHVJUZ TVDIBTWJFXT UIBUKVNQGSPNQMBDFUPQMBDF PSUIBUBSFJOUIFXSPOH QMBDF
  3. @property(nonatomic) BOOL clipsToBounds; // When YES, content and subviews are

    clipped to the bounds of the view. Default is NO. @property(nullable, nonatomic,copy) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is nil. Can be useful with the appearance proxy on custom UIView subclasses. @property(nonatomic) CGFloat alpha; // animatable. default is 1.0 @property(nonatomic,getter=isOpaque) BOOL opaque; // default is YES. opaque views must fill their entire bounds or the results are undefined. the active CGContext in drawRect: will not have been cleared and may have non-zeroed pixels @property(nonatomic) BOOL clearsContextBeforeDrawing; // default is YES. ignored for opaque views. for non-opaque views causes the active CGContext in drawRect: to be pre-filled with transparent pixels @property(nonatomic,getter=isHidden) BOOL hidden; // default is NO. doesn't check superviews @property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill   EFGBVMU஋͸΄΅࣮֬ʹॻ͔Ε͍ͯΔ
  4. typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) { UIViewAnimationOptionLayoutSubviews = 1 << 0, UIViewAnimationOptionAllowUserInteraction

    = 1 << 1, // turn on user interaction while animating UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial value UIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitely UIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forth UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only) UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // do not inherit any options or animation type UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default UIViewAnimationOptionCurveEaseIn = 1 << 16, UIViewAnimationOptionCurveEaseOut = 2 << 16, UIViewAnimationOptionCurveLinear = 3 << 16, UIViewAnimationOptionTransitionNone = 0 << 20, // default UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20, UIViewAnimationOptionTransitionFlipFromRight = 2 << 20, UIViewAnimationOptionTransitionCurlUp = 3 << 20, UIViewAnimationOptionTransitionCurlDown = 4 << 20, UIViewAnimationOptionTransitionCrossDissolve = 5 << 20, UIViewAnimationOptionTransitionFlipFromTop = 6 << 20, UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20, UIViewAnimationOptionPreferredFramesPerSecondDefault = 0 << 24, UIViewAnimationOptionPreferredFramesPerSecond60 = 3 << 24, UIViewAnimationOptionPreferredFramesPerSecond30 = 7 << 24,  
  5. typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) { UIViewAnimationOptionLayoutSubviews = 1 << 0, UIViewAnimationOptionAllowUserInteraction

    = 1 << 1, // turn on user interaction while animating UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial value UIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitely UIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forth UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only) UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // do not inherit any options or animation type UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default UIViewAnimationOptionCurveEaseIn = 1 << 16, UIViewAnimationOptionCurveEaseOut = 2 << 16, UIViewAnimationOptionCurveLinear = 3 << 16, UIViewAnimationOptionTransitionNone = 0 << 20, // default UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20, UIViewAnimationOptionTransitionFlipFromRight = 2 << 20, UIViewAnimationOptionTransitionCurlUp = 3 << 20, UIViewAnimationOptionTransitionCurlDown = 4 << 20, UIViewAnimationOptionTransitionCrossDissolve = 5 << 20, UIViewAnimationOptionTransitionFlipFromTop = 6 << 20, UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20, UIViewAnimationOptionPreferredFramesPerSecondDefault = 0 << 24, UIViewAnimationOptionPreferredFramesPerSecond60 = 3 << 24, UIViewAnimationOptionPreferredFramesPerSecond30 = 7 << 24, } NS_ENUM_AVAILABLE_IOS(4_0);   ϖʔδ͕ભҠ͠ͳ͍෼ಡΈ΍͍͢
  6. typedef NS_ENUM(NSInteger, UIViewAnimationCurve) { UIViewAnimationCurveEaseInOut, // slow at beginning and

    end UIViewAnimationCurveEaseIn, // slow at beginning UIViewAnimationCurveEaseOut, // slow at end UIViewAnimationCurveLinear, }; typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped. UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay) UIViewContentModeCenter, // contents remain same size. positioned adjusted. UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft, UIViewContentModeRight, UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight, };   ͨͩ͠໢ཏతͰ͸ͳ͍
  7. For example: - (void)layoutSubviews { UIView *snapshot = [self snapshotViewAfterScreenUpdates:YES];

    self.alpha = 0.0; }   ίϝϯτͷํ͕දݱ͕ϥϑ㲈Θ͔Γ΍͍͢ To fix this chicken and egg problem These methods may not exist in the future - no promises.
  8. @property (nonatomic) UISemanticContentAttribute semanticContentAttribute NS_AVAILABLE_IOS(9_0); // This method returns the

    layout direction implied by the provided semantic content attribute relative to the application-wide layout direction (as returned by UIApplication.sharedApplication.userInterfaceLayoutDirection). + (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute: (UISemanticContentAttribute)attribute NS_AVAILABLE_IOS(9_0); // This method returns the layout direction implied by the provided semantic content attribute relative to the provided layout direction. For example, when provided a layout direction of RightToLeft and a semantic content attribute of Playback, this method returns LeftToRight. Layout and drawing code can use this method to determine how to arrange elements, but might find it easier to query the container view’s effectiveUserInterfaceLayoutDirection property instead. + (UIUserInterfaceLayoutDirection)userInterfaceLayoutDirectionForSemanticContentAttribute: (UISemanticContentAttribute)semanticContentAttribute relativeToLayoutDirection: (UIUserInterfaceLayoutDirection)layoutDirection NS_AVAILABLE_IOS(10_0); // Returns the user interface layout direction appropriate for arranging the immediate content of this view. Always consult the effectiveUserInterfaceLayoutDirection of the view whose immediate content is being arranged or drawn. Do not assume that the value propagates through the view’s subtree. @property (readonly, nonatomic) UIUserInterfaceLayoutDirection effectiveUserInterfaceLayoutDirection NS_AVAILABLE_IOS(10_0);   ଞΛࢀর͢Ε͹Θ͔Δ෭࣍తͳ৘ใ
  9. // Compatibility and Adoption @interface UIView (UIConstraintBasedCompatibility) /* By default,

    the autoresizing mask on a view gives rise to constraints that fully determine the view's position. This allows the auto layout system to track the frames of views whose layout is controlled manually (through -setFrame:, for example). When you elect to position the view using auto layout by adding your own constraints, you must set this property to NO. IB will do this for you. */ @property(nonatomic) BOOL translatesAutoresizingMaskIntoConstraints NS_AVAILABLE_IOS(6_0); // Default YES /* constraint-based layout engages lazily when someone tries to use it (e.g., adds a constraint to a view). If you do all of your constraint set up in -updateConstraints, you might never even receive updateConstraints if no one makes a constraint. To fix this chicken and egg problem, override this method to return YES if your view needs the window to use constraint-based layout. */ #if UIKIT_DEFINE_AS_PROPERTIES @property(class, nonatomic, readonly) BOOL requiresConstraintBasedLayout NS_AVAILABLE_IOS(6_0); #else + (BOOL)requiresConstraintBasedLayout NS_AVAILABLE_IOS(6_0); #endif   ୺తͳ8):
  10. @interface UIView (UIViewGestureRecognizers) @property(nullable, nonatomic,copy) NSArray<__kindof UIGestureRecognizer *> *gestureRecognizers NS_AVAILABLE_IOS(3_2);

    - (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2); - (void)removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2); // called when the recognizer attempts to transition out of UIGestureRecognizerStatePossible if a touch hit-tested to this view will be cancelled as a result of gesture recognition // returns YES by default. return NO to cause the gesture recognizer to transition to UIGestureRecognizerStateFailed // subclasses may override to prevent recognition of particular gestures. for example, UISlider prevents swipes parallel to the slider that start in the thumb - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_AVAILABLE_IOS(6_0); @end   ۩ମྫ
  11. /* Override this method to tell the layout system that

    there is something it doesn't natively understand in this view, and this is how large it intrinsically is. A typical example would be a single line text field. The layout system does not understand text - it must just be told that there's something in the view, and that that something will take a certain amount of space if not clipped. In response, UIKit will set up constraints that specify (1) that the opaque content should not be compressed or clipped, (2) that the view prefers to hug tightly to its content. A user of a view may need to specify the priority of these constraints. For example, by default, a push button -strongly wants to hug its content in the vertical direction (buttons really ought to be their natural height) -weakly hugs its content horizontally (extra side padding between the title and the edge of the bezel is acceptable) -strongly resists compressing or clipping content in both directions. However, you might have a case where you'd prefer to show all the available buttons with truncated text rather than losing some of the buttons. The truncation might only happen in portrait orientation but not in landscape, for example. In that case you'd want to setContentCompressionResistancePriority:forAxis: to (say) UILayoutPriorityDefaultLow for the horizontal axis. The default 'strong' and 'weak' priorities referred to above are UILayoutPriorityDefaultHigh and UILayoutPriorityDefaultLow. Note that not all views have an intrinsicContentSize. UIView's default implementation is to return (UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric). The _intrinsic_ content size is concerned only with data that is in the view itself, not in other views. Remember that you can also set constant width or height constraints on any view, and you don't need to override instrinsicContentSize if these dimensions won't be changing with changing view content. */ UIKIT_EXTERN const CGFloat UIViewNoIntrinsicMetric NS_AVAILABLE_IOS(6_0); // -1 #if UIKIT_DEFINE_AS_PROPERTIES @property(nonatomic, readonly) CGSize intrinsicContentSize NS_AVAILABLE_IOS(6_0); #else - (CGSize)intrinsicContentSize NS_AVAILABLE_IOS(6_0); #endif - (void)invalidateIntrinsicContentSize NS_AVAILABLE_IOS(6_0); // call this when something changes that affects the intrinsicContentSize. Otherwise UIKit won't notice that it changed. - (UILayoutPriority)contentHuggingPriorityForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0); - (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0); - (UILayoutPriority)contentCompressionResistancePriorityForAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0); - (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0); @end   IVHHJOH DPNQSFTTJPOͷઆ໌
  12. // Size To Fit UIKIT_EXTERN const CGSize UILayoutFittingCompressedSize NS_AVAILABLE_IOS(6_0); UIKIT_EXTERN

    const CGSize UILayoutFittingExpandedSize NS_AVAILABLE_IOS(6_0); @interface UIView (UIConstraintBasedLayoutFittingSize) /* The size fitting most closely to targetSize in which the receiver's subtree can be laid out while optimally satisfying the constraints. If you want the smallest possible size, pass UILayoutFittingCompressedSize; for the largest possible size, pass UILayoutFittingExpandedSize. Also see the comment for UILayoutPriorityFittingSizeLevel. */ - (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize NS_AVAILABLE_IOS(6_0); // Equivalent to sending - systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority: with UILayoutPriorityFittingSizeLevel for both priorities. - (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority: (UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority NS_AVAILABLE_IOS(8_0); @end   ଞͷίϝϯτ΁ͷ༠ಋ
  13. // // UIView Constraint-based Layout Support // typedef NS_ENUM(NSInteger, UILayoutConstraintAxis)

    { UILayoutConstraintAxisHorizontal = 0, UILayoutConstraintAxisVertical = 1 }; // Installing Constraints /* A constraint is typically installed on the closest common ancestor of the views involved in the constraint. It is required that a constraint be installed on _a_ common ancestor of every view involved. The numbers in a constraint are interpreted in the coordinate system of the view it is installed on. A view is considered to be an ancestor of itself. */ @interface UIView (UIConstraintBasedLayoutInstallingConstraints) @property(nonatomic,readonly) NSArray<__kindof NSLayoutConstraint *> *constraints NS_AVAILABLE_IOS(6_0); - (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead, set NSLayoutConstraint's active property to YES. - (void)addConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead use +[NSLayoutConstraint activateConstraints:]. - (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead set NSLayoutConstraint's active property to NO. - (void)removeConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead use +[NSLayoutConstraint deactivateConstraints:]. @end   কདྷతͳEFQSFDBUFEΛڭ͑ͯ͘ΕΔ
  14. @interface UIView(UIViewGeometry) // animatable. do not use frame if view

    is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead. @property(nonatomic) CGRect frame; // use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part @property(nonatomic) CGRect bounds; // default bounds is zero origin, frame size. animatable @property(nonatomic) CGPoint center; // center is center of frame. animatable @property(nonatomic) CGAffineTransform transform; // default is CGAffineTransformIdentity. animatable @property(nonatomic) CGFloat contentScaleFactor NS_AVAILABLE_IOS(4_0);   ૝૾Ͱ͖Δࡉ͔͍࢓༷
  15. @interface UIView (UIStateRestoration) @property (nullable, nonatomic, copy) NSString *restorationIdentifier NS_AVAILABLE_IOS(6_0);

    - (void) encodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0); - (void) decodeRestorableStateWithCoder:(NSCoder *)coder NS_AVAILABLE_IOS(6_0); @end @interface UIView (UISnapshotting) /* * When requesting a snapshot, 'afterUpdates' defines whether the snapshot is representative of what's currently on screen or if you wish to include any recent changes before taking the snapshot. If called during layout from a committing transaction, snapshots occurring after the screen updates will include all changes made, regardless of when the snapshot is taken and the changes are made. For example: - (void)layoutSubviews { UIView *snapshot = [self snapshotViewAfterScreenUpdates:YES]; self.alpha = 0.0; } The snapshot will appear to be empty since the change in alpha will be captured by the snapshot. If you need to animate the view during layout, animate the snapshot instead. * Creating snapshots from existing snapshots (as a method to duplicate, crop or create a resizable variant) is supported. In cases where many snapshots are needed, creating a snapshot from a common superview and making subsequent snapshots from it can be more performant. Please keep in mind that if 'afterUpdates' is YES, the original snapshot is committed and any changes made to it, not the view originally snapshotted, will be included. */ - (nullable UIView *)snapshotViewAfterScreenUpdates:(BOOL)afterUpdates NS_AVAILABLE_IOS(7_0); - (nullable UIView *)resizableSnapshotViewFromRect:(CGRect)rect afterScreenUpdates:(BOOL)afterUpdates withCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(7_0); // Resizable snapshots will default to stretching the center // Use this method to render a snapshot of the view hierarchy into the current context. Returns NO if the snapshot is missing image data, YES if the snapshot is complete. Calling this method from layoutSubviews while the current transaction is committing will capture what is currently displayed regardless if afterUpdates is YES.   ࠷దԽͷ࿩
  16. // Separation of Concerns @interface UIView (UIConstraintBasedLayoutLayering) /* Constraints do

    not actually relate the frames of the views, rather they relate the "alignment rects" of views. This is the same as the frame unless overridden by a subclass of UIView. Alignment rects are the same as the "layout rects" shown in Interface Builder 3. Typically the alignment rect of a view is what the end user would think of as the bounding rect around a control, omitting ornamentation like shadows and engraving lines. The edges of the alignment rect are what is interesting to align, not the shadows and such. */ /* These two methods should be inverses of each other. UIKit will call both as part of layout computation. They may be overridden to provide arbitrary transforms between frame and alignment rect, though the two methods must be inverses of each other. However, the default implementation uses -alignmentRectInsets, so just override that if it's applicable. It's easier to get right. A view that displayed an image with some ornament would typically override these, because the ornamental part of an image would scale up with the size of the frame. Set the NSUserDefault UIViewShowAlignmentRects to YES to see alignment rects drawn. */ - (CGRect)alignmentRectForFrame:(CGRect)frame NS_AVAILABLE_IOS(6_0); - (CGRect)frameForAlignmentRect:(CGRect)alignmentRect NS_AVAILABLE_IOS(6_0); /* override this if the alignment rect is obtained from the frame by insetting each edge by a fixed amount. This is only called by alignmentRectForFrame: and frameForAlignmentRect:. */ #if UIKIT_DEFINE_AS_PROPERTIES @property(nonatomic, readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0); #else - (UIEdgeInsets)alignmentRectInsets NS_AVAILABLE_IOS(6_0); #endif   ݱࡏͷ*OUFSGBDF#VJMEFS͸WFS
  17. // Set the NSUserDefault UIViewShowAlignmentRects to YES to see alignment

    rects drawn.   ίʔυͰ΋BMJNFOU3FDUͷσόοάΛ0/ʹͰ͖Δ
  18. w ׆༻Ͱ͖ͦ͏ w EFGBVMU஋͕஌Γ͍ͨ w ΨΠυϥΠϯͱυΩϡϝϯτͷதؒతଘࡏͱͯ͠ྑͦ͞͏ʁʂ w ஌͍ͬͯΔ஌ࣝΛิڧ͍ͨ͠ w ର৅ΛҰཡ͍ͨ͠ɾγϡοͱಡΈ͍ͨ

    w ෆՄղʹͭ·͍ͮͨ࣌ w Ջͳ࣌ w ޲͔ͳͦ͞͞͏ w લఏ஌͕ࣝͳ͍தɻཧղ͢ΔͨΊʹಡΉˠυΩϡϝϯτɺΨΠυϥΠϯͷํ͕खް͍   ͜͏͍͏࣌ʹಡΉ