UIScrollView slide attempt, uiscrollview slide

Source: Internet
Author: User

UIScrollView slide attempt, uiscrollview slide

UIScrollView ---> UIView

// Create UIScrollView

TestScrollView = [[UIScrollView alloc] init];

TestScrollView. frame = CGRectMake (0, 0,320,200 );

TestScrollView. backgroundColor = [UIColor cyanColor];

// Set the capacity of UIScrollView

TestScrollView. contentSize = CGSizeMake (320*5,200 );

// Hide the horizontal indicator bar

TestScrollView. showsHorizontalScrollIndicator = NO;

// Hide the vertical indicator bar

TestScrollView. showsVerticalScrollIndicator = NO;

// Whether pagination is allowed. YES indicates that NO is allowed by default.

TestScrollView. pagingEnabled = YES;

// Set the edge animation effect to "NO". The default value is "Yes ".

TestScrollView. bounces = YES;

// Set proxy

TestScrollView. delegate = self;

// Display ScrollView

[Self. view addSubview: testScrollView];

 

// Create a UIPageControl, which is the count point in the image.

UIPageControl * page = [[UIPageControl alloc] initWithFrame: CGRectMake (110,130,100,100)];

// Page. backgroundColor = [UIColor redColor];

// Set the number of pages on the current page

Page. numberOfPages = 5;

// Set which page is displayed on the current page

Page. currentPage = 0;

// Set the color of the currently unselected middle page

Page. pageIndicatorTintColor = [UIColor yellowColor];

// Set the color of the selected page

Page. currentPageIndicatorTintColor = [UIColor redColor];

// Bind the UIPageControl Method

[Page addTarget: self action: @ selector (movePageControl :) forControlEvents: UIControlEventValueChanged];

// Create a timer

[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @ selector (move) userInfo: nil repeats: YES];

}

// The static variable is executed only once.

Static int count =-1;

// Implementation Method

-(Void) move

{

If (page. currentPage = 4 | page. currentPage = 0 ){

Count =-count;

}

Page. currentPage = page. currentPage + count;

// Set the offset of each jump

TestScrollView. contentOffset = CGPointMake (page. currentPage * 320, 0 );

}

// Locate the offset

-(Void) movePageControl :( UIPageControl *) pageControl

{

// Set the offset to have no animation effect

// TestScrollView. contentOffset = CGPointMake (320 * page. currentPage, 0 );

// Sets the scrollView offset and uses the animation effect.

[TestScrollView setContentOffset: CGPointMake (pageControl. currentPage * 320, 0)];

NSLog (@ "% d", pageControl. currentPage );

}

# Pragma mark-

# Pragma mark-UIScrollViewDelegete

// Called when the image is being moved

-(Void) scrollViewDidScroll :( UIScrollView *) scrollView

{

NSLog (@ "called when the image is being moved ");

}

// It will be called once at the beginning of image Movement

-(Void) scrollViewWillBeginDragging :( UIScrollView *) scrollView

{

NSLog (@ "this is called once when the image is moved ");

}

// Called once when scrollView is released

-(Void) scrollViewWillBeginDecelerating :( UIScrollView *) scrollView

{

NSLog (@ "called once when scrollView is released ");

}

// Call scrollView once after sliding ends

-(Void) scrollViewDidEndDecelerating :( UIScrollView *) scrollView

{

NSLog (@ "scrollView sliding end call once ");

NSLog (@ "% f", scrollView. contentOffset. x );

 

Page. currentPage = scrollView. contentOffset. x/320;

}

 

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.