├── .gitignore ├── EMPartialModalViewController └── EMPartialModalViewController.swift ├── Example ├── EMPartialModalViewController.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── EMPartialModalViewController │ ├── AppDelegate.swift │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── PrimaryViewController.swift │ ├── SecondaryViewController.swift │ └── ViewController.swift ├── LICENSE ├── README.md └── partial_modal.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | -------------------------------------------------------------------------------- /EMPartialModalViewController/EMPartialModalViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EMPartialModalViewController.swift 3 | // EMPartialModalViewController 4 | // 5 | // Created by Emad A. on 25/01/2015. 6 | // Copyright (c) 2015 Emad A. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class EMPartialModalViewController: UIViewController { 12 | 13 | // MARK: - Public Properties 14 | 15 | // The max height of content navigation view controller 16 | var contentViewMaxHeight: CGFloat = 402 { 17 | didSet { 18 | if contentViewController != nil { 19 | var frame: CGRect = contentViewController!.view.frame 20 | frame.size.height = contentViewMaxHeight 21 | frame.origin.y = CGRectGetMaxY(view.bounds) - frame.height 22 | 23 | contentViewController!.view.frame = frame 24 | } 25 | } 26 | } 27 | 28 | // MARK: - Private Properties 29 | 30 | // The height of content navigation view controller 31 | private var contentViewHeight: CGFloat = 0 32 | 33 | // A snapshot of man screen with status bar 34 | private var snapshotView: UIView?// = UIScreen.mainScreen().snapshotViewAfterScreenUpdates(false) 35 | 36 | // An overlay view, as button to dismiss the modal view controller on being touched 37 | private let overlayView: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton 38 | 39 | // A view controller holds the main content of modal 40 | private var contentViewController: UIViewController? 41 | 42 | // MARK: - Initializers 43 | 44 | convenience init(rootViewController: UIViewController) { 45 | self.init(rootViewController: rootViewController, contentHeight: rootViewController.view.bounds.height) 46 | } 47 | 48 | convenience init(rootViewController: UIViewController, contentHeight: CGFloat) { 49 | self.init() 50 | 51 | contentViewHeight = contentHeight 52 | 53 | contentViewController = rootViewController 54 | if contentViewController != nil { 55 | view.addSubview(contentViewController!.view) 56 | addChildViewController(contentViewController!) 57 | } 58 | } 59 | 60 | // MARK: - Overriden Methods 61 | 62 | override func viewDidLoad() { 63 | super.viewDidLoad() 64 | 65 | // Setting view controler properties to have customized presentation transition 66 | transitioningDelegate = self 67 | modalPresentationCapturesStatusBarAppearance = true 68 | modalPresentationStyle = UIModalPresentationStyle.Custom 69 | 70 | // The view should have balck background color. 71 | view.opaque = true 72 | view.backgroundColor = UIColor.blackColor() 73 | 74 | // Initializing overlay 75 | overlayView.frame = view.bounds 76 | overlayView.backgroundColor = UIColor(white: 0, alpha: 0.6) 77 | overlayView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight 78 | overlayView.addTarget(self, action: Selector("dismissViewController"), forControlEvents: UIControlEvents.TouchUpInside) 79 | 80 | view.addSubview(overlayView) 81 | } 82 | 83 | override func viewWillAppear(animated: Bool) { 84 | super.viewWillAppear(animated) 85 | 86 | if contentViewController != nil { 87 | contentViewHeight = min(contentViewHeight, self.contentViewMaxHeight) 88 | var frame = CGRectZero 89 | frame.size = CGSizeMake(view.bounds.width, contentViewHeight) 90 | frame.origin = CGPointMake(CGRectGetMinX(view.bounds), CGRectGetMaxY(view.bounds) - frame.height) 91 | contentViewController!.view.frame = frame 92 | } 93 | } 94 | 95 | override func preferredStatusBarStyle() -> UIStatusBarStyle { 96 | return UIStatusBarStyle.LightContent 97 | } 98 | 99 | // MARK: - Public Methods 100 | 101 | func dismissViewController() { 102 | dismissViewControllerAnimated(true, completion: nil) 103 | } 104 | } 105 | 106 | extension EMPartialModalViewController: UIViewControllerTransitioningDelegate { 107 | 108 | func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 109 | return self 110 | } 111 | 112 | func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 113 | return self 114 | } 115 | } 116 | 117 | extension EMPartialModalViewController: UIViewControllerAnimatedTransitioning { 118 | 119 | func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { 120 | return 0.42 121 | } 122 | 123 | func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 124 | let fromViewController: UIViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! 125 | let toViewController: UIViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! 126 | let animationDuration: NSTimeInterval = transitionDuration(transitionContext) 127 | let containerView: UIView = transitionContext.containerView() 128 | 129 | fromViewController.viewWillDisappear(transitionContext.isAnimated()) 130 | toViewController.viewWillAppear(transitionContext.isAnimated()) 131 | 132 | // To present the view controller 133 | if let viewController = toViewController as? EMPartialModalViewController { 134 | if viewController.contentViewController == nil { 135 | return; 136 | } 137 | 138 | // Setting the srart point of overlay alpha animation 139 | viewController.overlayView.alpha = 0; 140 | 141 | // Inserting the snapshot of the window root view controller at the back all views of modal view controller 142 | // The snapshot is going to be scaled down 143 | viewController.snapshotView = fromViewController.view.resizableSnapshotViewFromRect( 144 | toViewController.view.frame, 145 | afterScreenUpdates: false, 146 | withCapInsets: UIEdgeInsetsZero) 147 | let snapshot: UIView = viewController.snapshotView! 148 | viewController.view.insertSubview(snapshot, atIndex: 0) 149 | 150 | // Frame for snapshot to scale it down 151 | var frame: CGRect = snapshot.frame 152 | let snapshotScale = UIApplication.sharedApplication().statusBarFrame.height / frame.height 153 | frame = CGRectInset(frame, frame.width * snapshotScale, frame.height * snapshotScale) 154 | 155 | // Putting the modal view content at the bottom of the view 156 | let view = viewController.contentViewController!.view 157 | view.transform = CGAffineTransformMakeTranslation(0, view.bounds.height) 158 | 159 | // Adding the modal view controller into view 160 | containerView.addSubview(viewController.view) 161 | 162 | // Starting animation 163 | UIView.animateWithDuration( 164 | animationDuration, 165 | delay: 0, 166 | usingSpringWithDamping: 1, 167 | initialSpringVelocity: 1, 168 | options: UIViewAnimationOptions.CurveEaseOut, 169 | animations: { () -> Void in 170 | viewController.overlayView.alpha = 1 171 | view.transform = CGAffineTransformMakeTranslation(0, 0) 172 | snapshot.frame = frame 173 | }, 174 | completion: { (Bool) -> Void in 175 | transitionContext.completeTransition(true) 176 | viewController.viewDidAppear(transitionContext.isAnimated()) 177 | fromViewController.viewDidDisappear(transitionContext.isAnimated()) 178 | }) 179 | } 180 | 181 | // To dismiss the view controller 182 | else if let viewController = fromViewController as? EMPartialModalViewController { 183 | if viewController.contentViewController == nil { 184 | return; 185 | } 186 | 187 | // Getting the view of the content view controller 188 | let view: UIView = viewController.contentViewController!.view 189 | 190 | // Start animation 191 | UIView.animateWithDuration( 192 | animationDuration, 193 | delay: 0, 194 | usingSpringWithDamping: 1, 195 | initialSpringVelocity: 1, 196 | options: UIViewAnimationOptions.CurveEaseOut, 197 | animations: { () -> Void in 198 | viewController.overlayView.alpha = 0; 199 | view.transform = CGAffineTransformMakeTranslation(0, view.bounds.height) 200 | viewController.snapshotView?.frame = viewController.view.bounds 201 | }, 202 | completion: { (Bool) -> Void in 203 | transitionContext.completeTransition(true) 204 | toViewController.viewDidAppear(transitionContext.isAnimated()) 205 | fromViewController.viewDidDisappear(transitionContext.isAnimated()) 206 | }) 207 | } 208 | } 209 | } -------------------------------------------------------------------------------- /Example/EMPartialModalViewController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 047FA2B31A920A60006D7167 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047FA2B21A920A60006D7167 /* AppDelegate.swift */; }; 11 | 047FA2B51A920A60006D7167 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047FA2B41A920A60006D7167 /* ViewController.swift */; }; 12 | 047FA2B81A920A60006D7167 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 047FA2B61A920A60006D7167 /* Main.storyboard */; }; 13 | 047FA2BA1A920A60006D7167 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 047FA2B91A920A60006D7167 /* Images.xcassets */; }; 14 | 047FA2BD1A920A60006D7167 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 047FA2BB1A920A60006D7167 /* LaunchScreen.xib */; }; 15 | 047FA2D51A920B1C006D7167 /* EMPartialModalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047FA2D41A920B1C006D7167 /* EMPartialModalViewController.swift */; }; 16 | 047FA2DB1A921038006D7167 /* SecondaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047FA2DA1A921038006D7167 /* SecondaryViewController.swift */; }; 17 | 047FA2DD1A921379006D7167 /* PrimaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047FA2DC1A921379006D7167 /* PrimaryViewController.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 047FA2AD1A920A60006D7167 /* EMPartialModalViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EMPartialModalViewController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 047FA2B11A920A60006D7167 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | 047FA2B21A920A60006D7167 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 047FA2B41A920A60006D7167 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | 047FA2B71A920A60006D7167 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | 047FA2B91A920A60006D7167 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 27 | 047FA2BC1A920A60006D7167 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 28 | 047FA2D41A920B1C006D7167 /* EMPartialModalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EMPartialModalViewController.swift; sourceTree = ""; }; 29 | 047FA2DA1A921038006D7167 /* SecondaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondaryViewController.swift; sourceTree = ""; }; 30 | 047FA2DC1A921379006D7167 /* PrimaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrimaryViewController.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 047FA2AA1A920A60006D7167 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 047FA2A41A920A60006D7167 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 047FA2D31A920B1C006D7167 /* EMPartialModalViewController */, 48 | 047FA2AF1A920A60006D7167 /* EMPartialModalViewControllerExample */, 49 | 047FA2AE1A920A60006D7167 /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | 047FA2AE1A920A60006D7167 /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 047FA2AD1A920A60006D7167 /* EMPartialModalViewController.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | 047FA2AF1A920A60006D7167 /* EMPartialModalViewControllerExample */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 047FA2B21A920A60006D7167 /* AppDelegate.swift */, 65 | 047FA2B41A920A60006D7167 /* ViewController.swift */, 66 | 047FA2DC1A921379006D7167 /* PrimaryViewController.swift */, 67 | 047FA2DA1A921038006D7167 /* SecondaryViewController.swift */, 68 | 047FA2B61A920A60006D7167 /* Main.storyboard */, 69 | 047FA2B91A920A60006D7167 /* Images.xcassets */, 70 | 047FA2BB1A920A60006D7167 /* LaunchScreen.xib */, 71 | 047FA2B01A920A60006D7167 /* Supporting Files */, 72 | ); 73 | name = EMPartialModalViewControllerExample; 74 | path = EMPartialModalViewController; 75 | sourceTree = ""; 76 | }; 77 | 047FA2B01A920A60006D7167 /* Supporting Files */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 047FA2B11A920A60006D7167 /* Info.plist */, 81 | ); 82 | name = "Supporting Files"; 83 | sourceTree = ""; 84 | }; 85 | 047FA2D31A920B1C006D7167 /* EMPartialModalViewController */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 047FA2D41A920B1C006D7167 /* EMPartialModalViewController.swift */, 89 | ); 90 | name = EMPartialModalViewController; 91 | path = ../EMPartialModalViewController; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | 047FA2AC1A920A60006D7167 /* EMPartialModalViewController */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = 047FA2CC1A920A60006D7167 /* Build configuration list for PBXNativeTarget "EMPartialModalViewController" */; 100 | buildPhases = ( 101 | 047FA2A91A920A60006D7167 /* Sources */, 102 | 047FA2AA1A920A60006D7167 /* Frameworks */, 103 | 047FA2AB1A920A60006D7167 /* Resources */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = EMPartialModalViewController; 110 | productName = EMPartialModalViewController; 111 | productReference = 047FA2AD1A920A60006D7167 /* EMPartialModalViewController.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | 047FA2A51A920A60006D7167 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastUpgradeCheck = 0610; 121 | ORGANIZATIONNAME = "Emad A."; 122 | TargetAttributes = { 123 | 047FA2AC1A920A60006D7167 = { 124 | CreatedOnToolsVersion = 6.1.1; 125 | }; 126 | }; 127 | }; 128 | buildConfigurationList = 047FA2A81A920A60006D7167 /* Build configuration list for PBXProject "EMPartialModalViewController" */; 129 | compatibilityVersion = "Xcode 3.2"; 130 | developmentRegion = English; 131 | hasScannedForEncodings = 0; 132 | knownRegions = ( 133 | en, 134 | Base, 135 | ); 136 | mainGroup = 047FA2A41A920A60006D7167; 137 | productRefGroup = 047FA2AE1A920A60006D7167 /* Products */; 138 | projectDirPath = ""; 139 | projectRoot = ""; 140 | targets = ( 141 | 047FA2AC1A920A60006D7167 /* EMPartialModalViewController */, 142 | ); 143 | }; 144 | /* End PBXProject section */ 145 | 146 | /* Begin PBXResourcesBuildPhase section */ 147 | 047FA2AB1A920A60006D7167 /* Resources */ = { 148 | isa = PBXResourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 047FA2B81A920A60006D7167 /* Main.storyboard in Resources */, 152 | 047FA2BD1A920A60006D7167 /* LaunchScreen.xib in Resources */, 153 | 047FA2BA1A920A60006D7167 /* Images.xcassets in Resources */, 154 | ); 155 | runOnlyForDeploymentPostprocessing = 0; 156 | }; 157 | /* End PBXResourcesBuildPhase section */ 158 | 159 | /* Begin PBXSourcesBuildPhase section */ 160 | 047FA2A91A920A60006D7167 /* Sources */ = { 161 | isa = PBXSourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 047FA2D51A920B1C006D7167 /* EMPartialModalViewController.swift in Sources */, 165 | 047FA2B51A920A60006D7167 /* ViewController.swift in Sources */, 166 | 047FA2B31A920A60006D7167 /* AppDelegate.swift in Sources */, 167 | 047FA2DD1A921379006D7167 /* PrimaryViewController.swift in Sources */, 168 | 047FA2DB1A921038006D7167 /* SecondaryViewController.swift in Sources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXSourcesBuildPhase section */ 173 | 174 | /* Begin PBXVariantGroup section */ 175 | 047FA2B61A920A60006D7167 /* Main.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | 047FA2B71A920A60006D7167 /* Base */, 179 | ); 180 | name = Main.storyboard; 181 | sourceTree = ""; 182 | }; 183 | 047FA2BB1A920A60006D7167 /* LaunchScreen.xib */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 047FA2BC1A920A60006D7167 /* Base */, 187 | ); 188 | name = LaunchScreen.xib; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | 047FA2CA1A920A60006D7167 /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_UNREACHABLE_CODE = YES; 210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 211 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 212 | COPY_PHASE_STRIP = NO; 213 | ENABLE_STRICT_OBJC_MSGSEND = YES; 214 | GCC_C_LANGUAGE_STANDARD = gnu99; 215 | GCC_DYNAMIC_NO_PIC = NO; 216 | GCC_OPTIMIZATION_LEVEL = 0; 217 | GCC_PREPROCESSOR_DEFINITIONS = ( 218 | "DEBUG=1", 219 | "$(inherited)", 220 | ); 221 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 222 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 223 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 224 | GCC_WARN_UNDECLARED_SELECTOR = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 226 | GCC_WARN_UNUSED_FUNCTION = YES; 227 | GCC_WARN_UNUSED_VARIABLE = YES; 228 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 229 | MTL_ENABLE_DEBUG_INFO = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 233 | }; 234 | name = Debug; 235 | }; 236 | 047FA2CB1A920A60006D7167 /* Release */ = { 237 | isa = XCBuildConfiguration; 238 | buildSettings = { 239 | ALWAYS_SEARCH_USER_PATHS = NO; 240 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 241 | CLANG_CXX_LIBRARY = "libc++"; 242 | CLANG_ENABLE_MODULES = YES; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_CONSTANT_CONVERSION = YES; 246 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INT_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_UNREACHABLE_CODE = YES; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 254 | COPY_PHASE_STRIP = YES; 255 | ENABLE_NS_ASSERTIONS = NO; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu99; 258 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 259 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 260 | GCC_WARN_UNDECLARED_SELECTOR = YES; 261 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 262 | GCC_WARN_UNUSED_FUNCTION = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 265 | MTL_ENABLE_DEBUG_INFO = NO; 266 | SDKROOT = iphoneos; 267 | VALIDATE_PRODUCT = YES; 268 | }; 269 | name = Release; 270 | }; 271 | 047FA2CD1A920A60006D7167 /* Debug */ = { 272 | isa = XCBuildConfiguration; 273 | buildSettings = { 274 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 275 | INFOPLIST_FILE = EMPartialModalViewController/Info.plist; 276 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | }; 279 | name = Debug; 280 | }; 281 | 047FA2CE1A920A60006D7167 /* Release */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | INFOPLIST_FILE = EMPartialModalViewController/Info.plist; 286 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | }; 289 | name = Release; 290 | }; 291 | /* End XCBuildConfiguration section */ 292 | 293 | /* Begin XCConfigurationList section */ 294 | 047FA2A81A920A60006D7167 /* Build configuration list for PBXProject "EMPartialModalViewController" */ = { 295 | isa = XCConfigurationList; 296 | buildConfigurations = ( 297 | 047FA2CA1A920A60006D7167 /* Debug */, 298 | 047FA2CB1A920A60006D7167 /* Release */, 299 | ); 300 | defaultConfigurationIsVisible = 0; 301 | defaultConfigurationName = Release; 302 | }; 303 | 047FA2CC1A920A60006D7167 /* Build configuration list for PBXNativeTarget "EMPartialModalViewController" */ = { 304 | isa = XCConfigurationList; 305 | buildConfigurations = ( 306 | 047FA2CD1A920A60006D7167 /* Debug */, 307 | 047FA2CE1A920A60006D7167 /* Release */, 308 | ); 309 | defaultConfigurationIsVisible = 0; 310 | defaultConfigurationName = Release; 311 | }; 312 | /* End XCConfigurationList section */ 313 | }; 314 | rootObject = 047FA2A51A920A60006D7167 /* Project object */; 315 | } 316 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // EMPartialModalViewController 4 | // 5 | // Created by Emad A. on 16/02/2015. 6 | // Copyright (c) 2015 Emad A. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 31 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.codeisjoy.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/PrimaryViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PrimaryViewController.swift 3 | // EMPartialModalViewController 4 | // 5 | // Created by Emad A. on 16/02/2015. 6 | // Copyright (c) 2015 Emad A. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PrimaryViewController: UIViewController { 12 | 13 | @IBAction func dismiss() { 14 | parentViewController?.dismissViewControllerAnimated(true) { 15 | println("dismissing view controller - done") 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/SecondaryViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondaryViewController.swift 3 | // EMPartialModalViewController 4 | // 5 | // Created by Emad A. on 16/02/2015. 6 | // Copyright (c) 2015 Emad A. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondaryViewController: UIViewController { 12 | 13 | @IBAction func dismiss() { 14 | parentViewController?.dismissViewControllerAnimated(true) { 15 | println("dismissing view controller - done") 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/EMPartialModalViewController/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // EMPartialModalViewController 4 | // 5 | // Created by Emad A. on 16/02/2015. 6 | // Copyright (c) 2015 Emad A. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func viewWillAppear(animated: Bool) { 19 | super.viewDidAppear(animated) 20 | println(__LINE__,__FUNCTION__) 21 | } 22 | 23 | override func viewDidAppear(animated: Bool) { 24 | super.viewDidAppear(animated) 25 | println(__LINE__,__FUNCTION__) 26 | } 27 | 28 | override func viewWillDisappear(animated: Bool) { 29 | super.viewWillDisappear(animated) 30 | println(__LINE__,__FUNCTION__) 31 | } 32 | 33 | override func viewDidDisappear(animated: Bool) { 34 | super.viewDidDisappear(animated) 35 | println(__LINE__,__FUNCTION__) 36 | } 37 | 38 | override func didReceiveMemoryWarning() { 39 | super.didReceiveMemoryWarning() 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | @IBAction func showModalViewController_1() { 44 | let content: UIViewController = storyboard!.instantiateViewControllerWithIdentifier("modalNav") as! UIViewController 45 | let partialModal: EMPartialModalViewController = EMPartialModalViewController(rootViewController: content, contentHeight: 400) 46 | 47 | presentViewController(partialModal, animated: true) { 48 | println("presenting view controller - done") 49 | } 50 | } 51 | 52 | @IBAction func showModalViewController_2() { 53 | let content: UIViewController = storyboard!.instantiateViewControllerWithIdentifier("modalNav") as! UIViewController 54 | var frame: CGRect = content.view.frame 55 | frame.size.height = 200 56 | content.view.frame = frame 57 | 58 | let partialModal: EMPartialModalViewController = EMPartialModalViewController(rootViewController: content) 59 | 60 | presentViewController(partialModal, animated: true) { 61 | println("presenting view controller - done") 62 | } 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Emad A. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EMPartialModalViewController 2 | 3 | Presents modal view controllers in style, while the height is under your control! 4 | 5 | ![EMPartialModalViewController shot](https://github.com/codeisjoy/EMPartialModalViewController/blob/master/partial_modal.jpg) 6 | 7 | EMPartialModalViewController is a UIViewController subclass which takes a root view controller and present it modally. The height of presented view control is completely controllable. 8 | 9 | ## Usage 10 | 11 | Before using the view controller to show your modals it is necessary to set `View controller-based status bar appearance` in the `Info.plist` of application `YES`. It is needed to change the status bar style when modal view controller is about to show. 12 | 13 | Then just initialise an instance of `EMPartialModalViewController` with a root view controller which would be the content of your modal. 14 | 15 | There is two way to initialise: 16 | 17 | **1. Specify the height directly
`init(rootViewController: UIViewController, contentHeight: CGFloat)`** 18 | 19 | This way the root view controller will be shown with the given height. 20 | 21 | let content: UIViewController = <…> 22 | let partialModal: EMPartialModalViewController = EMPartialModalViewController(rootViewController: content, contentHeight: ) 23 | 24 | **2. Let’s present the view controller with its own height
`init(rootViewController: UIViewController)`** 25 | 26 | This way the root view controller will be shown with the height that its `view` already has. 27 | 28 | let content: UIViewController = <…> 29 | var frame: CGRect = content.view.frame 30 | frame.size.height = 200 31 | content.view.frame = frame 32 | … 33 | let partialModal: EMPartialModalViewController = EMPartialModalViewController(rootViewController: content) 34 | 35 | When you are done with the initialising the modal view controller the only thing should be done is presenting. So, just present that as you do normaly: 36 | 37 | presentViewController(partialModal, animated: true, completion: nil) 38 | 39 | In addition, you can set the property of `contentViewMaxHeight` to indicate the maximum height that the content could have. By default, it has been set `402`. 40 | 41 | ## Install 42 | 43 | Simply add it as a submodule then import `EMPartialModalViewController` folder into your Xcode project. 44 | 45 | git submodule add https://github.com/codeisjoy/EMPartialModalViewController.git 46 | 47 | #### Known issues 48 | 49 | - It is not suitable for iPad. Showing modals in iPad should be completely different. 50 | - It does not support rotation. If rotation happen it may have strange and unpredictable behaviour. So, at the moment just lock your app to support portrait mode only. 51 | - You can not set `false` for `animated` when you are about to presenting view controller. This causes app crash. 52 | 53 | presentViewController(partialModal, animated: false, completion: nil) -------------------------------------------------------------------------------- /partial_modal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeisjoy/EMPartialModalViewController/3e4620240d29c355c4ea0748ce4b65c75203a29e/partial_modal.jpg --------------------------------------------------------------------------------