├── CustomAlertViewDemo.xcodeproj └── project.pbxproj ├── CustomAlertViewDemo ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Base.lproj │ └── Main.storyboard ├── CustomAlertViewController.swift ├── CustomAlertViewController.xib ├── CustomAlertViewDemo-Info.plist ├── CustomAlertViewTransitioner.swift ├── LaunchScreen.storyboard ├── ViewController.swift └── smileybignew.png └── README.md /CustomAlertViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3232610B1B6AD23E0008EC29 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3232610A1B6AD23E0008EC29 /* LaunchScreen.storyboard */; }; 11 | 3232610D1B6AD25F0008EC29 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3232610C1B6AD25F0008EC29 /* AppDelegate.swift */; }; 12 | 3232610F1B6AD2970008EC29 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3232610E1B6AD2970008EC29 /* ViewController.swift */; }; 13 | 3276A7D0197A040B00568EFF /* CustomAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3276A7CF197A040B00568EFF /* CustomAlertViewController.swift */; }; 14 | 3276A7D2197A066200568EFF /* CustomAlertViewTransitioner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3276A7D1197A066200568EFF /* CustomAlertViewTransitioner.swift */; }; 15 | 32CCF134187DCEA4009ED52A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32CCF132187DCEA4009ED52A /* Main.storyboard */; }; 16 | 32CCF139187DCEA4009ED52A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32CCF138187DCEA4009ED52A /* Assets.xcassets */; }; 17 | 32CCF156187DCF0E009ED52A /* smileybignew.png in Resources */ = {isa = PBXBuildFile; fileRef = 32CCF155187DCF0E009ED52A /* smileybignew.png */; }; 18 | 32CCF15B187DCFA6009ED52A /* CustomAlertViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32CCF159187DCFA6009ED52A /* CustomAlertViewController.xib */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 3232610A1B6AD23E0008EC29 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 23 | 3232610C1B6AD25F0008EC29 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 3232610E1B6AD2970008EC29 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | 3276A7CF197A040B00568EFF /* CustomAlertViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAlertViewController.swift; sourceTree = ""; }; 26 | 3276A7D1197A066200568EFF /* CustomAlertViewTransitioner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAlertViewTransitioner.swift; sourceTree = ""; }; 27 | 32CCF11D187DCEA4009ED52A /* CustomAlertViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CustomAlertViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 32CCF128187DCEA4009ED52A /* CustomAlertViewDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CustomAlertViewDemo-Info.plist"; sourceTree = ""; }; 29 | 32CCF133187DCEA4009ED52A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 32CCF138187DCEA4009ED52A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 32CCF155187DCF0E009ED52A /* smileybignew.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = smileybignew.png; sourceTree = ""; }; 32 | 32CCF159187DCFA6009ED52A /* CustomAlertViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomAlertViewController.xib; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 32CCF11A187DCEA4009ED52A /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 32CCF114187DCEA4009ED52A = { 47 | isa = PBXGroup; 48 | children = ( 49 | 32CCF126187DCEA4009ED52A /* CustomAlertViewDemo */, 50 | 32CCF11E187DCEA4009ED52A /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 32CCF11E187DCEA4009ED52A /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 32CCF11D187DCEA4009ED52A /* CustomAlertViewDemo.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 32CCF126187DCEA4009ED52A /* CustomAlertViewDemo */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 32CCF132187DCEA4009ED52A /* Main.storyboard */, 66 | 3232610C1B6AD25F0008EC29 /* AppDelegate.swift */, 67 | 3232610E1B6AD2970008EC29 /* ViewController.swift */, 68 | 3276A7CF197A040B00568EFF /* CustomAlertViewController.swift */, 69 | 32CCF159187DCFA6009ED52A /* CustomAlertViewController.xib */, 70 | 3276A7D1197A066200568EFF /* CustomAlertViewTransitioner.swift */, 71 | 32CCF155187DCF0E009ED52A /* smileybignew.png */, 72 | 32CCF138187DCEA4009ED52A /* Assets.xcassets */, 73 | 3232610A1B6AD23E0008EC29 /* LaunchScreen.storyboard */, 74 | 32CCF128187DCEA4009ED52A /* CustomAlertViewDemo-Info.plist */, 75 | ); 76 | path = CustomAlertViewDemo; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 32CCF11C187DCEA4009ED52A /* CustomAlertViewDemo */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 32CCF14F187DCEA4009ED52A /* Build configuration list for PBXNativeTarget "CustomAlertViewDemo" */; 85 | buildPhases = ( 86 | 32CCF119187DCEA4009ED52A /* Sources */, 87 | 32CCF11A187DCEA4009ED52A /* Frameworks */, 88 | 32CCF11B187DCEA4009ED52A /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = CustomAlertViewDemo; 95 | productName = CustomAlertViewDemo; 96 | productReference = 32CCF11D187DCEA4009ED52A /* CustomAlertViewDemo.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 32CCF115187DCEA4009ED52A /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | LastSwiftUpdateCheck = 0700; 106 | LastUpgradeCheck = 0510; 107 | ORGANIZATIONNAME = "Matt Neuburg"; 108 | TargetAttributes = { 109 | 32CCF11C187DCEA4009ED52A = { 110 | LastSwiftMigration = 1010; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 32CCF118187DCEA4009ED52A /* Build configuration list for PBXProject "CustomAlertViewDemo" */; 115 | compatibilityVersion = "Xcode 3.2"; 116 | developmentRegion = English; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 32CCF114187DCEA4009ED52A; 123 | productRefGroup = 32CCF11E187DCEA4009ED52A /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 32CCF11C187DCEA4009ED52A /* CustomAlertViewDemo */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 32CCF11B187DCEA4009ED52A /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | 32CCF15B187DCFA6009ED52A /* CustomAlertViewController.xib in Resources */, 138 | 32CCF139187DCEA4009ED52A /* Assets.xcassets in Resources */, 139 | 32CCF156187DCF0E009ED52A /* smileybignew.png in Resources */, 140 | 3232610B1B6AD23E0008EC29 /* LaunchScreen.storyboard in Resources */, 141 | 32CCF134187DCEA4009ED52A /* Main.storyboard in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 32CCF119187DCEA4009ED52A /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 3232610D1B6AD25F0008EC29 /* AppDelegate.swift in Sources */, 153 | 3276A7D0197A040B00568EFF /* CustomAlertViewController.swift in Sources */, 154 | 3232610F1B6AD2970008EC29 /* ViewController.swift in Sources */, 155 | 3276A7D2197A066200568EFF /* CustomAlertViewTransitioner.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 32CCF132187DCEA4009ED52A /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 32CCF133187DCEA4009ED52A /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | 32CCF14D187DCEA4009ED52A /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 179 | CLANG_CXX_LIBRARY = "libc++"; 180 | CLANG_ENABLE_MODULES = YES; 181 | CLANG_ENABLE_OBJC_ARC = YES; 182 | CLANG_WARN_BOOL_CONVERSION = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 185 | CLANG_WARN_EMPTY_BODY = YES; 186 | CLANG_WARN_ENUM_CONVERSION = YES; 187 | CLANG_WARN_INT_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 191 | COPY_PHASE_STRIP = NO; 192 | GCC_C_LANGUAGE_STANDARD = gnu99; 193 | GCC_DYNAMIC_NO_PIC = NO; 194 | GCC_OPTIMIZATION_LEVEL = 0; 195 | GCC_PREPROCESSOR_DEFINITIONS = ( 196 | "DEBUG=1", 197 | "$(inherited)", 198 | ); 199 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 200 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 201 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 202 | GCC_WARN_UNDECLARED_SELECTOR = YES; 203 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 204 | GCC_WARN_UNUSED_FUNCTION = YES; 205 | GCC_WARN_UNUSED_VARIABLE = YES; 206 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 207 | ONLY_ACTIVE_ARCH = YES; 208 | SDKROOT = iphoneos; 209 | }; 210 | name = Debug; 211 | }; 212 | 32CCF14E187DCEA4009ED52A /* Release */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 217 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 218 | CLANG_CXX_LIBRARY = "libc++"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_WARN_BOOL_CONVERSION = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_EMPTY_BODY = YES; 225 | CLANG_WARN_ENUM_CONVERSION = YES; 226 | CLANG_WARN_INT_CONVERSION = YES; 227 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 228 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 229 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 230 | COPY_PHASE_STRIP = YES; 231 | ENABLE_NS_ASSERTIONS = NO; 232 | GCC_C_LANGUAGE_STANDARD = gnu99; 233 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 234 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 235 | GCC_WARN_UNDECLARED_SELECTOR = YES; 236 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 237 | GCC_WARN_UNUSED_FUNCTION = YES; 238 | GCC_WARN_UNUSED_VARIABLE = YES; 239 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 240 | SDKROOT = iphoneos; 241 | VALIDATE_PRODUCT = YES; 242 | }; 243 | name = Release; 244 | }; 245 | 32CCF150187DCEA4009ED52A /* Debug */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 249 | CLANG_ENABLE_MODULES = YES; 250 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 251 | GCC_PREFIX_HEADER = "CustomAlertViewDemo/CustomAlertViewDemo-Prefix.pch"; 252 | INFOPLIST_FILE = "CustomAlertViewDemo/CustomAlertViewDemo-Info.plist"; 253 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 254 | PRODUCT_NAME = "$(TARGET_NAME)"; 255 | SWIFT_OBJC_BRIDGING_HEADER = ""; 256 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 257 | SWIFT_VERSION = 4.2; 258 | WRAPPER_EXTENSION = app; 259 | }; 260 | name = Debug; 261 | }; 262 | 32CCF151187DCEA4009ED52A /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 266 | CLANG_ENABLE_MODULES = YES; 267 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 268 | GCC_PREFIX_HEADER = "CustomAlertViewDemo/CustomAlertViewDemo-Prefix.pch"; 269 | INFOPLIST_FILE = "CustomAlertViewDemo/CustomAlertViewDemo-Info.plist"; 270 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 271 | PRODUCT_NAME = "$(TARGET_NAME)"; 272 | SWIFT_OBJC_BRIDGING_HEADER = ""; 273 | SWIFT_VERSION = 4.2; 274 | WRAPPER_EXTENSION = app; 275 | }; 276 | name = Release; 277 | }; 278 | /* End XCBuildConfiguration section */ 279 | 280 | /* Begin XCConfigurationList section */ 281 | 32CCF118187DCEA4009ED52A /* Build configuration list for PBXProject "CustomAlertViewDemo" */ = { 282 | isa = XCConfigurationList; 283 | buildConfigurations = ( 284 | 32CCF14D187DCEA4009ED52A /* Debug */, 285 | 32CCF14E187DCEA4009ED52A /* Release */, 286 | ); 287 | defaultConfigurationIsVisible = 0; 288 | defaultConfigurationName = Release; 289 | }; 290 | 32CCF14F187DCEA4009ED52A /* Build configuration list for PBXNativeTarget "CustomAlertViewDemo" */ = { 291 | isa = XCConfigurationList; 292 | buildConfigurations = ( 293 | 32CCF150187DCEA4009ED52A /* Debug */, 294 | 32CCF151187DCEA4009ED52A /* Release */, 295 | ); 296 | defaultConfigurationIsVisible = 0; 297 | defaultConfigurationName = Release; 298 | }; 299 | /* End XCConfigurationList section */ 300 | }; 301 | rootObject = 32CCF115187DCEA4009ED52A /* Project object */; 302 | } 303 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate : UIResponder, UIApplicationDelegate { 5 | var window : UIWindow? 6 | 7 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { 8 | return true 9 | } 10 | 11 | } 12 | 13 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/Assets.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 | } -------------------------------------------------------------------------------- /CustomAlertViewDemo/Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /CustomAlertViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/CustomAlertViewController.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | 4 | class CustomAlertViewController : UIViewController { 5 | let transitioner = CAVTransitioner() 6 | 7 | override init(nibName: String?, bundle: Bundle?) { 8 | super.init(nibName: nibName, bundle: bundle) 9 | self.modalPresentationStyle = .custom 10 | self.transitioningDelegate = self.transitioner 11 | } 12 | 13 | convenience init() { 14 | self.init(nibName:nil, bundle:nil) 15 | } 16 | 17 | required init?(coder: NSCoder) { 18 | fatalError("NSCoding not supported") 19 | } 20 | 21 | @IBAction func doDismiss(_ sender:Any) { 22 | self.presentingViewController?.dismiss(animated: true) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/CustomAlertViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/CustomAlertViewDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.neuburg.matt.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/CustomAlertViewTransitioner.swift: -------------------------------------------------------------------------------- 1 | 2 | import UIKit 3 | import QuartzCore 4 | 5 | class CAVTransitioner : NSObject, UIViewControllerTransitioningDelegate { 6 | func presentationController( 7 | forPresented presented: UIViewController, 8 | presenting: UIViewController?, 9 | source: UIViewController) 10 | -> UIPresentationController? { 11 | return MyPresentationController( 12 | presentedViewController: presented, presenting: presenting) 13 | } 14 | } 15 | 16 | class MyPresentationController : UIPresentationController { 17 | 18 | func decorateView(_ v:UIView) { 19 | // iOS 8 doesn't have this 20 | // v.layer.borderColor = UIColor.blue.cgColor 21 | // v.layer.borderWidth = 2 22 | v.layer.cornerRadius = 8 23 | 24 | let m1 = UIInterpolatingMotionEffect( 25 | keyPath:"center.x", type:.tiltAlongHorizontalAxis) 26 | m1.maximumRelativeValue = 10.0 27 | m1.minimumRelativeValue = -10.0 28 | let m2 = UIInterpolatingMotionEffect( 29 | keyPath:"center.y", type:.tiltAlongVerticalAxis) 30 | m2.maximumRelativeValue = 10.0 31 | m2.minimumRelativeValue = -10.0 32 | let g = UIMotionEffectGroup() 33 | g.motionEffects = [m1,m2] 34 | v.addMotionEffect(g) 35 | } 36 | 37 | override func presentationTransitionWillBegin() { 38 | self.decorateView(self.presentedView!) 39 | let vc = self.presentingViewController 40 | let v = vc.view! 41 | let con = self.containerView! 42 | let shadow = UIView(frame:con.bounds) 43 | shadow.backgroundColor = UIColor(white:0, alpha:0.4) 44 | shadow.alpha = 0 45 | con.insertSubview(shadow, at: 0) 46 | shadow.autoresizingMask = [.flexibleWidth, .flexibleHeight] 47 | let tc = vc.transitionCoordinator! 48 | tc.animate(alongsideTransition: { _ in 49 | shadow.alpha = 1 50 | }) { _ in 51 | v.tintAdjustmentMode = .dimmed 52 | } 53 | } 54 | 55 | override func dismissalTransitionWillBegin() { 56 | let vc = self.presentingViewController 57 | let v = vc.view! 58 | let con = self.containerView! 59 | let shadow = con.subviews[0] 60 | let tc = vc.transitionCoordinator! 61 | tc.animate(alongsideTransition: { _ in 62 | shadow.alpha = 0 63 | }) { _ in 64 | v.tintAdjustmentMode = .automatic 65 | } 66 | } 67 | 68 | override var frameOfPresentedViewInContainerView : CGRect { 69 | // we want to center the presented view at its "native" size 70 | // I can think of a lot of ways to do this, 71 | // but here we just assume that it *is* its native size 72 | let v = self.presentedView! 73 | let con = self.containerView! 74 | v.center = CGPoint(x: con.bounds.midX, y: con.bounds.midY) 75 | return v.frame.integral 76 | } 77 | 78 | override func containerViewWillLayoutSubviews() { 79 | // deal with future rotation 80 | // again, I can think of more than one approach 81 | let v = self.presentedView! 82 | v.autoresizingMask = [ 83 | .flexibleTopMargin, .flexibleBottomMargin, 84 | .flexibleLeftMargin, .flexibleRightMargin 85 | ] 86 | v.translatesAutoresizingMaskIntoConstraints = true 87 | } 88 | 89 | } 90 | 91 | extension CAVTransitioner { // UIViewControllerTransitioningDelegate 92 | func animationController( 93 | forPresented presented:UIViewController, 94 | presenting: UIViewController, 95 | source: UIViewController) 96 | -> UIViewControllerAnimatedTransitioning? { 97 | return self 98 | } 99 | 100 | func animationController( 101 | forDismissed dismissed: UIViewController) 102 | -> UIViewControllerAnimatedTransitioning? { 103 | return self 104 | } 105 | } 106 | 107 | extension CAVTransitioner : UIViewControllerAnimatedTransitioning { 108 | func transitionDuration( 109 | using transitionContext: UIViewControllerContextTransitioning?) 110 | -> TimeInterval { 111 | return 0.25 112 | } 113 | 114 | func animateTransition( 115 | using transitionContext: UIViewControllerContextTransitioning) { 116 | 117 | let con = transitionContext.containerView 118 | 119 | let v1 = transitionContext.view(forKey: .from) 120 | let v2 = transitionContext.view(forKey: .to) 121 | 122 | // we are using the same object (self) as animation controller 123 | // for both presentation and dismissal 124 | // so we have to distinguish the two cases 125 | 126 | if let v2 = v2 { // presenting 127 | con.addSubview(v2) 128 | let scale = CGAffineTransform(scaleX: 1.6, y: 1.6) 129 | v2.transform = scale 130 | v2.alpha = 0 131 | UIView.animate(withDuration: 0.25, animations: { 132 | v2.alpha = 1 133 | v2.transform = .identity 134 | }) { _ in 135 | transitionContext.completeTransition(true) 136 | } 137 | } else if let v1 = v1 { // dismissing 138 | UIView.animate(withDuration: 0.25, animations: { 139 | v1.alpha = 0 140 | }) { _ in 141 | transitionContext.completeTransition(true) 142 | } 143 | } 144 | 145 | } 146 | 147 | } 148 | 149 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class ViewController: UIViewController { 4 | 5 | @IBAction func doButton (_ sender:Any) { 6 | let vc = CustomAlertViewController() 7 | self.present(vc, animated: true) 8 | } 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /CustomAlertViewDemo/smileybignew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattneub/custom-alert-view-iOS7/59f37dcd8957abe5282ccddc6a6dafc1e16bd1c3/CustomAlertViewDemo/smileybignew.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | custom-alert-view-iOS7 2 | ====================== 3 | 4 | Demonstrates how to create a small presented view that hovers in front of the interface like a UIAlertView. 5 | 6 | Originally created in association with this tutorial article: 7 | 8 | In iOS 8, the architecture for customizing presented view controllers changed very greatly from iOS 7, and the project was reorganized accordingly. For the earlier iOS 7 version, checkout commit 7410850. 9 | 10 | Now updated to Swift 3 and 4. 11 | 12 | ![screenshot](http://www.apeth.com/customAlert.png) 13 | 14 | --------------------------------------------------------------------------------