A small summary of UIView

Source: Internet
Author: User

Slow the development of iOS, it is always a little progress, the UI Foundation has gone through, today, review what you learned before, make a summary


Enumeration

UIView's animated form

typedef Ns_enum(Nsinteger, Uiviewanimationcurve) {

Uiviewanimationcurveeaseinout, //slow at beginning and end slow at beginning

Uiviewanimationcurveeasein, //slow at beginning

Uiviewanimationcurveeaseout, //slow at end

Uiviewanimationcurvelinear

};

typedef Ns_enum(Nsinteger, Uiviewcontentmode) {

Uiviewcontentmodescaletofill,

Uiviewcontentmodescaleaspectfit, //contents scaled to fit with fixed aspect. Remainder are transparent content proportionally to VI EW

Uiviewcontentmodescaleaspectfill, //contents scaled to fill with fixed aspect. Some portion of the content may be CLI  pped. Content fill view, scale by content, does not change content scale

Uiviewcontentmoderedraw, //Redraw on Bounds change (calls-setneedsdisplay)

Uiviewcontentmodecenter, //contents remain same size. positioned adjusted.

Uiviewcontentmodetop,

Uiviewcontentmodebottom,

Uiviewcontentmodeleft,

Uiviewcontentmoderight,

Uiviewcontentmodetopleft,

Uiviewcontentmodetopright,

Uiviewcontentmodebottomleft,

Uiviewcontentmodebottomright,

};

Note that the above several constants, usually without scale, when the picture size exceeds imageview size, only part of the display in the ImageView. The Uiviewcontentmodescaletofill property causes the picture to deform. Uiviewcontentmodescaleaspectfit will ensure that the picture scale is the same, and that it all appears in ImageView, which means that ImageView will be partially blank. Uiviewcontentmodescaleaspectfill will also be able to show the picture proportions, but it is filled with the entire imageview, may only part of the picture display

@interfaceUIView (uiviewhierarchy) @property (nonatomic,ReadOnly) UIView *Superview, @property (nonatomic,ReadOnly, copy) Nsarray *subviews, @property (nonatomic,ReadOnly) UIWindow *window;- (void) Removefromsuperview;- (void) Insertsubview: (UIView *) View Atindex: (nsinteger) index;- (void) Exchangesubviewatindex: (Nsinteger) index1 Withsubviewatindex: (Nsinteger) index2;- (void) Addsubview: (UIView *) view;- (void) Insertsubview: (UIView *) View Belowsubview: (UIView *) Siblingsubview;- (void) Insertsubview: (UIView *) View Abovesubview: (UIView *) Siblingsubview;- (void) Bringsubviewtofront: (UIView *) view;- (void) Sendsubviewtoback: (UIView *) view;//allows to perform layout before the drawing cycle happens.-layoutifneeded Forces layout Early- (void) Setneedslayout;- (void) layoutifneeded;- (void) Layoutsubviews;//override point. Called by layoutifneeded automatically. As of IOS 6.0, when constraints-based layout is used the base implementation applies the constraints-based layout, Otherwi Se it does nothing.@end

Refresh child Object Layout

-layoutsubviews method: This method, the default does not do anything, need to rewrite the subclass
-setneedslayout method: Marked for the need to re-layout, asynchronous call layoutifneeded refresh the layout, not immediately refreshed, but layoutsubviews must be called
-layoutifneeded method: If there are tags that need to be refreshed, call layoutsubviews immediately to lay out (without a tag, layoutsubviews will not be called)

If you want to refresh immediately, call [view Setneedslayout], set the tag to need layout, and immediately call [view layoutifneeded] to implement the layout

Before the view is first displayed, the tag always "needs to be refreshed" and can be called directly [view layoutifneeded]

@interfaceUIView (uiviewrendering)- (void) DrawRect: (cgrect) rect;- (void) Setneedsdisplay;- (void) Setneedsdisplayinrect: (cgrect) rect; @property (nonatomic) BOOL clipstobounds; //When YES, content and subviews is clipped to the bounds of the view. Default is NO.@property (nonatomic,copy) uicolor *backgroundcolor ui_appearance_selector;//default is nil. Can is useful with the appearance proxy on the 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 be undefined. The active cgcontext in draw Rect:will not has been cleared and may have non-zeroed pixels@end

Redraw

-drawrect: (CGRect) Rect method: Override this method to perform a redraw task
-setneedsdisplay method: Mark as required redraw, call DrawRect asynchronously
-setneedsdisplayinrect: (CGRect) Invalidrect method: Marked to require partial redraw


Layoutsubviews re-layout of subviews


Layoutsubviews method invocation precedes DrawRect

Setneedslayout a tag that needs to be re-laid on the receiver label and is automatically called on the next cycle of the system Runloop layoutsubviews

Layoutifneeded the name of the method, Uikit will determine if the receiver needs layout. According to Apple's official documentation, the Layoutifneeded method should be

Layoutifneeded traversal is not the Superview chain, it should be the Subviews chain

DrawRect is a redraw of receiver that gets the context

Setneeddisplay a marker that needs to be redrawn on the receiver label, automatically redrawn on the next draw cycle, and iphone device refresh rate is 60hz, which is 1/60 seconds after redrawing

UIView's Setneedsdisplay and Setneedslayout methods. The first two methods are executed asynchronously. Setneedsdisplay will call the automatic call DrawRect method, so that you can get uigraphicsgetcurrentcontext, you can draw. Setneedslayout, by default, calls Layoutsubviews to handle some of the data in the child view.

All two methods are executed asynchronously, layoutsubviews convenient data calculation, DrawRect convenient view redraw.

animation*********************

UIView's Animation

@interfaceUIView (uiviewanimation)+ (void) Beginanimations: (NSString *) Animationid Context: (void*) context;//additional Context info passed to would start/did stop selectors. Begin/commit can nested+ (void) Commitanimations;//starts up to animations when the top level animation is commited//no getters. If called outside animation block, these setters has no effect.+ (void) Setanimationdelegate: (ID)Delegate;//default = Nil+ (void) Setanimationwillstartselector: (SEL) selector;//default = NULL.-animationwillstart: (NSString *) Animationid context: (void *) Context+ (void) Setanimationdidstopselector: (SEL) selector;//default = NULL.-animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void *) context + (void) Setanimationduration: (nstimeinterval) duration;//default = 0.2+ (void) Setanimationdelay: (nstimeinterval) delay;//default = 0.0+ (void) Setanimationstartdate: (NSDate *) StartDate;//default = Now ([nsdate Date])+ (void) Setanimationcurve: (Uiviewanimationcurve) curve;//default = Uiviewanimationcurveeaseinout+ (void) Setanimationrepeatcount: (float) RepeatCount;//default = 0.0. may be fractional+ (void) Setanimationrepeatautoreverses: (BOOL) repeatautoreverses;//default = NO. Used if repeat count is Non-zero+ (void) Setanimationbeginsfromcurrentstate: (BOOL) fromcurrentstate;//default = NO. If YES, the current view position are always used for new animations--allowing animations to ' pile up ' on each other. Otherwise, the last end of the state was used for the animation (the default).+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache;//Current Limitation-only one per begin/commit block+ (void) setanimationsenabled: (BOOL) enabled;//ignore any attribute changes while set.+(BOOL) areanimationsenabled;+ (void) Performwithoutanimation: (void(^) (void) ) actionswithoutanimation Ns_available_ios (7_0);@end

Example: (Kinsoku) called in Viewdidload

//UIView Animation- (void) test1{//1.UIView Animation[UIView Beginanimations:nil Context:nil]; //Set the time[UIView setanimationduration:2]; //monitoring the completion of the animation[UIView setanimationdelegate:self];        [UIView setanimationdidstopselector: @selector (stop)]; //Implementing animation CodeSelf.imageView.center = Cgpointmake ( -, -);
Commit animation [UIView commitanimations];}- (void) stop{NSLog (@"%s", __func__); }

UIView the second method of animation: Block

// block animation of 2.UIView -(void) test2{    [UIView animatewithduration:2 animations:^ {        = Cgpointmake ()    } completion:^(BOOL finished) {        NSLog (@ " animation complete ");}    ];    }

UIView transition animations are used:

//transition animations for 3.UIView- (void) test3{[UIView transitionWithView:self.imageView Duration:3Options:uiviewanimationoptiontransitionflipfrombottom animations:^{self.imageView.image= [UIImage imagenamed:@"FC1F4134970A304E9A8F631ED0C8A786C8175CA1"]; } Completion:^(BOOL finished) {NSLog (@"Complete page turn"); }];//page Turn effect: enter from bottom            }

A small summary of UIView

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.