Common methods of UIView

Source: Internet
Author: User

Common methods of UIView
  • Add a view as a child view and make it appear on top
    -(void)addSubView:(UIView *)view;
  • Move the specified child view to top
    -(void)bringSubViewToFront:(UIView *)view;
  • Place the specified view at the bottom
    -(void)sendSubViewToBack:(UIView *)view;
  • Adds the specified view to the index position of the subviews array
    -(void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
  • Adds the specified view below the specified sub-view
    -(void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
  • Adds the specified view above the specified child view
    -(void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
  • Swaps a child view of two locations in an subviews array
    -(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
  • Remove from parent view
    -(void)removeFromSuperview;
  • Gets the corresponding descendant control according to the tag value
    -(UIView *)viewWithTag:(NSInteger)tag;
  • Converts the midpoint of a view from its own coordinate system to the specified view coordinate system
    -(CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
  • Converts a point within the coordinate system in the specified view into its own coordinate system
    -(CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
  • Converts a rectangular area in a view from its own coordinate system to a specified view coordinate system
    -(CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
  • Converts a rectangular region within a coordinate system in a specified view into its own coordinate system
    -(CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
  • Refresh view, call DrawRect after calling automatically: (cgrect) rect
    -(void)setNeedsDisplay;
    • Inherit from Uiresponder methods for responding to touch events
1.- (void) Touchesbegan: (Nsset<Uitouch*> *) touches withevent: (nullableuievent*) event;
2.- (void) Touchesmoved: (Nsset<Uitouch*> *) touches withevent: (nullableuievent*) event;
3.- (void) Touchesended: (Nsset<Uitouch*> *) touches withevent: (nullableuievent*) event;
4.- (void) Touchescancelled: (NullableNsset<Uitouch*> *) touches withevent: (nullableuievent*) event;

The above method requires a custom view rewrite, and if you need to override the method for touch point to judgment (use), first get the touch point in the method body:

1.UITouch *touch = [touches anyObject];
2.CGPoint point = [touch locationInView:self];
    • Animation
1.//First you need to set the animation header to tell the compiler that the animation
2.[UIViewBeginanimations:NilContextNil];
3.//Set the animation to perform the configuration, animation
4.[UIViewSetanimationduration:0.5];
5.[UIViewSetanimationrepeatcount:2];
6.[UIViewSetanimationdelay:3.0];
7.//Balabala animations to be performed
8.................
9.//Last commit animation
.[UIViewCommitanimations];
    • Animating with block
      • Method One
        +(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
      • Method Two
        +(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
      • Method Three
        + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion

Common methods 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.