Created
November 11, 2019 06:53
-
-
Save godrm/b444100f8d0a687d85727cfdd186b4c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// SideView | |
// | |
// Created by JK on 2019/11/11. | |
// Copyright © 2019 codesquad. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var menuView: UIView! | |
@IBOutlet weak var menuViewTrailingConstraint: NSLayoutConstraint! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let rightButton = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(rightButtonTouched(_:))) | |
rightButton.title = "X" | |
self.navigationItem.rightBarButtonItem = rightButton | |
} | |
@objc func rightButtonTouched(_ sender: UIBarButtonItem) { | |
} | |
@IBAction func leftButtonTouched(_ sender: Any) { | |
// UIView.animate(withDuration: 1) { | |
// self.menuViewTrailingConstraint.constant = 200 | |
// self.view.layoutIfNeeded() | |
// } | |
// let menuViewController = self.storyboard?.instantiateViewController(withIdentifier: "MenuViewController") as! MenuViewController | |
// self.addChild(menuViewController) | |
// self.view.addSubview(menuViewController.view) | |
// menuViewController.view.frame = CGRect(origin: menuView.frame.origin, size: CGSize(width: 300, height: menuView.frame.size.height)) | |
// menuViewController.view.frame.origin = CGPoint(x: 0, y: menuView.frame.origin.y) | |
// menuViewController.didMove(toParent: self) | |
let menuViewController = self.storyboard?.instantiateViewController(withIdentifier: "MenuViewController") as! MenuViewController | |
menuViewController.transitioningDelegate = self | |
menuViewController.modalPresentationStyle = .custom | |
self.present(menuViewController, animated: false, completion: { | |
// menuViewController.view.frame = CGRect(x: 0, y: 00, width: 200, height: 300) | |
self.view.alpha = 0.5 | |
}) | |
} | |
} | |
extension ViewController : UIViewControllerTransitioningDelegate { | |
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { | |
return Presenter(presentedViewController: presented, presenting: presenting) | |
} | |
} | |
class Presenter : UIPresentationController { | |
override var frameOfPresentedViewInContainerView: CGRect { | |
return CGRect(x: 100, y: 100, width: 200, height: 200) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment