UIViews with UIPageControl

I start when it comes to page controls, and so I'm not 100% sure if my headline agrees with what I want. I want to make UIPageControl, which, when the user goes over the screen, will switch to a different view, and the UIPageController at the bottom of the screen will be updated. In addition, to make my query even more confusing, I want a tab bar at the bottom of the screen to stay set when changing views.

A great example of this is The Iconfactory Ramp Champ: http://img.slidetoplay.com/screenshots/ramp-champ_5.jpg

The bar at the bottom remains while the rest of the elements on the screen move. What would be the easiest way to do this?

EDIT: I know that I need to use UISrollView, I just don't know how to implement this ...

+6
ios objective-c iphone uiview uipagecontrol
source share
2 answers

I believe you are looking for a UIScrollView , and pagingEnabled for YES. You can leave scrollview as a view above a regular UITabBar. You will use UIPageControl to get small dots. You can update it programmatically when the UIScrollView scrolls to the page, implementing the appropriate scroll delegate method, possibly -scrollViewDidScroll :.

Suppose you have two ivars: scrollView and pageControl. When you know how many pages will be displayed in your scroll, you can set contentSize for scrollView. It must be a multiple of the scrollView bounds. For example, if the number of pages is static, you can copy it to your -viewDidLoad ...

- (void)viewDidLoad { // Any other code. scrollView.pagingEnabled = YES; scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * 3, scrollView.bounds.size.height); // 3 pages wide. scrollView.delegate = self; } 

Then, to update your little dots ...

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat pageWidth = scrollView.bounds.size.width; NSInteger pageNumber = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; pageControl.currentPage = pageNumber; } 
+22
source share

You need to use UIScrollView

Assuming you have a named ivar called scrollView

  int amountOfFrames = 10; scrollView.pagingEnabled = TRUE; scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * amountOfFrames, scrollView.frame.size.height); scrollView.delegate = self; 

Then you need to implement the required delegation methods so that you can update page management

 - (void)scrollViewDidScroll:(UIScrollView *)sender { // Switch the indicator when more than 50% of the previous/next page is visible CGFloat pageWidth = scrollView.frame.size.width; int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; pageControl.currentPage = page; } 

You need to put any content that you want to scroll inside this scroll, ideally lazyload into it, if the content that you will display requires a lot of heap memory, use scrollviewDidScroll to delete and add content to the required positions

+2
source share

All Articles