IOS - loading and switching between pages using UIPageContol

I would like to use UIPageControl to navigate between different controllers. I have 2 view controllers, and the other main view controller contains a UIPageControl . Type 2 controllers that will be moved between them have been added as children to the main view controller. When I am currently running the application, I see a blank screen. I used pageControl.currentPage = 0 , but I can not understand why I do not see the views.

Please note that I do not want to use UIScrollView in my application.

Edit - I completed this tutorial http://www.wannabegeek.com/?p=168

But it uses a scroll view. I do not want to use scroll view, as it creates some problems with UIWebView and CorePlot, which I use in different view managers.

I am looking for recommendations on how to change this tutorial without using scroll. Thanks!

+1
source share
3 answers

Adding other view controllers, since the children simply bind the view controllers - they do not add the views they control as subviews. Thus, when you add them as children, you must also add sub-items and set the initial frames. You may also need to add gesture wipes to trigger a view animation to animate view frames (although there are several other options, such as scrolling).

As part of the animation for moving views, you manually refresh the page control (this will not happen automatically).


The loadScrollViewWithPage method is the key. Call this parameter 0 and then 1 to load both pages and add subzones views. Just change self.scrollView to self.view .

I would add (two actually, but first started working) to move on to managing the page. Then, when it is displayed, you can move other views.

Gesture motion callback:

 - (void)swipeRightToLeftGesture:(UIGestureRecognizer *)gestureRecognizer { [UIView animateWithDuration:1 animations:^{ for (UIViewController *vc in self.childViewControllers) { CGRect frame = vc.view.frame; frame.origin.x -= self.view.frame.size.width; vc.view.frame = frame; } }]; } 

These iterate over the child view controllers and animate their view frames to move them to the left. Scrolling left to the right handler will be the same, except that the width += will shift to the right.

[Code Edited - Syntax]

+1
source

UIPageControl does not handle page switching or page switching for you. To use it, you NEED to have a scroll view (or some other control) to handle checks and actually switch pages, and then implement the UIScrollViewDelegate protocol (or any protocol that is needed for the control you are using) to know when the element The page control should update the current position of the page (the current selected point). UIPageControl alone does not do much.

+1
source

UIPageControl does nothing but display some points. If you need a way to switch between view controllers, it looks like you want a UIPageViewController, which is a completely different animal. A good feature of the UIPageViewController is that it can display the UIPageControl as a way to display / switch view controllers, which may be exactly what you need.

0
source

Source: https://habr.com/ru/post/912748/


All Articles