IOS UI Basics 05

Source: Internet
Author: User

  • Uiscrollview
    • Uiscrollview Steps to use
      • 1. Create Uiscrollview
      • 2. Add the content you want to show to the Uiscrollview
      • 3. Set the scroll range of the Uiscrollview (contentsize)
    • Note: If you want Uiscrollview to scroll, you must set a range that you can scroll
    • ScrollView can not scroll in several cases
      • 1. Contentsize not set
      • 2.scrollEnabled property = NO
      • 3.userInteractionEnabled property = NO
    • The difference between enabled and userinteractionenabled
      • Enabled: Represents a control that is not available
      • Userinteractionenabled: Represents a control that cannot interact with the user, that is, does not respond to user actions
    • Common Properties
      • Go to scroll bar
        • The scrollbar is also part of the ScrollView child control//scroll bar may be in front of the child control, or it may be behind the child control//Just because of this primitive, so it is not recommended in development to manipulate child controls in the way that subviews gets child controls
          self.scrollView.showsHorizontalScrollIndicator = NO;self.scrollView.showsVerticalScrollIndicator = NO;
      • Set the style of the scroll bar
        self.scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
      • The default Uiscrollview has a rebound effect as long as the contentsize is set to rebound effect
        self.scrollView.bounces = YES/NO;
      • Even if not set contentsize can also have rebound effect
        self.scrollView.alwaysBounceVertical = YES;self.scrollView.alwaysBounceHorizontal = YES;
      • Set Margin Contentinset
        self.scrollView.contentInset = UIEdgeInsetsMake(10, 20, 30, 40);
      • Set content bias shift (Contentoffset)
        • It's actually setting the ScrollView to where to scroll.
        • Tell ScrollView how much to move in the x direction and how much to move in the y direction
        • If X is positive: The picture moves to the left
        • If X is negative: The picture moves to the right
        • The same y is positive: the picture moves upwards
        • Y is negative: the picture moves down
        • Calculation formula: Always in the upper-left corner of the control – the upper-left corner of the content
      • Proxy method
        • As long as the agent of Uiscrollview, abide by the agent protocol, implement the method in the Protocol
        • The system automatically calls these proxy methods when Uiscrollview changes.
        • As soon as the Uiscrollview scrolls, the system will automatically call
          • -(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView
        • As long as the user is ready to start dragging, it calls
          - -(void)scrollViewWillBeginDragging:(nonnull UIScrollView *)scrollView
        • User has finished dragging, on behalf of the user has let go of the system called the method does not mean that the Uiscrollview has stopped scrolling
          - -(void)scrollViewDidEndDragging:(nonnull UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
        • The only way to do this is to represent that Uiscrollview has stopped scrolling.
          - -(void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
          + NOTE: If you want to do something after the Uiscrollview stops scrolling, there are two things
          • 1. No inertia: Only the method of stopping dragging is called, and the method of stopping deceleration is not called.
          • 2. Inertia situation: Both the method of stopping dragging is called, and the method of stopping deceleration is called.
          • So: To determine whether Uiscrollview stops scrolling, you need to rewrite two methods at a time
             + scrollViewDidEndDragging + scrollViewDidEndDecelerating
  • Scaling
    • 1. Become an agent and tell Uiscrollview which child control to scale by proxy method
      • In this method, tell Uisrollview which control to scale
        UIView *)viewForZoomingInScrollView:(nonnull UIScrollView *)scrollView
    • 2. To scale, in addition to telling Uisrollview which control to scale, tell Uisrollview how small the minimum can be, how large the maximum can be self.sc.maximumzoomscale = 2.0; Maximum 2.0self.sc .minimumzoomscale = 0.5; min 0.5
      • 3. In the process of scaling calls and scrollviewdidscroll, as long as scaling a little bit will call
         -(void)
         Scrollviewdidzoom: (nonnull uiscrollview *) scrollView    
      1. Called when the zoom ends
        -(void)scrollViewDidEndZooming:(nonnull UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale
  • Uipagecontrol

       @property (nonatomic) nsinteger numberofpages; Set maximum pages //default is 0  @property ( nonatomic) nsinteger currentpage; Set page number // Set a custom picture [self.pagecontrol by KVC Assigning a value to Uipagecontrol's private property Setvalue:[uiimage imagenamed:@ "current"] ForKeyPath:@ "_currentpageimage"]; [self.pagecontrol setvalue:[ UIImage imagenamed:@ "other"] forkeypath:@ "_pageimage"];    
  • Nstimer

    Note: Nstimer should be weakWhy Nstimer should be weak, because whenever a Nstimer object is created, the object is referenced by the main line Chengqiang@property (Weaknonatomic) Nstimer *timer;Scheduledtimerwithtimeinterval: Creates a timer and is immediately timedTimeInterval: Interval Time//target: Call Who's method //Selector: What method to call// UserInfo: What parameters to pass //repeats: whether to repeat //every 2 seconds to invoke the self NEXTPAG E method, and does not pass any arguments [Nstimer scheduledtimerwithtimeinterval:2.0 target: Selfselector:@selector (NextPage) UserInfo:nil repeats:YES]; //The main thread handles other events in a little bit of time to handle nstimer [[Nsrunloop Mainrunloop] AddTimer:self. Timer Formode: Nsrunloopcommonmodes];} //As long as the Invalidate method is called, the system will remove Nstimer from the main thread and destroy the Nstimer object [self. Timer invalidate];    

IOS UI Basics 05

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.