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;
}