CustomSizeController 1.0.1

CustomSizeController 1.0.1

Maintained by Warif Akhand Rishi.



  • By
  • Warif Akhand Rishi

CustomSizeController

CI Status Version License Platform

Overview

CustomSizeController is a subclass of UIPresentationController allowing custom size for any UIViewController.

Usage

import CustomSizeController

Add these two extensions to your view controller

extension ViewController: UIViewControllerTransitioningDelegate {

    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {

        let customSizePC = CustomSizeController(presentedViewController: presented, presenting: presenting)
        customSizePC.sizeDelegate = self
        //customSizePC.isDisabledTapOutside = true

        return customSizePC
    }
}

extension ViewController: CustomSizeControllerDelegate {

    func frameOfPresentedView(in containerViewFrame: CGRect) -> CGRect {

        return CGRect(origin: CGPoint(x: 0, y: containerViewFrame.height / 4), size: CGSize(width: containerViewFrame.width, height: containerViewFrame.height / (4/3)))
    }
}

return a frame for the small view controller from frameOfPresentedView(in:) function.

How to Present the view controller

From Code:

let vc = storyboard?.instantiateViewController(withIdentifier: "SmallVC") as! SmallViewController
vc.modalPresentationStyle = .custom
vc.transitioningDelegate = self
present(vc, animated: true, completion: nil)

From Storyboard:

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

    if let smallVC = segue.destination as? SmallViewController {

        smallVC.modalPresentationStyle = .custom
        smallVC.transitioningDelegate = self
    }
}

Disable dismiss on tap outside

customSizePC.isDisabledTapOutside = true

Example

An example project is included with this repo. To run the example project, clone the repo, and run pod install from the Example directory first.

Minimum Requirements

  • Xcode 9
  • iOS 9.3

Installation with CocoaPods

CustomSizeController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CustomSizeController'

Author

Warif Akhand Rishi, [email protected]

License

CustomSizeController is available under the MIT license. See the LICENSE file for more info.