I know I have asked this question a couple of times, but I'm very inexperienced and don't think I've been given the right answer yet.
I now have two view controllers, each with a .h file, a .m file, and a .xib file. In both the .xib files, I have a UIView. How can I make it so that you can swipe between these two views? For example, the app opens on the first view, then you swipe from the right to the left and the next view appears. I want the animation of the swiping to be like that of the Photos app when swiping through photos.
There are a number of right ways to to rich your goal.
For example:
1) From iOS 6 you can use
UIPageViewController
with transitionStyle propertyUIPageViewControllerTransitionStyleScroll
2) You can use
UIScrollView
with propertypagingEnable = YES;
and add your views inside it. Also you will need to implement all containers methodsaddChildViewController:
,removeFromParentViewController
,willMoveToParentViewController:
,didMoveToParentViewController:
to deal with with appear/disappear mathods of your controllers3) you can find third-party solution like:
Here is a great repo for this:
https://github.com/goktugyil/EZSwipeController
You basically need a UIPageViewController and put your ViewControllers inside that.
While you could implement this yourself (with custom container view controller in conjunction with
UIPanGestureRecognizer
orUIScrollView
), if using iOS 6 and later, the easiest way will be to use a Page View Controller with "scroll" transition style.Consider this storyboard:
It consists of a page view controller, and two scenes for two pages. Page 1 has a storyboard identifier of
one
and a base class ofPageOneViewController
. Page 2 has a storyboard identifier oftwo
and a base class ofPageTwoViewController
.I then wrote a
UIPageViewController
subclass (and, perhaps obvious, this is the class I specified for the first scene of the above storyboard), which has the following code:You could do this with NIBs, too, but it requires writing more code. If you search for
UIPageViewController XIB
and you'll probably get some hits.If you need to support iOS versions prior to 6.0, you'll have to do the custom container approach with pan gesture or scroll view.
you can use this repo .It is so much simpler and easily understandable for RnD. (Swift 3 code)
https://github.com/lakshikabhardwaj/LBViewControllerCollection