iOS Learning Uiscrollview

Source: Internet
Author: User

first, the creation of Uiscrollview and Common Properties1. Uiscrollview Overview
    • Uiscrollview is a subclass of UIView.
    • Uiscrollview as the base class for all scrolling views.
    • Uiscrollview is mainly used in common functions such as rolling headlines (Carousel charts), photo albums, etc.
2, the creation of Uiscrollview
    #define kwidth self.frame.size.width    #define kheight self.frame.size.height    // Create a Uiscrollview        with the same screen size Self.scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (00, Kwidth, Kheight)];     //  Set background color        self.scrollView.backgroundColor = [Uicolor yellowcolor];     // Add to Parent view        [Self addSubview:self.scrollView];
3. Contentsize Scrolling Range
    • Uiscrollview is used to control the scrolling range of important properties contentsize, through this important property setting to control the scrolling of the view, we target to lay 3 screen width of the picture, so we set the scrolling range is 3 screen width
    • Contentsize has two parameters, one is width and the other is height, setting two values with different effects
// Scroll Horizontally 3 0 ); // Scroll in the vertical direction
Self.scrollView.contentSize = Cgsizemake (03);  
4. Properties of Uiscrollview
//after setting the scroll range for the Uiscrollview, then tile 3 pictures in ScrollView with a for loop, noting the location of each ImageView for(Nsinteger i =1; I <4; i++) {Uiimageview*imageview = [[Uiimageview alloc] Initwithframe:cgrectmake ((I-1) * Kwidth,0, Kwidth, Kheight)]; Imageview.image= [UIImage imagenamed:[nsstring stringwithformat:@ "h%d.jpg ", I]]; [ScrollView Addsubview:imageview];} //The offset setting allows the specified view to be displayed (which picture will be displayed first)//directly set the second view to appear on the screenSelf.scrollView.contentOffset = Cgpointmake (Kwidth,0); //Allows scrollview to scroll by pageself.scrollView.pagingEnabled =YES;//Turn off horizontal scroll barsSelf.scrollView.showsHorizontalScrollIndicator =NO;//Turn off vertical scroll barsSelf.scrollView.showsVerticalScrollIndicator =NO;//turn off the bounding rebound effectSelf.scrollView.bounces =NO;//set a Tag valueSelf.scrollView.tag =101; //If you want to have a horizontal or vertical rebound effect scrollview scrolling range needs to be set to screen sizeSelf.scrollView.alwaysBounceHorizontal =YES; Self.scrollView.alwaysBounceVertical= YES;
    • Ii. the protocol method of Uiscrollview
1. Uiscrollview protocol Method
    • The first is to monitor the state of the scrolling time.
    • The second is to control the zoom of the view.
2.
    • Trigger Order: Begindragging->didenddragging->begindecelerating->didenddecelerating
3. Control the zoom of the view

// set the maximum scale for scaling 2  //  Set the minimum scale for scaling 0.5//  Set the current scale to 1;

    • When we set the maximum and minimum scale in the Viewdidload method, we can zoom on the view.

Three, Uiscrollview and Uipageco ntrol combination of Use

iOS Learning Uiscrollview

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.