Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UITableViewのスクロールに合わせて、UIViewControllerを縦方向にページングする

Taiki Suzuki
September 28, 2016

 UITableViewのスクロールに合わせて、UIViewControllerを縦方向にページングする

Taiki Suzuki

September 28, 2016
Tweet

More Decks by Taiki Suzuki

Other Decks in Programming

Transcript

  1. ॎํ޲ͷભҠ • ࿮ͰғΘΕͨ෦෼͕ը໘ʹදࣔ͞Εͯ ͍Δ෦෼ • upperͱcenterͷ HCContentViewControllerͷ view.frame.origin.y͸ม͑ͳ͍ • centerͷHCContentViewControllerͷ

    UITableView͕bounce͍ͯ͠Δ෦෼ ʹɺlowerͷHCContentViewController ͷview͕ॏͳ͍ͬͯΔͷͰɺ࿈ಈͯ͠ ͍ΔΑ͏ʹݟ͑Δ
  2. BackϘλϯͰͷભҠ class HCRootAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning { @objc func animateTransition(using transitionContext:

    UIViewControllerContextTransitioning) { //লུ var initialFrame: CGRect? if let rootVC = toVC as? HCRootViewController, let pagingVC = fromVC as? HCPagingViewController { let indexPath = pagingVC.currentIndexPath //֘౰ͷcell͕ը໘಺ʹଘࡏ͠ͳ͍৔߹͸ɺͦͷcell·ͰΞχϝʔγϣϯͳ͠ͰεΫϩʔϧʢলུʣ if let cell = rootVC.tableView?.cellForRow(at: indexPath) { //ը໘ʹରͯ͠ͷ֘౰ͷcellͷҐஔΛऔಘ if let superview = rootVC.view, let point = cell.superview?.convert(cell.frame.origin, to: superview) { initialFrame = CGRect(origin: point, size: cell.bounds.size) ɹɹɹɹɹ } ɹɹɹɹɹɹɹ} rootVC.tableView?.selectRow(at: indexPath, animated: false, scrollPosition: .none) //֘౰ͷcellΛબ୒ঢ়ଶʹ͢Δ } //লུ //HCPagingViewControllerͷview͕initialFrameʹͳΔΞχϝʔγϣϯΛ࣮ߦʢলུʣ } }
  3. ΤοδεϫΠϓͰͷભҠ HCDefaultAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning { @objc func animateTransition(using transitionContext: UIViewControllerContextTransitioning)

    { //লུ if let pagingVC = fromVC as? HCPagingViewController, let rootVC = toVC as? HCRootViewController { let indexPath = pagingVC.currentIndexPath //֘౰ͷcell͕ը໘಺ʹଘࡏ͠ͳ͍৔߹͸ɺͦͷcell·ͰΞχϝʔγϣϯͳ͠ͰεΫϩʔϧ if rootVC.tableView?.cellForRow(at: indexPath) == nil { rootVC.tableView?.scrollToRowAtIndexPath( indexPath, atScrollPosition: pagingVC.scrollDirection, animated: false) } //֘౰ͷcellΛબ୒ঢ়ଶʹ͢Δ rootVC.tableView?.selectRow(at: indexPath, animated: false, scrollPosition: .none) } //লུ //ΤοδεϫΠϓͰભҠ͢ΔΞχϝʔγϣϯΛ࣮ߦʢলུʣ } }
  4. MisterFusion3 3 MisterFusion is Swift DSL for AutoLayout. It is

    the extremely clear, but concise syntax. https://github.com/marty-suzuki/MisterFusion
  5. MartyJunior4 4 You can change tab contents with swipe gesture

    on middle of UITableView. https://github.com/marty-suzuki/MartyJunior