Lesson5 - Scroll

侧滑效果图

QQ20180320-113853.gif

项目代码地址

上个项目使用的collectionView的方式实现侧滑,这个主要是scrollview的方式,将不同的VC作为主VC的子控制器来进行管理

self.scrollView = UIScrollView.init(frame: self.view.bounds)
        self.view.addSubview(self.scrollView)
        
        let leftVC = LeftViewController()
        leftVC.view.frame = CGRect.init(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
        
        let centerVC = CenterViewController()
        centerVC.view.frame = CGRect.init(x: self.view.frame.width, y: 0, width: self.view.frame.width, height: self.view.frame.height)
        
        let rightVC = RightViewController()
        rightVC.view.frame = CGRect.init(x: 2 * self.view.frame.width, y: 0, width: self.view.frame.width, height: self.view.frame.height)
        
        self.addChildViewController(leftVC)
        self.scrollView.addSubview(leftVC.view)
        leftVC.didMove(toParentViewController: self)
        
        self.addChildViewController(centerVC)
        self.scrollView.addSubview(centerVC.view)
        centerVC.didMove(toParentViewController: self)
        
        self.addChildViewController(rightVC)
        self.scrollView.addSubview(rightVC.view)
        rightVC.didMove(toParentViewController: self)
        
        self.scrollView.contentSize = CGSize.init(width: self.view.frame.width * 3, height: self.view.frame.size.height)
        //是否一页一页的滚动
        self.scrollView.isPagingEnabled =
        true;

你可能感兴趣的:(Lesson5 - Scroll)