Ios ui basics 05 and iosui05

Source: Internet
Author: User

Ios ui basics 05 and iosui05

  • UIScrollView
    • UIScrollView procedure
      • 1. Create UIScrollView
      • 2. Add the content to be displayed to UIScrollView.
      • 3. Set the rolling range (contentSize) of UIScrollView)
    • Note: If you want UIScrollView to be rolled, you must set a range that can be rolled.
    • Several situations where scrollView cannot be rolled
      • 1. The contentSize is not set.
      • 2. scrollEnabled property = NO
      • 3. userInteractionEnabled property = NO
    • Difference between enabled and userInteractionEnabled
      • Enabled: indicates that the control is unavailable.
      • UserInteractionEnabled: controls cannot interact with users, that is, they cannot respond to user operations.
    • Common attributes
      • Go to the scroll bar
        • The scroll bar is also part of the Child control of scrollView. // the scroll bar may be in front of the child control, or it may be behind the child control. // It is because of this original, therefore, we do not recommend that you use subviews to obtain sub-controls in future development.
          self.scrollView.showsHorizontalScrollIndicator = NO;self.scrollView.showsVerticalScrollIndicator = NO;
      • Set the scroll bar style
         self.scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
      • By default, UIScrollView has a rebound effect. You only need to set contentSize to have a rebound effect.
        self.scrollView.bounces = YES/NO;
      • Even if contentSize is not set, it can have a rebound effect.
        self.scrollView.alwaysBounceVertical = YES;self.scrollView.alwaysBounceHorizontal = YES;
      • Set the margin contentInset
        self.scrollView.contentInset = UIEdgeInsetsMake(10, 20, 30, 40);
      • Set the content offset (contentOffset)
        • It is actually set where scrollView is rolled
        • Tell scrollView how much to move in the x direction and how much to move in the y direction
        • If x is positive, move the image to the left.
        • If x is negative, the image is moved to the right.
        • Similarly, y is positive: the image is moved up.
        • Similarly, y is a negative number: The image is moved down.
        • Calculation formula: Always in the upper left corner of the control-the upper left corner of the content
      • Proxy Method
        • As long as you become a proxy for UIScrollView, follow the proxy Protocol to implement the methods in the Protocol
        • When UIScrollView changes, the system automatically calls these proxy methods.
        • As long as UIScrollView is rolled, the system will automatically call
          • -(Void) scrollViewDidScroll :( UIScrollView *) scrollView
        • You can call
          - -(void)scrollViewWillBeginDragging:(nonnull UIScrollView *)scrollView
        • The user has finished dragging. This means that the user has been released and the system has called this method. This does not mean that UIScrollView has stopped scrolling.
          - -(void)scrollViewDidEndDragging:(nonnull UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
        • Only when this method is executed indicates that UIScrollView has stopped scrolling.
          - -(void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
          + Note: You can perform operations after UIScrollView stops rolling.
          • 1. No inertia: only the stop drag method is called, and the Stop slow method is not called.
          • 2. Inertial condition: both the stop drag method and the Stop slow method are called.
          • Therefore, to determine whether UIScrollView stops scrolling in the future, you need to rewrite two methods at the same time.
             + scrollViewDidEndDragging + scrollViewDidEndDecelerating
  • Zoom
    • 1. Become a proxy. Tell UIScrollView which sub-control to zoom in through proxy
      • In this method, tell UISrollView which control to scale
        - -(nullable UIView *)viewForZoomingInScrollView:(nonnull UIScrollView *)scrollView
    • 2. to zoom in and out, in addition to telling UISrollView which control to zoom in, we also need to tell UISrollView how small it can be and how large it can be.
      Self. SC. maximumZoomScale = 2.0; maximum 2.0self. SC .minimumZoomScale = 0.5; minimum 0.5
      • 3. The call is the same as that of scrollViewDidScroll in the scaling process.
        -(void)scrollViewDidZoom:(nonnull UIScrollView *)scrollView
  • UIPageControl

    @ Property (nonatomic) NSInteger numberOfPages; set the maximum number of pages/default is 0 @ property (nonatomic) NSInteger currentPage; set the page number // assign values to the private attribute of UIPageControl through KVC, set custom image [self. pageControl setValue: [UIImage imageNamed: @ "current"] forKeyPath: @ "_ currentPageImage"]; [self. pageControl setValue: [UIImage imageNamed: @ "other"] forKeyPath: @ "_ pageImage"];
  • NSTimer

    // Note: nstmic should be weak // Why Should nstmic be weak, because as long as an NSTimer object is created, this object will be strongly referenced by the main thread @ property (weak, nonatomic) NSTimer * timer; // scheduledTimerWithTimeInterval: method To Call // userInfo: parameter to be passed // repeats: whether the call is repeated // call the nextPage Method of self every 2.0 seconds without passing any parameter [NSTimer scheduledTimerWithTimeInterval: 2.0 target: self selector: @ selector (nextPage) userInfo: nil repeats: YES]; // when the main thread is processing other events, take a moment to process nstammer [[[nsunloop mainRunLoop] addTimer: self. timer forMode: nsunloopcommonmodes];} // as long as the invalidate method is called, the system will remove nstdate from the main thread and destroy the NSTimer object [self. timer invalidate];

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.