0

I have tried so many different blog and video tutorials and all of them are very convoluted. I can't imagine this technique is as hard as it seems to be. These are my view controllers: enter image description here

All I want is for, after signing, my app goes to the middle view controller (the home controller). Then, I want to be able to swipe left and right to the adjacent view controllers. I have tried so many tutorials on UIPageViewControllers and UIScrollViews and to no success. I already have these view controllers, I just need a simple way to swipe between them. I feel like this should be very easy but every video I watch is on how to make a tutorial in an app with the UIPageViewController. I just need these 3 view controllers to be navigated via swiping.

Any help would be greatly appreciated.

evanhaus
  • 727
  • 3
  • 12
  • 30

2 Answers2

0

If you want to achieve this using UISwipeGesture then you can try following code...

here you just need to give animation in viewDidLoad() method to self.view so that it looks like it swipe one controller from another.

In middle view controller you need to check that from which controller you have pushed to MiddleController and after that put left or right animation depend on your controller.

override func viewDidLoad()
{
    super.viewDidLoad()

    self.imgSlideInFromLeft(self.view)

    let swipeGesture:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipeViewFromLeft:"))
    swipeGesture.direction = .Right
    swipeGesture.numberOfTouchesRequired = 1
    swipeGesture.delegate = self
    self.view .addGestureRecognizer(swipeGesture)
}

func imgSlideInFromLeft(view: UIView)
{
    let transition:CATransition = CATransition()
    transition.duration = 0
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromRight
    transition.delegate = self
    view.layer .addAnimation(transition, forKey: "transition")
}

func swipeViewFromLeft(recognizer : UISwipeGestureRecognizer)
{
    let followingController = FollowingController()
    self.navigationController!.pushViewController(followingController, animated: false)
}
DJ1
  • 936
  • 15
  • 29
0

You can follow below link.

PageScroller_swift

Just with one change get page controller which you want. In your case you want to jump directly on the 1st —> Home view controller then get view controller from index 1.

self.setViewControllers([getViewControllerAtIndex(1)] as [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
VRAwesome
  • 4,721
  • 5
  • 27
  • 52