0

I am totally aware that you cannot push the same UIViewController from a UINavigationController. However my implementation demands so. I have to swipe gestures. On swiping right to left, I have to reload the content of view (which is a UIScrollView) along with animation. And vice versa on left to right swipe. I have tried with following but it does not give the expected animation:

func leftSwipe()
    {
        self.scroll_course_detail.frame = CGRect(x: 2*self.scroll_course_detail!.frame.size.width, y: self.scroll_course_detail.frame.origin.y, width: self.scroll_course_detail.frame.size.width, height: self.scroll_course_detail.frame.size.height)
        UIView.animate(withDuration: 0.25, animations: {() -> Void in
            self.scroll_course_detail.frame = CGRect(x: 0, y: self.scroll_course_detail.frame.origin.y, width: self.scroll_course_detail.frame.size.width, height: self.scroll_course_detail.frame.size.height)
        })
    }

    func rightSwipe()
    {
        self.scroll_course_detail.frame = CGRect(x: -self.scroll_course_detail!.frame.size.width, y: self.scroll_course_detail.frame.origin.y, width: self.scroll_course_detail.frame.size.width, height: self.scroll_course_detail.frame.size.height)
        UIView.animate(withDuration: 0.25, animations: {() -> Void in
            self.scroll_course_detail.frame = CGRect(x: 0, y: self.scroll_course_detail.frame.origin.y, width: self.scroll_course_detail.frame.size.width, height: self.scroll_course_detail.frame.size.height)
        })
    }  

Before animation block, I am changing the frame of UIScrollView which makes the background clear for the animation duration. I was thinking that UIScrollView content is overriden along with animation So what should be the best approach for reloading content along with animation on swipe ?

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • What do you mean by reload contentView? Also what animation are you trying to achieve? Are you trying to make a scrollView behave like a NavigationController? – Brandon Oct 14 '16 at 03:38
  • @Brandon : I want to reload the content of UIScrollView. Yes, I want the animation to be just like UINavigationController. – Nitish Oct 14 '16 at 03:40
  • For swipe kind of effect with same view controller probably UIPageViewController is good choice. Will keep view hierarchy clean as well as clear way to reload data. Also manage two or three view controller instance at a time.So, memory management is free of charge – Iducool Oct 14 '16 at 03:44
  • Do you want it to be interactive or just happen? – agibson007 Jul 15 '17 at 22:27

0 Answers0