zoukankan      html  css  js  c++  java
  • swift开发笔记11

    // 注意判断条件,  

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

     

        if let cell = sender as? UICollectionViewCell,

          let indexPath = collectionView?.indexPath(for: cell),

          let managePageViewController = segue.destination as? ManagePageViewController {

          managePageViewController.photos = photos

          managePageViewController.currentIndex = indexPath.row

        }

      }

    }

     

    // UIPageViewController 用法

    if let viewController = viewPhotoCommentController(index: currentIndex ?? 0) {

          let viewControllers = [viewController]

          setViewControllers (

            viewControllers,

            direction: .forward,

            animated: false,

            completion: nil

          )

        }

     

    // 来自storyboard的VC,初始化方法

      fileprivate func viewPhotoCommentController(index: Int) -> PhotoCommentViewController? {

        if let storyboard = storyboard,

          let page = storyboard.instantiateViewController(withIdentifier: "PhotoCommentViewController")

            as? PhotoCommentViewController {

          page.photoName = photos[index]

          page.photoIndex = index

          return page

        }

        

        return nil

      }

     

    // UIPageViewControllerDataSource

    extension ManagePageViewController: UIPageViewControllerDataSource {

      func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

        

        if let viewController = viewController as? PhotoCommentViewController {

          guard let index = viewController.photoIndex, index != 0 else {

            return nil

          }

          return viewPhotoCommentController(index: index - 1)

        }

        return nil

      }

      

      func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

        

        if let viewController = viewController as? PhotoCommentViewController {

          guard let index = viewController.photoIndex, index != photos.count - 1 else {

            return nil

          }

          return viewPhotoCommentController(index: index + 1)

        }

        return nil

      }

      

      /// MARK: UIPageControl

      func presentationCount(for pageViewController: UIPageViewController) -> Int {

        return photos.count

      }

      

      func presentationIndex(for pageViewController: UIPageViewController) -> Int {

        return currentIndex ?? 0

      }

    }

    // 初始化Selector

    fileprivate extension Selector {

      static let keyboardWillShowHandler = #selector(PhotoCommentViewController.keyboardWillShow(notification:))

      static let keyboardWillHideHandler = #selector(PhotoCommentViewController.keyboardWillHide(notification:))

      static let generalTap = #selector(PhotoCommentViewController.dismissKeyboard)

      static let zoomTap = #selector(PhotoCommentViewController.openZoomingController(sender:))

    }

    // UIScrollViewDelegate

        func viewForZooming(in scrollView: UIScrollView) -> UIView? {

            return myImageView

        }

        func scrollViewDidZoom(_ scrollView: UIScrollView) {

            updateConstraints(forSize: view.bounds.size)

        }

     

  • 相关阅读:
    PCB电路板元器件布局的一般原则*(转)
    PCB Layout初学者必会知识总结(转)
    数字器件和模拟器件?
    同一原理图中怎么区分数字电路和模拟电路
    oracle 11g R2执行INSERT语句,数据库把一个汉字看做3个汉字
    SQL存储过程与函数的区别
    用户自定义函数——Oracle 11g R2
    提高使用SQL Developer进行PL/SQL编程的效率——Oracle 11g R2
    Oracle查看用户使用的表
    JAVA-Eclipse快捷键
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/7374635.html
Copyright © 2011-2022 走看看