"We all love Paul Hegarty." Stanford IOS8 public class personal note view

Source: Internet
Author: User

A view is a subclass of UIView in iOS that identifies a rectangular area on the screen, defines a coordinate system space to draw, and handles the manipulation of the touch.


View is hierarchical, a view can have only one superview, but there can be multiple subview. You can get a view, of course, the return value is optional, or get a view of all the Subview, the return value is an array, although the elements in this array is actually anyobject, because some historical reasons, but it does not matter what the contents of the content hundred is UIView, You're not going to get anything else.

There's another thing called UIWindow, which is a subclass of UIView, but you don't have to worry about it in iOS development, there's a uiwindow on every device screen, it's at the top, but you don't send any messages to him, you don't interact with it, You just have to care about UIView.


The hierarchy of views usually does not require the use of code, and you can drag and drop the stack directly from the storyboard. You can also create through code, there are two ways to do it, one is Addsubview, the other is Removefromsuperview. Addsubview sends a message to the expected Superview, and Removefromsuperview sends the message to the Superview you need to remove.

So where is the vertex of the view hierarchy or where is the root, due to some historical problems, one of the attributes in Viewcontroller is named View, which is the highest level of view in your storyboard scene.


Let's take a look at how to initialize a view. The usual advice is to try not to do an initialization. UIView has two constructors, which represent two different construction methods. If you write init (frame:cgrect), the parameter frame represents the frame in the parent view, which is a coordinate system that represents the view being placed in this coordinate system. The other is initialized using coder, and if you use storyboard to create a view, the view is implemented using init (Coder:nscoder).

If you want to do your own initialization, the recommended approach is to implement both initialization methods, the first is a designed initialization method, once you rewrite it you can no longer inherit the other designed initialization method. There is also an initialization method for required. Then write the action you want to do in a method called in the constructor. This approach is only used when you have to write a constructor yourself. Another way to initialize it is to awakefromnib as follows:


Use this method if you need to manipulate something before the view is displayed, but only the view in storyboard will call this method. The next step is to explain how to draw and capture user gestures in the view.


"We all love Paul Hegarty." Stanford IOS8 public class personal note view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.