IOS UIView very useful methods and properties

Source: Internet
Author: User
Tags uikit

Quartz calls in the call view can be correctly depicted in the view.

View object throughbounds, and the Center property declaration to track their size and location. The Frame property contains a rectangle, the bounding rectangle, that specifies the position and size of the view relative to its parent view coordinate system. The Bounds property also contains a rectangle, the bounding rectangle, that defines the position and size of the view relative to the local coordinate system. Although the origin of the bounding rectangle is usually set to (0, 0), this is not required. The Center property contains the central point of the bounding rectangle. When you pass in the codeinitWithFrame: When a method creates a View object, its Frame property is set. The method also initializes the origin of the bounds rectangle to (0.0, 0.0), and the size is the same as the border of the view. The Center property is then set to the central point of the border. By default, the border of a view is not cropped by the parent view's border. If you want a view to crop its child views, you need tothe Clipstobounds property is set to Yes. For example,The UIView class contains a transform property declaration that allows you to apply various types of panning, scaling, and zooming to the entire view. By default, the value of this property is an identity transform and does not alter the appearance of the view. Before adding the transformation, we first get the cgaffinetransform structure stored in the attribute , transform it with the corresponding core Graphics function, and then reassign the modified transform structure to the Transform property of the view. of the ViewThe Contentmode property determines the effect that boundary changes and scaling operations have on the view. By default, the value of this property is set toUiviewcontentmodescaletofill, meaning that the view content is always scaled to fit the new border size. of differentUiviewcontentmode Constants (such as uiviewcontentmodetop and uiviewcontentmodebottomright) allows the current content to appear in different corners of the view or along different boundaries of the view, as well as a pattern to display the content in the center of the view. When you want to implement a resizable control in your application, be sure to consider using theUiviewcontentmoderedraw ModeIf the view'sThe autoresizessubviews Property declaration is set to Yes, its child views are based on thethe values of the Autoresizingmask property are automatically resized. Otherwise, the application must provide its own implementation by overloading the Layoutsubviews method. If you want to keep the relative position of the lower-left corner of a view and its parent view intact, you can joinUiviewautoresizingflexibletopmargin constant and assigns the result to the Autoresizingmask property. When multiple parts of the same axis are set to variable, the margin for sizing is evenly distributed across the sections. Uiviewautoresizingnone If this constant is set, the view will not be automatically resized. UiviewautoresizingflexiblewidthIf this constant is set, the width of the view will change proportionally with the width of the parent view. Otherwise, the width of the view remains the same.UiviewautoresizingflexiblerightmarginIf this constant is set, the right edge of the view adjusts proportionally as the width of the parent view changes. Otherwise, the relative position of the right edge of the view and its parent view remains the same.UiviewautoresizingflexibletopmarginIf this constant is set, the top bounds of the view will adjust proportionally as the parent view height changes. Otherwise, the relative position of the top boundary of the view and its parent view remains unchanged.

If you passInterface Builder Configuration view, you can use the autosizing control of the size viewer to set the automatic resizing behavior for each view. The flexible width and height constants in the interface Builder have the same behavior as the springs in the same position, but the behavior of the blank constants is exactly the opposite. In other words, if you want to apply the flexible right blank automatic resizing behavior to a view of interface Builder, you must control the autosizing of the corresponding direction space to NULL instead of placing a pillar. If the view'sif the Autoresizessubviews property is set to Uiviewautoresizingnone, the dimensions of the child view will not be resized, and the dimensions of its immediate child view will not be adjusted. The parent-child relationship in the view hierarchy helps us define the chain of objects in the application that handles the touch event. When creating a new View object, you need to allocate memory for it and send aan instance of the UIView class is used as a container for other views, you can use the following code:CGRect viewrect = CGRectMake (0, 0,.);uiview* MyView = [[UIView alloc]Initwithframe:viewrect]; In the iphone program, there are two places that are most commonly used to create views and sub-views, which are the object of the application delegateLoadview method. Called by the parent view.Insertsubview: ... method to insert a view in the middle of the child View list of the parent view. Called by the parent view.sendsubviewtoback:, orThe Removefromsuperview method can remove a child view from the parent view. Create a window with a view-(void)UIScreen mainscreen] bounds]; Window.backgroundcolor = [Uicolor whitecolor];Create a simple red squarecgrect redframe = CGRectMake (10, 10, 100, 100); UIView *redview = [[UIView alloc] Initwithframe:redframe];redview.backgroundcolor = [Uicolor redcolor];//Create a simple Blue Squarecgrect blueframe = CGRectMake (10, 150, 100, 100); UIView *blueview = [[UIView alloc] Initwithframe:blueframe];blueview.backgroundcolor = [Uicolor bluecolor];//Add the Squ is views to the Window[window Addsubview:redview]; [Window addsubview:blueview];//Once added to the window, release the ' views ' to avoid the//extra retain count on each of T Hem. [Redview release]; [Blueview release];//Show the window. [Window makekeyandvisible];}   When you add a child view for a view, UIKit sends several messages to the corresponding parent-child view to inform them of the current state change. In your own custom view, you canWillmovetowindow:, didaddsubview:, Didmovetosuperview, and Didmovetowindow methods are overloaded, To make the necessary processing before and after the event occurs, and to update the status information of the view based on the changes that occurred. After the view hierarchy is established, you can use the view'sSuperview property to get its parent view, or by Isdescendantofview: method to determine whether a view is in the view layer of its parent view. The root view of a view hierarchy has no parent view, so its Superview property is set to nil.  For a view that is currently displayed on the screen, the Window object is usually the root view of the entire view hierarchy. The UIView class defines the following methods for coordinate transformation between different view local coordinate systems: ConvertPoint:fromView:convertRect:fromView:convertPoint:toView: The ConvertRect:toView:UIWindow version uses the window coordinate system. The ConvertPoint:fromWindow:convertRect:fromWindow:convertPoint:toWindow:convertRect:toWindow:UIView class contains aThe Tag property. With this property, you can identify a view object by an integer value. You can use this property to uniquely identify the view in the view hierarchy and to retrieve the view at run time (the retrieval based on the tag identity is faster than traversing the view hierarchy yourself). The default value for the Tag property is 0. You can retrieve an identified view by UIView's Viewwithtag: Method The animation block is called from the UIViewThe Commitanimations class method as the end. Between these two calls, you can configure the parameters of the animation and change the property values that you want to animate. Once the Commitanimations method is called, UIKit begins the animation, which animates the change of the given property from the current value to the new value. Animation blocks can be nested, but animations that are nested are not executed until the outermost animation block is committed. The bounding rectangle of the frame view, which is in the coordinate system of the parent view. The bounding rectangle of the bounds view, which is in the coordinate system of the view. The center border of the center, in the coordinate system of the parent view. The transformation matrix on the transform view, relative to the center of the view boundary. The alpha value of the Alpha view, which determines the transparency of the view. UseSetanimationdelay: Method to set the interval between the actual occurrence of the animation and the time point returned by the Commitanimations method. UseSetanimationcurve: Method to set the relative speed of the animation process, such as the animation may gradually accelerate during the revelation phase, and gradually slow down at the end stage, or the whole process will remain the same speed. Usesetanimationrepeatautoreverses: Method to specify whether the animation will play back automatically when it reaches the target value. You can use this method together with the Setanimationrepeatcount: method to make each property transition between the initial and target values smoothly for a period of time. You can use the UIViewSetanimationwillstartselector: AndSetanimationdidstopselector: Method to specify the selector method that receives the message. The message processing method is in the following form:-(void) Animationwillstart: (NSString *) Animationid context: (void *) context;-(void) Animationdidstop: (NSString *) Animationid Finished: (NSNumber *) finished context: (void*) context; The Animationid and context parameters and animation blocks of the above two methods are transmitted at the beginning of theAnimationid-The application provides a string that identifies an animation in an animation block. context-is also an application-supplied object that is used to pass additional information to the delegate object. Setanimationdidstopselector: The selector method also has a parameter-that is, a Boolean value. If the animation completes successfully and is not canceled or stopped by another animation, the value is yes. At any time, when the layout of the view changes, UIKit activates the automatic resizing behavior for each view, and then calls the respectiveThe Layoutsubviews method gives you the opportunity to further adjust the geometry dimensions of the child view. Your application calls the view'sSetneedslayout or layoutifneeded method to force the layout. Your application calls the Layer object behind the view.Setneedslayout method to force the layout. You can also useLayoutsubviews method to adjust the custom Calayer that is linked to the view layer as a child layerAs in some cases, changes in the application data model can affect the corresponding user interface. To reflect these changes, you can identify the corresponding view as requiring a refresh (by invoking theSetneedsdisplay or setneedsdisplayinrect: method) You can change the view by changing thehidden property declarations to hide or show viewsInitialize a view's subclass-(ID)initWithFrame:(CGRect) arect {self = [super initwithframe:arect];if (self) {//setup the initial properties ofthe view ...} return self;} In the iphone OS, the code that loads the nib does not passInitwithcoder: Method to proceed. cgcontextref context = uigraphicsgetcurrentcontext (); CGRect myframe = self.bounds;cgcontextsetlinewidth (context, ten);[[Uicolor Redcolor] set];Uirectframe (MyFrame);//To Tinker with, make complex!!! The view that handles touch events typically requires implementing all of the following methods touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:touchesCancelled: Withevent: Activates multi-touch events:the Multipletouchenabled property declaration is set to Yes. You can change the view by changing thethe Userinteractionenabled property value to control whether the view can handle the event. You can also use the UIApplication object'sBeginignoringinteractionevents andEndignoringinteractionevents MethodUIKit will pass UIView'sPointinside:withevent: MethodTo determine whether the touch event occurred on the specified view.

IOS UIView very useful methods and properties

Related Article

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.