본문 바로가기
프로그래밍 놀이터/iOS

[ios] UIView 에 대한 이야기

by 돼지왕 왕돼지 2017. 11. 10.
반응형

 [ios] UIView 에 대한 이야기


참조 : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/

# Identifying the View at Runtime, ', @property, addconstraint, addConstraints, addGestureRecognizer, addlayoutguide, addsubview, Aligning Views in Auto Layout, alignmentRectForFrame, alignmentRectInsets, ALPHA, alternative to subclassing, animateWithDuration:animations, animateWithDuration:delay:options:animations:completion, Animating Views with Block Objects, animation, animations, autoresizemask, autoresizessubviews, autoresizingmask, BackgroundColor, block-based animation, bottomanchor, bound, bounds, bringsubviewtofront, calayer, canBecomeFocused, center, center property, centerxanchor, centeryanchor, CGRectMake, clearscontextbeforedrawing, clip, clipstobounds, Cofiguring the resizing Behavior, Configuring a View’s Visual Appearance, Configuring Content margins, Configuring the Bounds and Frame Rectangles, Configuring the Event-Related Behavior, Constraints, constraintsAffectingLayoutForAxis, contentCompressinoResistancePriorityForAxis, contentHuggingPriorityForAxis, contentMode, contentScaleFactor, contentstretch, core animation layer, Creating Constraints Using Layout Anchors, custom content, Debugging Auto Layout, designated initializer, didaddsubview, didmovetosuperview, didmovetowindow, drawing and printing, Drawing and Updating the View, drawing performance up, drawrect, drawrect:forviewprintformatter, drawViewHierarchyInRect:afterScreenUpdates, endediting, Ending a View Editing Session, event handling, exchangeSubviewAtIndex:withSubviewAtIndex, exclusivetouch, exerciseAmbiguityInLayout, firstbaselineanchor, focused, Formatting Printed View Content, FRAME, frame bound, frameForAlignmentRect, geometry, gesture, gesture recognizer, gesture recognizers, gestureRecognizerShouldBegin, hasAmbiguousLayout, heightanchor, Hidden, Hit Testing in a View, hitTest:withEvent, IMAGE, image-based backgrounds, Initialization, initWithCoder, initwithframe, insertsubview:abovesubview, insertsubview:belowsubview, insertsubviewabovesubview, insertsubviewatindex, insertsubviewbelowsubview, Interface builder, intrinsicContentSize, invalidateIntricsicContentSize, isdescendatofview, Label, lastbaselineanchor, Layer, layerclass, laying out, Laying out Subviews, layout, layout change, layoutguides, layoutIfNeeded, layoutMargins, layoutMarginsDidChange, layoutmarginsguide, layoutsubvies, layoutsubviews, leadinganchor, leftanchor, main thread, Managing Gesture Recognizers, Managing the User Interface Direction, Managing the View’s Contraints, maskview, Measuring in Auto Layout, methods to override, multipletouchenabled, needsUpdateConstraints, nib file, opaque, pointInside:withEvent, Position, preservesSuperviewLayoutMargins, read-only, readablecontentguide, REDRAW, removeconstraint, removeconstraints, removefromsuperview, removeGestureRecognizer, removelayoutguide, requiresConstraintBasedLayout, resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets, Resizing, rightanchor, semanticContentAttribute, sendsubviewtoback, setContentCompressionResistancePriority:forAxis, setContentHuggingPriority:forAxis, setNeedsDisplay, setNeedsDisplayInRect, setneedslayout, setNeedsUpdateConstraints, SIBLING, Size, sizethatfits, sizeToFit, snapshotViewAfterScreenUpdates, Subclassing, subview, subviews, superview, System, systemLayoutSizeFittingSize, systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority, TAG, the view drawing cycle, threading considerations, tinitadjustmentmode, tintColor, tintColorDidChange, Top, topanchor, toucesended, touchesbega, touchesCancelled, touchesMoved, trailinganchor, transform, translatesAutoresizingMaskIntoConstraints, UIImageView, UIView, Update, updateConstraints, updateConstraintsIfNeeded, userinteractionEnabled, userInterfaceLayoutDirectionForSemanticContentAttribute, View, view internal dimension, view 만들기, viewForFirstBaselineLayout, viewForLastBaselineLayout, widthanchor, willmovetosuperview, willmovetowindow, willremovesubview, window, withevent, Working with Layout Guides, YES, z-order, [ios] UIView 에 대한 이야기


-

UIView 는 다른 View 를 가질 수 있다.



-

보통 Subview 는 superView 의 bound 에 clip 되지 않지만 clipsToBounds property 를 사용하면 clip 시킬 수 있다.



-

view 의 geometry 는 frame, bounds, 그리고 center property 에 의해 결정된다.

frame 은 superview 기준의 position 과 size 를 결정할 때 사용된다.

center 는 size 변화 없이 position 변경할 때 사용된다.

bounds 는 view 의 internal dimension 을 정의한다.


frame 과 bounds 은 coupled 되어 있어 상호간 영향을 미친다.




# View 만들기


-

UIView* view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];



-

만들어진 view 는 addSubview: 함수를 통해 add 할 수 있다.

addSubview 는 sibling 중 top 으로 위치시키며 add 된다.

z-order 는 insertSubview:aboveSubview: 나 insertSubview:belowSubview: 함수를 통해 조절 가능하다.

exchangeSubviewAtIndex:withSubviewAtIndex: 를 통해 위치 조정도 가능하다.



-

setNeedsLayout 함수는 view 가 layout 을 update 하도록 한다.




# The View Drawing Cycle


-

뷰가 처음 보여지거나, layout change 등으로 안 보여지다가 보여지는 상황이라든지 이런 경우에 system 이 view 에게 그리라고 명령한다.

Custom content 를 가진 경우에는 system 이 drawRect: 함수를 불러준다.



-

뷰 안의 내용물이 실제 변경될 경우 system 에게 redraw 명령을 내리는 것이 필요하다.

setNeedsDisplay 나 setNeedsDisplayInrect: 함수가 그것이다.

위의 메소드들은 다음 drawing cycle 에 redraw 할 것을 예약한다.




# Animations


-

block-based animation 사용하는 것이 추천된다.



-

animateWithDuration:animations: 가 block-based animation 의 대표적인 녀석이다.



-

다음의 것들이 animate 될 수 있다.


@property frame

@property bounds

@property center

@property transform

@property alpha

@property backgroundColor

@property contentStretch




# Threading Considerations


-

Main thread 에서만 operation 해야 한다.




# Methods to Override


-

initialization

     initWithFrame: - 추천되는 메소드

     initWithCoder: - interface builder nib file 로부터 불러오는 경우 사용한다.

     layerClass - 다른 Core Animation layer 를 사용할 때만 사용한다.



-

Drawing and printing

     drawRect: - custom content 를 그릴 경우에 사용한다.

     drawRect:forViewPrintFormatter: - print 할 때 다르게 그릴 필요가 있을 때만 사용한다.



-

Constraints

     requiresConstraintBasedLayout - constraint 가 필요할 때 사용한다.

     updateConstraints - custom constraint 를 subview 간 필요할 때 사용한다.

     alignmentRectForFrame:, frameForAlignmentRect: - 다른 view 에 대해 어떻게 align 되어야 할지 설정할 때 사용한다.



-

Layout

     sizeThatFits: - view 가 default size 와 다른 size 를 갖고자 할 때 구현한다.

     layoutSubviews - subview 의 layout 에 더 autoresize 와 constraint 외의 더 많은 control 이 필요할 때 사용한다. 

     didAddSubview:, willRemoveSubview: - subview 의 add, remove 를 track 할 때 사용한다.

     willMoveToSuperview:, didMoveToSuperview - view hierarchy 에서 이동이 있는 경우를 track 하기 위해 사용한다.

     willMoveToWindow:, didMoveToWindow - 다른 window 로의 이동이 있는 경우를 track 하기 위해 사용한다.



-

Event Handling

     touchesBegan:withEvent:, touchesMoved:withEvnet:, toucesEnded:withEvent:, touchesCancelled:withEvent: - touch event 를 직접적으로 control 하기 위해 사용된다. gestrue 기반 event 들은 gesture recognizer 를 사용하는 것이 추천된다.

     gestureRecognizerShouldBegin: - touch event 를 직접적으로 control 하고, attach 된 다른 recognizer 를 prevent 하기 위해서도 사용된다.




# Alternative to Subclassing


-

실제 subclassing 하지 않고도 문제를 많이 해결할 수 있다.

다음 함수들 호출을 점검해보자.



-

addConstraint:

autoresizingMask

contentMode

contentStretch

hidden

alpha

backgroundColor



-

drawRect:  를 이용해 직접 그리기보다는 image 나 label 등의 view 를 subview 로 구성해서 subclassing 하는 것이 좋다.



-

Gesture recognizers - subclass 를 만들어 touch event 를 intercept 하기보다는 gesture recognizer 를 달아서 control 하는 것이 좋다.



-

Animation - built-in animation 을 사용하는 것이 직접 animation 을 subclass 에서 control 하는 것보다 좋다.



-

Image-based backgrounds - 정적 content 를 보여주는 뷰들은 UIImageView 와 Gesture recognizer 를 사용하는 것이 subclassing 하여 직접 image 를 그리고 event 를 control 하는 것보다 좋다. 혹은 CALayer 의 content 로 삼아서 image 를 세팅해주는 것이 좋다.






# Initializing a View Object


- initWithFrame: // designated initializer




# Configuring a View’s Visual Appearance


backgroundColor

hidden

alpha

opaque // default 는 YES 로 drawing performance up

tintColor

tintAdjustmentMode

clipsToBounds

clearsContextBeforeDrawing

maskView

+layerClass

layer // read-only 로 view 의 Core Animation layer 이다.




# Configuring the Event-Related Behavior

    

userInteractionEnabled

multipleTouchEnabled

exclusiveTouch // YES 로 두면 같은 window 의 다른 view 에 event 를 전달하지 않는다. 기본은 NO




# Configuring the Bounds and Frame Rectangles


frame // superview 기준의 좌표

bounds // view 자체 기준의 좌표

center

transform




# Managing the View Hierarchy


superview

subviews

window

-addSubview:

-bringSubviewToFront:

-sendSubviewToBack:

-removeFromSuperview

-insertSubview:atIndex:

-insertSubview:aboveSubview:

-insertSubview:belowSubview:

-exchangeSubviewAtIndex:withSubviewAtIndex:

-isDescendantOfView:




# Cofiguring the resizing Behavior


autoresizeMask

autoresizesSubviews

contentMode

-sizeThatFits: // view 에게 size 계산을 해서 return 하도록 한다

-sizeToFit // resize & move 시킨다.




# Laying out Subviews


-layoutSubviews

-setNeedsLayout

-layoutIfNeeded

+requiresConstraintBasedLayout

translatesAutoresizingMaskIntoConstraints




# Creating Constraints Using Layout Anchors


bottomAnchor

centerXAnchor

centerYAnchor

firstBaselineAnchor

heightAnchor

lastBaselineAnchor

leadingAnchor

leftAnchor

rightAnchor

topAnchor

trailingAnchor

widthAnchor




# Managing the View’s Contraints


constraints

-addConstraint:

-addConstraints:

-removeConstraint:

-removeConstraints:




# Working with Layout Guides


-addLayoutGuide:

layoutGuides

layoutMarginsGuide

readableContentGuide

-removeLayoutGuide:




# Measuring in Auto Layout


-systemLayoutSizeFittingSize:

-systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:

-intrinsicContentSize

-invalidateIntricsicContentSize

-contentCompressinoResistancePriorityForAxis:

-setContentCompressionResistancePriority:forAxis:

-contentHuggingPriorityForAxis:

-setContentHuggingPriority:forAxis:




# Aligning Views in Auto Layout


-alignmentRectForFrame:

-frameForAlignmentRect:

-alignmentRectInsets

viewForFirstBaselineLayout

viewForLastBaselineLayout




# Triggering Auto Layout


-needsUpdateConstraints

-setNeedsUpdateConstraints

-updateConstraints

-updateConstraintsIfNeeded




# Debugging Auto Layout


-constraintsAffectingLayoutForAxis:

-hasAmbiguousLayout

-exerciseAmbiguityInLayout




# Managing the User Interface Direction


semanticContentAttribute

+userInterfaceLayoutDirectionForSemanticContentAttribute:




# Configuring Content margins


layoutMargins

preservesSuperviewLayoutMargins

-layoutMarginsDidChange






# Drawing and Updating the View


-drawRect:

-setNeedsDisplay

-setNeedsDisplayInRect:

contentScaleFactor

-tintColorDidChange




# Formatting Printed View Content


-viewPrintFormatter

-drawRect:forViewPrintFormatter:




# Managing Gesture Recognizers


-addGestureRecognizer:

-removeGestureRecognizer:

gestureRecognizers

-gesturerecognizerShouldBegin:




# Animating Views with Block Objects


+animateWithDuration:delay:options:animations:completion:

+animateWithDuration:animations:completion:

+animateWithDuration:animations:

+transitionWithView:duration:options:animtations:completion:

+transitionFromView:toView:duration:options:completion:

+animateKeyframesWithDuration:delay:options:animtations:completion:

+addKeyframeWithRelativeStartTime:relativeDuration:animations:

+performSystemAnimation:onViews:options:animations:completion:

+animateWithDuration:delay:usingSprintWithDamping:initialSpringVelocity:options:animtations:completion:

+performWithoutAnimation:




# Animating Views


...




# Using Motion Effects


...




# Preserving and Restoring State


...




# Capturing a View Snapshot


-snapshotViewAfterScreenUpdates:

-resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:

-drawViewHierarchyInRect:afterScreenUpdates:




# Identifying the View at Runtime


tag

-viewWithTag:




# Converting Between View Coordinate Systems


...




# Hit Testing in a View


- hitTest:withEvent:

-pointInside:withEvent:




# Ending a View Editing Session


- endEditing:




# Observing View-Related Changes


-didAddSubview:

-willRemoveSubview:

-willMoveToSuperview:

-didMoveToSuperview

-willMoveToWindow:

-didMoveToWindow




# Observing Focus


-canBecomeFocused

+inheritedAnimationDuration

focused




# Data Types


UIViewAnimtationOptions

UIViewAnimtationCurve

UIViewContentMode

UIViewTintAdjustmentMode

UISystemAnimation

UIViewAutoResizing

UIViewAnimationTransition




# Constants


UIViewKeyframeAnimationOptions

UILayoutConstraintAxis

Fitting Size

UIView Intrinsic Metric Constant

UISemanticContentAttribute





반응형

댓글