UIView Class Reference의 개요부분을 간단히 번역한 것입니다.
UIViw 클래스는 귀하의 어플리케이션에 그림을 그릴 때 사용되는 기본적인 행위들을 실행합니다. 이 클래스를 그 자체로 단순히 다른 뷰 오브젝트를 담는 단순한 컨테이너처럼 작동하도록 하용할 수 있습니다, 또한 커스토마이즈된 컨텐츠를 그리기 위하여 하위클래스를 만들거나 이 클래스의 메소드를 오버라이드 할 수도 있습니다. 이 클래스는 리스폰터 오브젝트이기도 하기 때문에, 이 클래스에 잇는 컨텐츠와 연관된 상호작용에 대응할 수도 있습니다.
UIView 객체는 서브뷰의 네스팅 된 상하계층구조로서, UIWIndow 오브젝트 내부와 연관되어 있습니다. 뷰 계층구조에서 부모 오프젝트는 superview라고 불리워 지면, 자식 오브젝트는 서브뷰라고 불립니다. 뷰 객체는 superview에서 지정한 영역 내부의 사각형 영역을 필요로 하며, 또한 그 사각형 내에서 일어나는 이벤트를 수신할 권한이 있습니다. 형제(동급의) 뷰들은 아무런 문제 없이 겹쳐질 수 있으며, 복합적인 뷰 배치가 가능합니다.
UIView 클래스는 모든 형식의 뷰를 만들어내고 그들 프로퍼티에 접근할 수 있게 하는 공통적인 방법들을 제공합니다. 예를들어, 서브클래스가 독자적인 지정된 초기화방식을 사용하지 않는 한, 뷰를 새로 만들기 위하여 initWithFrame 을 사용할 수 있습니다: (47페이지) 프레임 (19페이지) 프로퍼티는 superview 좌표 한도이내에서 뷰의 원점과 크기를 지정합니다. 모든 뷰의 좌표 시스템의 원점은 좌상단 꼭지점입니다.
뷰의 위치와 크기를 지정하기 위하여 center (16페이지)와 bounds (16페이지) 프로퍼티를 사용할 수 있습니다. center 프로퍼티는 superview의 한계 내에서 이 뷰의 중심점을 지정합니다. bounds 프로퍼티는 뷰 좌표체계에서 뷰의 원점과 그 크기를 (뷰의 컨텐프는 bounds 사이즈보다 더 클 수도 있습니다) 지정합니다. frame 프로퍼티는 실제로 center와 bounds 프로퍼티 값으로부터 계산되어 집니다. 따라서, 이들 3 가지 프로퍼티를 마음대로 지정할 수 있으며 그들의 값은 서로간의 값에 영향을 주게 됩니다.
화면에 표시될 때 혹은 방향이 변경될 때, 뷰가 superview의 bounds 이내에서 올바르게 표시될 수 있도록, autoresizing 프로퍼티를 지정하는 것이 중요합니다. 특히 UIView의 서브 클래스로 지정했을 경우에는 뷰가 그 뷰의 하위 뷰를 자동적으로 resize할 수 있는지 여부를 지정하기 위하여, suatoresizeSubview 프로퍼티 (14 페이지)을 사용하십시오. 어떻게 뷰가 자동적으로 resize할 지를 지정하기 위하여는 UIViewAutoresizing에 설명되어 있는 상수들을 사용하여 autoresizingMask (59페이지) 프로퍼티를 사용하십시오.
UIVeiw 클래스는 뷰 계층구조를 관리하기 위한 다양한 방법들을 제공합니다. 보모 뷰를 얻기 위해서는 superview 프로퍼티 (23 페이지)를 사용하고 계층구조 상의 자식 뷰를 얻기 위해서는 subview 프로퍼티 (23 페이지) 사용하십시오. 형제 뷰를 상호간에 누구를 앞에 위치할 지 누구를 뒤에 위치할 지를 조정하거나, 서뷰 뷰를 추가하고, 삽입하고, 제거할 수 있도록, "Managing the View Hieracrch" (9 페이지)에 수록된 다양한 방법이 있습니다. 자신(self)에게 그림을 그리는 커스톰 클래스를 새로 만들기 위하여 UIView의 서브 클래스를 만들 경우에는, 지정된 영역 내부에서 뷰를 그리기 위하여 drawRect 메소드 (4 페이지)를 실행하십시오.
이 메소드는 뷰가 처음으로 표시될 때나, 뷰의 프레임의 일부가 무효화되어 컨텐츠를 다시 그릴 필요가 생기는 이벤트가 발생했을 때에 호출됩니다. 정상적인 기하학적인 변경은 뷰를 새로 그릴 필요가 없습니다. 따라서, 뷰의 모습을 변경하고 뷰를 강제로 새로 그리기를 원할 경우에는, 뷰에게 setNeedsDisplay (52페이지) 혹은 setNeedsDisplayInRect (페이지 53)을 전달하십시오. bounds가 변경되었거나 할 때에 drawRect (44페이지)를 호출하기 위해서는 contentMode (18페이지)를 UIViewContentModeRedraw (58 페이지)로 자정해도 됩니다; 그렇지 않으면, 뷰는 컨텐츠를 다시 그리지 않고 크기변경을 하거나 잘려 나가게 됩니다.
서브 클래스들도 역시 다른 뷰를 담는 컨테이너가 될 수 있습니다. 이 경웨, 뷰 계층구조를 새로 만들기 위해서는, 지정된 초기화방법, initWithFrame (47페이지) 을 오버라이드하면 됩니다. 만약에 그리기 전에 서브뷰의 레이아웃을 프로그램적으로 강제로 지정하고자 한다면, 뷰에 setNeedsLayout (53페이지)를 전달하십시오. 그러면 layoutIfNeeded (49페이지)가 호출될 때, 그림을 화면에 표시하기 직전에 layoutSubviews 메소드(50페이지)가 호출됩니다. 서브뷰의 특성을 맞춤형으로 지정하고자 할 때에는 layoutSubviews (50페이지)를 오버라이드 해야 합니다.
어떤 프로퍼티들은 뷰 오브젝트가 애니메이트 될 수 있도록 합니다 - 예를 들어, frame(페이지 19), bounds (16페이지), center (16페이지), 그리고 transform (24페이지) 프로퍼티의 지정 등입니다. 만약 애니메이션 블록에서 이들 프로퍼티를을 변경하면, 현재의 상태에서 새로운 상태로 변경될 때 애니메이션이 활성화 됩니다. 애니메이션 블록을 시작하려면beginAnimations:context: (page 27) class 메소드를 호출하고, 애니메이션화 하고 싶은 프로퍼티를 지정하고, 다음에 애니메이션 블록을 종료하기 위하여 commitAnimations (page 28) class 메소드를 호출하십시오.
애니메이션은 별도의 스레드에서 실행되며 어플리케이션이 실행(run) 루프로 돌려질 때 시작됩니다. 다른 애니메이션 클래스 메소드들은 블록 내에서 시작 시간, 지속 시간, 지연, 그리고 애니메이션의 곡선을 통제할 수 있도록 해 줍니다. 만약 이벤트를 처리 중이고 그 이벤트들이 어디서 일어나는지를 알고 싶을 때에는 itTest:withEvent: (page 46) 와 pointInside:withEvent: (page 50) 메소드를 사용하십시오. UIView 클래스는 UIResponder로부터 다른 이벤트 처리 메소드들을 상속 받습니다. 이벤트를 다루는 더 자세한 정보는, UIResponder Class Reference를 읽으십시오.
제스처 인식기를 사용해서 오브젝트가 뷰에서 만들어진 제스처를 해석할 수 있도록 하기 위해서는, addGestureRecognizer: (page 39) 메소드를 호출하십시오. (제스처 인식기는 UIGessrureRecognizer의 절대 서브클래스의 인스탄스 입니다)removeGestureRecognizer: (page 51) method 를 사용해서 제스처 인식기를 제거할 수 있고, gestureRecognizers (page 20) 프로퍼티를 이용해서 어떤 제스처 인식기가 뷰에 사용되고 있는지를 알 수 있습니다. 제스처 인식기는 iOS 3.2.에 도입된 기능입니다. 이 클래스를 어떻게 사용지에 관해 알려면 Window and Views in iOS Application Programming Guide 를 읽으십시오.
The UIView class implements the basic behavior used to facilitate drawing in your applications. You can use
this class as-is to act as a simple container for other view objects. You can also subclass it and override its
methods to draw custom content. Because it is also a responder object, you can also respond to interactions
with that content.
this class as-is to act as a simple container for other view objects. You can also subclass it and override its
methods to draw custom content. Because it is also a responder object, you can also respond to interactions
with that content.
UIView objects are arranged within an UIWindow object, in a nested hierarchy of subviews. Parent objects in the view hierarchy are called superviews, and children are called subviews. A view object claims a
rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive events occurring in it as well. Sibling views are able to overlap without any issues, allowing complex
view placement.
The UIView class provides common methods you use to create all types of views and access their properties. For example, unless a subclass has its own designated initializer, you use the initWithFrame: (page 47) method to create a view. The frame (page 19) property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.
You can also use the center (page 16) and bounds (page 16) properties to set the position and size of a view. The center property specifies the view’s center point in superview’s coordinates. The bounds property specifies the origin in the view’s coordinates and its size (the view’s content may be larger than the bounds size). The frame property is actually computed based on the center and bounds property values. Therefore, you can set any of these three properties and they affect the values of the others.
It’s important to set the autoresizing properties of views so that when they are displayed or the orientation changes, the views are displayed correctly within the superview’s bounds. Use the autoresizesSubviews (page 14) property, especially if you subclass UIView, to specify whether the view
should automatically resize its subviews. Use the autoresizingMask (page 15) property with the constants described in UIViewAutoresizing (page 59) to specify how a view should automatically resize.
should automatically resize its subviews. Use the autoresizingMask (page 15) property with the constants described in UIViewAutoresizing (page 59) to specify how a view should automatically resize.
The UIView class provides a number of methods for managing the view hierarchy. Use the superview (page 23) property to get the parent view and the subviews (page 23) property to get the child views in the hierarchy. There are also a number of methods, listed in “Managing the View Hierarchy” (page 9), for adding, inserting, and removing subviews as well as arranging subviews in front of or in back of siblings. When you subclass UIView to create a custom class that draws itself, implement the drawRect: (page 44) method to draw the view within the specified region.
This method is invoked the first time a view displays or when an event occurs that invalidates a part of the view’s frame requiring it to redraw its content. Normal geometry changes do not require redrawing the view. Therefore, if you alter the appearance of a view and want to force it to redraw, send setNeedsDisplay (page 52) or setNeedsDisplayInRect: (page 53) to the view. You can also set the contentMode (page 18) to UIViewContentModeRedraw (page 58) to invoke the drawRect: (page 44) method when the bounds change; otherwise, the view is scaled and
clipped without redrawing the content.
clipped without redrawing the content.
Subclasses can also be containers for other views. In this case, just override the designated initializer, initWithFrame: (page 47), to create a view hierarchy. If you want to programmatically force the layout
of subviews before drawing, send setNeedsLayout (page 53) to the view. Then when layoutIfNeeded (page 49) is invoked, the layoutSubviews (page 50) method is invoked just before displaying. Subclasses should override layoutSubviews (page 50) to perform any custom arrangement of
subviews.
Some of the property changes to view objects can be animated—for example, setting the frame (page 19), bounds (page 16), center (page 16), and transform (page 24) properties. If you change these properties
in an animation block, the changes from the current state to the new state are animated. Invoke the beginAnimations:context: (page 27) class method to begin an animation block, set the properties you want animated, and then invoke the commitAnimations (page 28) class method to end an animation block.
The animations are run in a separate thread and begin when the application returns to the run loop. Other animation class methods allow you to control the start time, duration, delay, and curve of the animations within the block. Use the hitTest:withEvent: (page 46) and pointInside:withEvent: (page 50) methods if you are processing events and want to know where they occur. The UIView class inherits other event processing methods from UIResponder. For more information on how views handle events, read UIResponder Class Reference.
To associate a gesture recognizer with a view so that object can interpret gestures made on the view, you must call the addGestureRecognizer: (page 39) method. (Gesture recognizers are instances of a concrete subclass of UIGestureRecognizer.) You remove a gesture recognizer with the
removeGestureRecognizer: (page 51) method and find out which gesture recognizers are associated with a view using the gestureRecognizers (page 20) property. Gesture recognition is a feature that was introduced in iOS 3.2. Read Window and Views in iOS Application Programming Guide to learn how to use this class.
removeGestureRecognizer: (page 51) method and find out which gesture recognizers are associated with a view using the gestureRecognizers (page 20) property. Gesture recognition is a feature that was introduced in iOS 3.2. Read Window and Views in iOS Application Programming Guide to learn how to use this class.
No comments:
Post a Comment