Taimoor Arif
Taimoor Arif

Reputation: 1190

Swipe a uiView in Swift like Tab View Controller

I want to swipe a uiView like we use in tab view controller in SwiftUI but while using storyboard, if we use tab view controller whole screen is been swiped but i have to swipe only half of the screen and perform some functions there. i am attaching screenshot of it for better understanding:

screenshot of my simulator

I want this type of response. With the button Add New Group I am adding a new group, and by swiping I want to see my secondary groups.

Upvotes: -2

Views: 746

Answers (1)

bdeviOS
bdeviOS

Reputation: 563

enter image description here

enter image description here

 let viewsList : [UIViewController] = {
        
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
       
        let vc1 = storyBoard.instantiateViewController(withIdentifier: "FirstViewController")
        let vc2 = storyBoard.instantiateViewController(withIdentifier: "SecondViewController")
        let vc3 = storyBoard.instantiateViewController(withIdentifier: "ThirdViewController")
        
        return [vc1, vc2, vc3]
        
    }()
    

add codes in viewDidLoad()

override func viewDidLoad() {
        super.viewDidLoad()
        self.dataSource = self
        self.delegate = self
        
        if let firstvc = viewsList.first {
            self.setViewControllers([firstvc], direction: .forward, animated: true, completion: nil)
        }
        
    }

detect next page or previous page.

        func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [AnyObject], transitionCompleted completed: Bool) {
      if completed {
        if previousIndex < currentIndex {   // forward
    
        }
        else if previousIndex > currentIndex {  // reverse
    
        }
      }
    }

Upvotes: 1

Related Questions