Uiscrollview can be used to display more than one screen of content, beyond the scope of the screen can be viewed by swiping, the Uipagecontrol class provides a line of points to indicate which page of a multi-page view is currently displayed.
The following implements a simple picture of an auto player as an example of some of the methods in Uiscrollview and Uipagecontrol classes.
Note: Scrolly,kscreenwidth,kscreenheight,kimgcount in the code below are defined constants
#define kScreenHeight [UIScreen mainScreen].bounds.size.height#define kScreenWidth [UIScreen mainScreen].bounds.size.widthCGFloat10;CGFloat10;CGFloat200;
Size in frame refers to the visual range of the Uiscrollview
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, scrollY, kScreenWidth, kScreenHeight - scrollY)];
Set the scrolling range (size) of the Uiscrollview
self.scrollView.contentSize = CGSizeMake(kScreenWidth * kImgCount, kScreenHeight - scrollY);
Control the full page Flip (page effect) of a control
self.scrollView.pagingEnabledYES;
Uiscrollview the current scrolling position, animated:yes means scrolling at a constant speed
[self.scrollView setContentOffset:point animated:YES];
For example: When you drag to half, the number of pages is 1.
NSInteger page = scrollView.contentOffset.x0.5;//contentOffset.x 表示在x轴上拖动的距离 self.pageCtrl.currentPage = page;
Initialize Uipagecontrol
self.pageCtrl = [[UIPageControl alloc] initWithFrame:CGRectMake((kScreenWidth - pageCtrlWidth)/2, kScreenHeight - scrollY, kScreenWidth/2, scrollY/2 )];
How many dots are shown in total?
self.pageCtrl.numberOfPages = kImgCount;
Set the dot color of a non-selected page
self.pageCtrl.pageIndicatorTintColor = [UIColor greenColor];
Set the dot color of the selected page
self.pageCtrl.currentPageIndicatorTintColor = [UIColor yellowColor];
a Insertsubview b abovesubview:c is to insert B into a and on top of a already existing child view C
a Addsubview B is to cover B directly at the top of a
a Insertsubview b atindex:2 is the position where B is inserted into the sub-view of a, index 2 (bottom 0)
A Insertsubview b belowsubview:c is to insert B into a and under a already existing sub-view C
Cases:
[selfinsertSubview:selfaboveSubview:self.scrollView];
Temporarily update Uiscrollview and Uipagecontrol These methods, of course, there are some other methods are not organized, follow-up will continue to accumulate according to learning situation!
IOS Uiscrollview,uipagecontrol