├── .gitignore ├── Demo.gif ├── Demo ├── iOS8Style-ImagePicker.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── iOS8Style-ImagePicker.xccheckout │ │ └── xcuserdata │ │ │ └── jacobsieradzki.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── jacobsieradzki.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── iOS8Style-ImagePicker.xcscheme │ │ └── xcschememanagement.plist ├── iOS8Style-ImagePicker │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── JSImagePickerViewController.h │ ├── JSImagePickerViewController.m │ ├── JSImagePickerViewController.m.BACKUP.9946.m │ ├── JSImagePickerViewController.m.BASE.9946.m │ ├── JSImagePickerViewController.m.LOCAL.9946.m │ ├── JSImagePickerViewController.m.REMOTE.9946.m │ ├── JSImagePickerViewController.m.orig │ ├── JSViewController.h │ ├── JSViewController.m │ └── main.m └── iOS8Style-ImagePickerTests │ ├── Info.plist │ └── iOS8Style_ImagePickerTests.m ├── JSImagePickerController Source ├── JSImagePickerViewController.h └── JSImagePickerViewController.m ├── LICENSE ├── README.md └── Screenshots └── imagePicker1.png /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacobsieradzki/JSImagePickerController/099752cf30bb8e7d5f048d978d3f421ece5a7c88/.gitignore -------------------------------------------------------------------------------- /Demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacobsieradzki/JSImagePickerController/099752cf30bb8e7d5f048d978d3f421ece5a7c88/Demo.gif -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3162124A1A604EFE00E9962D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 316212491A604EFE00E9962D /* main.m */; }; 11 | 3162124D1A604EFE00E9962D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3162124C1A604EFE00E9962D /* AppDelegate.m */; }; 12 | 316212531A604EFE00E9962D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 316212511A604EFE00E9962D /* Main.storyboard */; }; 13 | 316212551A604EFE00E9962D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 316212541A604EFE00E9962D /* Images.xcassets */; }; 14 | 316212581A604EFE00E9962D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 316212561A604EFE00E9962D /* LaunchScreen.xib */; }; 15 | 316212641A604EFE00E9962D /* iOS8Style_ImagePickerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 316212631A604EFE00E9962D /* iOS8Style_ImagePickerTests.m */; }; 16 | 316212721A608A8A00E9962D /* JSImagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 316212711A608A8A00E9962D /* JSImagePickerViewController.m */; }; 17 | 316212751A608F3A00E9962D /* JSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 316212741A608F3A00E9962D /* JSViewController.m */; }; 18 | 31D08A8A1A60A92200DBF1F9 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 31D08A891A60A92200DBF1F9 /* AssetsLibrary.framework */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 3162125E1A604EFE00E9962D /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 3162123C1A604EFE00E9962D /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 316212431A604EFE00E9962D; 27 | remoteInfo = "iOS8Style-ImagePicker"; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 316212441A604EFE00E9962D /* iOS8Style-ImagePicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS8Style-ImagePicker.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 316212481A604EFE00E9962D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 316212491A604EFE00E9962D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 3162124B1A604EFE00E9962D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 36 | 3162124C1A604EFE00E9962D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 37 | 316212521A604EFE00E9962D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | 316212541A604EFE00E9962D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 39 | 316212571A604EFE00E9962D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 40 | 3162125D1A604EFE00E9962D /* iOS8Style-ImagePickerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "iOS8Style-ImagePickerTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 316212621A604EFE00E9962D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 316212631A604EFE00E9962D /* iOS8Style_ImagePickerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iOS8Style_ImagePickerTests.m; sourceTree = ""; }; 43 | 316212701A608A8A00E9962D /* JSImagePickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSImagePickerViewController.h; sourceTree = ""; }; 44 | 316212711A608A8A00E9962D /* JSImagePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSImagePickerViewController.m; sourceTree = ""; }; 45 | 316212731A608F3A00E9962D /* JSViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSViewController.h; sourceTree = ""; }; 46 | 316212741A608F3A00E9962D /* JSViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSViewController.m; sourceTree = ""; }; 47 | 31D08A891A60A92200DBF1F9 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 316212411A604EFE00E9962D /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | 31D08A8A1A60A92200DBF1F9 /* AssetsLibrary.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | 3162125A1A604EFE00E9962D /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 3162123B1A604EFE00E9962D = { 70 | isa = PBXGroup; 71 | children = ( 72 | 316212461A604EFE00E9962D /* iOS8Style-ImagePicker */, 73 | 316212601A604EFE00E9962D /* iOS8Style-ImagePickerTests */, 74 | 316212451A604EFE00E9962D /* Products */, 75 | 31D08A891A60A92200DBF1F9 /* AssetsLibrary.framework */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 316212451A604EFE00E9962D /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 316212441A604EFE00E9962D /* iOS8Style-ImagePicker.app */, 83 | 3162125D1A604EFE00E9962D /* iOS8Style-ImagePickerTests.xctest */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | 316212461A604EFE00E9962D /* iOS8Style-ImagePicker */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 31ADD3D41A618229005090A9 /* JSImagePickerViewController */, 92 | 3162124B1A604EFE00E9962D /* AppDelegate.h */, 93 | 3162124C1A604EFE00E9962D /* AppDelegate.m */, 94 | 316212511A604EFE00E9962D /* Main.storyboard */, 95 | 316212731A608F3A00E9962D /* JSViewController.h */, 96 | 316212741A608F3A00E9962D /* JSViewController.m */, 97 | 316212541A604EFE00E9962D /* Images.xcassets */, 98 | 316212561A604EFE00E9962D /* LaunchScreen.xib */, 99 | 316212471A604EFE00E9962D /* Supporting Files */, 100 | ); 101 | path = "iOS8Style-ImagePicker"; 102 | sourceTree = ""; 103 | }; 104 | 316212471A604EFE00E9962D /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 316212481A604EFE00E9962D /* Info.plist */, 108 | 316212491A604EFE00E9962D /* main.m */, 109 | ); 110 | name = "Supporting Files"; 111 | sourceTree = ""; 112 | }; 113 | 316212601A604EFE00E9962D /* iOS8Style-ImagePickerTests */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 316212631A604EFE00E9962D /* iOS8Style_ImagePickerTests.m */, 117 | 316212611A604EFE00E9962D /* Supporting Files */, 118 | ); 119 | path = "iOS8Style-ImagePickerTests"; 120 | sourceTree = ""; 121 | }; 122 | 316212611A604EFE00E9962D /* Supporting Files */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 316212621A604EFE00E9962D /* Info.plist */, 126 | ); 127 | name = "Supporting Files"; 128 | sourceTree = ""; 129 | }; 130 | 31ADD3D41A618229005090A9 /* JSImagePickerViewController */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 316212701A608A8A00E9962D /* JSImagePickerViewController.h */, 134 | 316212711A608A8A00E9962D /* JSImagePickerViewController.m */, 135 | ); 136 | name = JSImagePickerViewController; 137 | sourceTree = ""; 138 | }; 139 | /* End PBXGroup section */ 140 | 141 | /* Begin PBXNativeTarget section */ 142 | 316212431A604EFE00E9962D /* iOS8Style-ImagePicker */ = { 143 | isa = PBXNativeTarget; 144 | buildConfigurationList = 316212671A604EFE00E9962D /* Build configuration list for PBXNativeTarget "iOS8Style-ImagePicker" */; 145 | buildPhases = ( 146 | 316212401A604EFE00E9962D /* Sources */, 147 | 316212411A604EFE00E9962D /* Frameworks */, 148 | 316212421A604EFE00E9962D /* Resources */, 149 | ); 150 | buildRules = ( 151 | ); 152 | dependencies = ( 153 | ); 154 | name = "iOS8Style-ImagePicker"; 155 | productName = "iOS8Style-ImagePicker"; 156 | productReference = 316212441A604EFE00E9962D /* iOS8Style-ImagePicker.app */; 157 | productType = "com.apple.product-type.application"; 158 | }; 159 | 3162125C1A604EFE00E9962D /* iOS8Style-ImagePickerTests */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = 3162126A1A604EFE00E9962D /* Build configuration list for PBXNativeTarget "iOS8Style-ImagePickerTests" */; 162 | buildPhases = ( 163 | 316212591A604EFE00E9962D /* Sources */, 164 | 3162125A1A604EFE00E9962D /* Frameworks */, 165 | 3162125B1A604EFE00E9962D /* Resources */, 166 | ); 167 | buildRules = ( 168 | ); 169 | dependencies = ( 170 | 3162125F1A604EFE00E9962D /* PBXTargetDependency */, 171 | ); 172 | name = "iOS8Style-ImagePickerTests"; 173 | productName = "iOS8Style-ImagePickerTests"; 174 | productReference = 3162125D1A604EFE00E9962D /* iOS8Style-ImagePickerTests.xctest */; 175 | productType = "com.apple.product-type.bundle.unit-test"; 176 | }; 177 | /* End PBXNativeTarget section */ 178 | 179 | /* Begin PBXProject section */ 180 | 3162123C1A604EFE00E9962D /* Project object */ = { 181 | isa = PBXProject; 182 | attributes = { 183 | LastUpgradeCheck = 0610; 184 | ORGANIZATIONNAME = "Jake Sieradzki"; 185 | TargetAttributes = { 186 | 316212431A604EFE00E9962D = { 187 | CreatedOnToolsVersion = 6.1.1; 188 | }; 189 | 3162125C1A604EFE00E9962D = { 190 | CreatedOnToolsVersion = 6.1.1; 191 | TestTargetID = 316212431A604EFE00E9962D; 192 | }; 193 | }; 194 | }; 195 | buildConfigurationList = 3162123F1A604EFE00E9962D /* Build configuration list for PBXProject "iOS8Style-ImagePicker" */; 196 | compatibilityVersion = "Xcode 3.2"; 197 | developmentRegion = English; 198 | hasScannedForEncodings = 0; 199 | knownRegions = ( 200 | en, 201 | Base, 202 | ); 203 | mainGroup = 3162123B1A604EFE00E9962D; 204 | productRefGroup = 316212451A604EFE00E9962D /* Products */; 205 | projectDirPath = ""; 206 | projectRoot = ""; 207 | targets = ( 208 | 316212431A604EFE00E9962D /* iOS8Style-ImagePicker */, 209 | 3162125C1A604EFE00E9962D /* iOS8Style-ImagePickerTests */, 210 | ); 211 | }; 212 | /* End PBXProject section */ 213 | 214 | /* Begin PBXResourcesBuildPhase section */ 215 | 316212421A604EFE00E9962D /* Resources */ = { 216 | isa = PBXResourcesBuildPhase; 217 | buildActionMask = 2147483647; 218 | files = ( 219 | 316212531A604EFE00E9962D /* Main.storyboard in Resources */, 220 | 316212581A604EFE00E9962D /* LaunchScreen.xib in Resources */, 221 | 316212551A604EFE00E9962D /* Images.xcassets in Resources */, 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | 3162125B1A604EFE00E9962D /* Resources */ = { 226 | isa = PBXResourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | /* End PBXResourcesBuildPhase section */ 233 | 234 | /* Begin PBXSourcesBuildPhase section */ 235 | 316212401A604EFE00E9962D /* Sources */ = { 236 | isa = PBXSourcesBuildPhase; 237 | buildActionMask = 2147483647; 238 | files = ( 239 | 316212751A608F3A00E9962D /* JSViewController.m in Sources */, 240 | 316212721A608A8A00E9962D /* JSImagePickerViewController.m in Sources */, 241 | 3162124D1A604EFE00E9962D /* AppDelegate.m in Sources */, 242 | 3162124A1A604EFE00E9962D /* main.m in Sources */, 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | 316212591A604EFE00E9962D /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 316212641A604EFE00E9962D /* iOS8Style_ImagePickerTests.m in Sources */, 251 | ); 252 | runOnlyForDeploymentPostprocessing = 0; 253 | }; 254 | /* End PBXSourcesBuildPhase section */ 255 | 256 | /* Begin PBXTargetDependency section */ 257 | 3162125F1A604EFE00E9962D /* PBXTargetDependency */ = { 258 | isa = PBXTargetDependency; 259 | target = 316212431A604EFE00E9962D /* iOS8Style-ImagePicker */; 260 | targetProxy = 3162125E1A604EFE00E9962D /* PBXContainerItemProxy */; 261 | }; 262 | /* End PBXTargetDependency section */ 263 | 264 | /* Begin PBXVariantGroup section */ 265 | 316212511A604EFE00E9962D /* Main.storyboard */ = { 266 | isa = PBXVariantGroup; 267 | children = ( 268 | 316212521A604EFE00E9962D /* Base */, 269 | ); 270 | name = Main.storyboard; 271 | sourceTree = ""; 272 | }; 273 | 316212561A604EFE00E9962D /* LaunchScreen.xib */ = { 274 | isa = PBXVariantGroup; 275 | children = ( 276 | 316212571A604EFE00E9962D /* Base */, 277 | ); 278 | name = LaunchScreen.xib; 279 | sourceTree = ""; 280 | }; 281 | /* End PBXVariantGroup section */ 282 | 283 | /* Begin XCBuildConfiguration section */ 284 | 316212651A604EFE00E9962D /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 289 | CLANG_CXX_LIBRARY = "libc++"; 290 | CLANG_ENABLE_MODULES = YES; 291 | CLANG_ENABLE_OBJC_ARC = YES; 292 | CLANG_WARN_BOOL_CONVERSION = YES; 293 | CLANG_WARN_CONSTANT_CONVERSION = YES; 294 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INT_CONVERSION = YES; 298 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 299 | CLANG_WARN_UNREACHABLE_CODE = YES; 300 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 301 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 302 | COPY_PHASE_STRIP = NO; 303 | ENABLE_STRICT_OBJC_MSGSEND = YES; 304 | GCC_C_LANGUAGE_STANDARD = gnu99; 305 | GCC_DYNAMIC_NO_PIC = NO; 306 | GCC_OPTIMIZATION_LEVEL = 0; 307 | GCC_PREPROCESSOR_DEFINITIONS = ( 308 | "DEBUG=1", 309 | "$(inherited)", 310 | ); 311 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 319 | MTL_ENABLE_DEBUG_INFO = YES; 320 | ONLY_ACTIVE_ARCH = YES; 321 | SDKROOT = iphoneos; 322 | }; 323 | name = Debug; 324 | }; 325 | 316212661A604EFE00E9962D /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ALWAYS_SEARCH_USER_PATHS = NO; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 336 | CLANG_WARN_EMPTY_BODY = YES; 337 | CLANG_WARN_ENUM_CONVERSION = YES; 338 | CLANG_WARN_INT_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_UNREACHABLE_CODE = YES; 341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 342 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 343 | COPY_PHASE_STRIP = YES; 344 | ENABLE_NS_ASSERTIONS = NO; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu99; 347 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 348 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 349 | GCC_WARN_UNDECLARED_SELECTOR = YES; 350 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 351 | GCC_WARN_UNUSED_FUNCTION = YES; 352 | GCC_WARN_UNUSED_VARIABLE = YES; 353 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 354 | MTL_ENABLE_DEBUG_INFO = NO; 355 | SDKROOT = iphoneos; 356 | VALIDATE_PRODUCT = YES; 357 | }; 358 | name = Release; 359 | }; 360 | 316212681A604EFE00E9962D /* Debug */ = { 361 | isa = XCBuildConfiguration; 362 | buildSettings = { 363 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 364 | CODE_SIGN_IDENTITY = "iPhone Developer"; 365 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 366 | INFOPLIST_FILE = "iOS8Style-ImagePicker/Info.plist"; 367 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 368 | PRODUCT_NAME = "$(TARGET_NAME)"; 369 | PROVISIONING_PROFILE = ""; 370 | }; 371 | name = Debug; 372 | }; 373 | 316212691A604EFE00E9962D /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 377 | CODE_SIGN_IDENTITY = "iPhone Developer"; 378 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 379 | INFOPLIST_FILE = "iOS8Style-ImagePicker/Info.plist"; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 381 | PRODUCT_NAME = "$(TARGET_NAME)"; 382 | PROVISIONING_PROFILE = ""; 383 | }; 384 | name = Release; 385 | }; 386 | 3162126B1A604EFE00E9962D /* Debug */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | BUNDLE_LOADER = "$(TEST_HOST)"; 390 | FRAMEWORK_SEARCH_PATHS = ( 391 | "$(SDKROOT)/Developer/Library/Frameworks", 392 | "$(inherited)", 393 | ); 394 | GCC_PREPROCESSOR_DEFINITIONS = ( 395 | "DEBUG=1", 396 | "$(inherited)", 397 | ); 398 | INFOPLIST_FILE = "iOS8Style-ImagePickerTests/Info.plist"; 399 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 400 | PRODUCT_NAME = "$(TARGET_NAME)"; 401 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOS8Style-ImagePicker.app/iOS8Style-ImagePicker"; 402 | }; 403 | name = Debug; 404 | }; 405 | 3162126C1A604EFE00E9962D /* Release */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | BUNDLE_LOADER = "$(TEST_HOST)"; 409 | FRAMEWORK_SEARCH_PATHS = ( 410 | "$(SDKROOT)/Developer/Library/Frameworks", 411 | "$(inherited)", 412 | ); 413 | INFOPLIST_FILE = "iOS8Style-ImagePickerTests/Info.plist"; 414 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOS8Style-ImagePicker.app/iOS8Style-ImagePicker"; 417 | }; 418 | name = Release; 419 | }; 420 | /* End XCBuildConfiguration section */ 421 | 422 | /* Begin XCConfigurationList section */ 423 | 3162123F1A604EFE00E9962D /* Build configuration list for PBXProject "iOS8Style-ImagePicker" */ = { 424 | isa = XCConfigurationList; 425 | buildConfigurations = ( 426 | 316212651A604EFE00E9962D /* Debug */, 427 | 316212661A604EFE00E9962D /* Release */, 428 | ); 429 | defaultConfigurationIsVisible = 0; 430 | defaultConfigurationName = Release; 431 | }; 432 | 316212671A604EFE00E9962D /* Build configuration list for PBXNativeTarget "iOS8Style-ImagePicker" */ = { 433 | isa = XCConfigurationList; 434 | buildConfigurations = ( 435 | 316212681A604EFE00E9962D /* Debug */, 436 | 316212691A604EFE00E9962D /* Release */, 437 | ); 438 | defaultConfigurationIsVisible = 0; 439 | defaultConfigurationName = Release; 440 | }; 441 | 3162126A1A604EFE00E9962D /* Build configuration list for PBXNativeTarget "iOS8Style-ImagePickerTests" */ = { 442 | isa = XCConfigurationList; 443 | buildConfigurations = ( 444 | 3162126B1A604EFE00E9962D /* Debug */, 445 | 3162126C1A604EFE00E9962D /* Release */, 446 | ); 447 | defaultConfigurationIsVisible = 0; 448 | defaultConfigurationName = Release; 449 | }; 450 | /* End XCConfigurationList section */ 451 | }; 452 | rootObject = 3162123C1A604EFE00E9962D /* Project object */; 453 | } 454 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/project.xcworkspace/xcshareddata/iOS8Style-ImagePicker.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 74705DCA-663B-4AFD-8F0F-1C8FF31EC099 9 | IDESourceControlProjectName 10 | iOS8Style-ImagePicker 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 3E4A22BB0E1538646EDC4F56D67F26B86FF9EA86 14 | https://github.com/jacobsieradzki/JSImagePickerController.git 15 | 16 | IDESourceControlProjectPath 17 | Demo/iOS8Style-ImagePicker.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 3E4A22BB0E1538646EDC4F56D67F26B86FF9EA86 21 | ../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/jacobsieradzki/JSImagePickerController.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 3E4A22BB0E1538646EDC4F56D67F26B86FF9EA86 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 3E4A22BB0E1538646EDC4F56D67F26B86FF9EA86 36 | IDESourceControlWCCName 37 | JSImagePickerController 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/project.xcworkspace/xcuserdata/jacobsieradzki.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacobsieradzki/JSImagePickerController/099752cf30bb8e7d5f048d978d3f421ece5a7c88/Demo/iOS8Style-ImagePicker.xcodeproj/project.xcworkspace/xcuserdata/jacobsieradzki.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/xcuserdata/jacobsieradzki.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/xcuserdata/jacobsieradzki.xcuserdatad/xcschemes/iOS8Style-ImagePicker.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 89 | 90 | 91 | 92 | 98 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker.xcodeproj/xcuserdata/jacobsieradzki.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | iOS8Style-ImagePicker.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 316212431A604EFE00E9962D 16 | 17 | primary 18 | 19 | 20 | 3162125C1A604EFE00E9962D 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 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 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/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 | } -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.Sieradzki.$(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 | 38 | 39 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.h 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class JSImagePickerViewController ; 12 | @protocol JSImagePickerViewControllerDelegate 13 | 14 | - (void)imagePicker:(JSImagePickerViewController *)imagePicker didSelectImage:(UIImage *)image; 15 | 16 | @optional 17 | - (void)imagePickerDidOpen; 18 | - (void)imagePickerWillOpen; 19 | 20 | - (void)imagePickerWillClose; 21 | - (void)imagePickerDidClose; 22 | 23 | - (void)imagePickerDidCancel; 24 | 25 | @end 26 | 27 | @interface JSImagePickerViewController : UIViewController { 28 | __unsafe_unretained id delegate; 29 | } 30 | 31 | @property (nonatomic, assign) id delegate; 32 | 33 | @property (readonly) bool isVisible; 34 | - (void)setAnimationTime:(NSTimeInterval)animationTime; 35 | 36 | @property (nonatomic, strong) UICollectionView *collectionView; 37 | @property (nonatomic, strong) UIButton *photoLibraryBtn; 38 | @property (nonatomic, strong) UIButton *cameraBtn; 39 | @property (nonatomic, strong) UIButton *cancelBtn; 40 | 41 | - (void)showImagePickerInController:(UIViewController *)controller; 42 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated; 43 | - (void)dismiss; 44 | - (void)dismissAnimated:(BOOL)animated; 45 | 46 | @end 47 | 48 | 49 | 50 | 51 | 52 | @interface TransitionDelegate : NSObject 53 | 54 | @end 55 | 56 | 57 | 58 | 59 | 60 | 61 | @interface AnimatedTransitioning : NSObject 62 | 63 | @property (nonatomic, assign) BOOL isPresenting; 64 | 65 | @end 66 | 67 | 68 | 69 | 70 | @interface JSPhotoCell : UICollectionViewCell 71 | 72 | @end 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 22 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 23 | 24 | @property (readwrite) bool isVisible; 25 | @property (readwrite) bool haveCamera; 26 | @property (nonatomic) NSTimeInterval animationTime; 27 | 28 | @property (nonatomic, strong) UIViewController *targetController; 29 | @property (nonatomic, strong) UIWindow *window; 30 | 31 | @property (nonatomic, strong) UIView *backgroundView; 32 | @property (nonatomic, strong) UIView *imagePickerView; 33 | 34 | @property (nonatomic) CGRect imagePickerFrame; 35 | @property (nonatomic) CGRect hiddenFrame; 36 | 37 | @property (nonatomic) TransitionDelegate *transitionController; 38 | 39 | @property (nonatomic, strong) NSMutableArray *assets; 40 | 41 | @end 42 | 43 | @implementation JSImagePickerViewController 44 | 45 | @synthesize delegate; 46 | @synthesize transitionController; 47 | 48 | - (id)init { 49 | self = [super init]; 50 | if (self) { 51 | self.assets = [[NSMutableArray alloc] init]; 52 | [self setupView]; 53 | } 54 | return self; 55 | } 56 | 57 | - (void)setupView { 58 | self.view.backgroundColor = [UIColor clearColor]; 59 | self.window = [UIApplication sharedApplication].keyWindow; 60 | 61 | self.haveCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; 62 | CGFloat localImagePickerHeight = imagePickerHeight; 63 | if (!self.haveCamera) { 64 | localImagePickerHeight -= 47.0f; 65 | } 66 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-localImagePickerHeight, [UIScreen mainScreen].bounds.size.width, localImagePickerHeight); 67 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, localImagePickerHeight); 68 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 69 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 70 | 71 | 72 | 73 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 74 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 75 | self.backgroundView.alpha = 0; 76 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 77 | self.backgroundView.userInteractionEnabled = YES; 78 | [self.backgroundView addGestureRecognizer:dismissTap]; 79 | 80 | 81 | 82 | self.animationTime = 0.2; 83 | 84 | [self.window addSubview:self.backgroundView]; 85 | [self.window addSubview:self.imagePickerView]; 86 | 87 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 88 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 89 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 90 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 91 | 92 | [self.imagePickerView addSubview:btn]; 93 | 94 | [self imagePickerViewSetup]; 95 | [self getCameraRollImages]; 96 | } 97 | 98 | - (void)imagePickerViewSetup { 99 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 100 | 101 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth-7-7, 122); 102 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 103 | const CGRect cameraBtnFrame = CGRectMake(0, self.haveCamera ? 196 : 0, screenWidth, 30); 104 | const CGRect cancelBtnFrame = CGRectMake(0, self.haveCamera ? 242 : 196, screenWidth, 30); 105 | 106 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 107 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 108 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 109 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 110 | self.collectionView.showsHorizontalScrollIndicator = NO; 111 | self.collectionView.showsVerticalScrollIndicator = NO; 112 | self.collectionView.delegate = self; 113 | self.collectionView.dataSource = self; 114 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 115 | 116 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 117 | 118 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 119 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 120 | self.photoLibraryBtn.titleLabel.font = btnFont; 121 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 122 | 123 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 124 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 125 | self.cameraBtn.titleLabel.font = btnFont; 126 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 127 | self.cameraBtn.hidden = !self.haveCamera; 128 | 129 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 130 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 131 | self.cancelBtn.titleLabel.font = btnFont; 132 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 133 | 134 | for (UIButton *btn in @[self.photoLibraryBtn, self.cameraBtn, self.cancelBtn]) { 135 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 136 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 137 | } 138 | 139 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 140 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 141 | [self.imagePickerView addSubview:separator1]; 142 | 143 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth-25, 1)]; 144 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 145 | [self.imagePickerView addSubview:separator2]; 146 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth-25, 1)]; 147 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 148 | [self.imagePickerView addSubview:separator3]; 149 | 150 | [self.imagePickerView addSubview:self.collectionView]; 151 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 152 | [self.imagePickerView addSubview:self.cameraBtn]; 153 | [self.imagePickerView addSubview:self.cancelBtn]; 154 | } 155 | 156 | #pragma mark - Collection view 157 | 158 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 159 | return 1; 160 | } 161 | 162 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 163 | return MIN(20, self.assets.count); 164 | } 165 | 166 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 167 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 168 | 169 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 170 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 171 | imageView.clipsToBounds = YES; 172 | imageView.contentMode = UIViewContentModeScaleAspectFill; 173 | [cell addSubview:imageView]; 174 | 175 | return cell; 176 | } 177 | 178 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 179 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 180 | 181 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 182 | ALAssetRepresentation* representation = [asset defaultRepresentation]; 183 | UIImageOrientation orientation = UIImageOrientationUp; 184 | NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"]; 185 | if (orientationValue != nil) { 186 | orientation = [orientationValue intValue]; 187 | } 188 | 189 | CGFloat scale = 1; 190 | UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage] 191 | scale:scale orientation:orientation]; 192 | 193 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 194 | [delegate imagePicker:self didSelectImage:image]; 195 | } 196 | 197 | [self dismissAnimated:YES]; 198 | } 199 | 200 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 201 | return CGSizeMake(170, 114); 202 | } 203 | 204 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { 205 | return 10.0f; 206 | } 207 | 208 | #pragma mark - Image library 209 | 210 | 211 | - (void)getCameraRollImages { 212 | _assets = [@[] mutableCopy]; 213 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 214 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 215 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 216 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 217 | if(result) 218 | { 219 | [tmpAssets addObject:result]; 220 | } 221 | }]; 222 | 223 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 224 | if (result) { 225 | [self.assets addObject:result]; 226 | } 227 | }; 228 | 229 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 230 | [group setAssetsFilter:onlyPhotosFilter]; 231 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 232 | 233 | [self.collectionView reloadData]; 234 | } failureBlock:^(NSError *error) { 235 | NSLog(@"Error loading images %@", error); 236 | }]; 237 | } 238 | 239 | + (ALAssetsLibrary *)defaultAssetsLibrary 240 | { 241 | static dispatch_once_t pred = 0; 242 | static ALAssetsLibrary *library = nil; 243 | dispatch_once(&pred, ^{ 244 | library = [[ALAssetsLibrary alloc] init]; 245 | }); 246 | return library; 247 | } 248 | 249 | #pragma mark - Image picker 250 | 251 | - (void)takePhotoWasPressed { 252 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 253 | 254 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 255 | message:@"Device has no camera" 256 | delegate:nil 257 | cancelButtonTitle:@"OK" 258 | otherButtonTitles: nil]; 259 | 260 | [myAlertView show]; 261 | 262 | } else { 263 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 264 | picker.delegate = self; 265 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 266 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 267 | 268 | [self presentViewController:picker animated:YES completion:nil]; 269 | } 270 | } 271 | 272 | - (void)selectFromLibraryWasPressed { 273 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 274 | picker.delegate = self; 275 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 276 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 277 | 278 | [self presentViewController:picker animated:YES completion:nil]; 279 | } 280 | 281 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 282 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 283 | 284 | [picker dismissViewControllerAnimated:YES completion:^{ 285 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 286 | [delegate imagePicker:self didSelectImage:chosenImage]; 287 | } 288 | [self dismissAnimated:YES]; 289 | }]; 290 | } 291 | 292 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 293 | [picker dismissViewControllerAnimated:YES completion:nil]; 294 | } 295 | 296 | #pragma mark - Show 297 | 298 | - (void)showImagePickerInController:(UIViewController *)controller { 299 | [self showImagePickerInController:controller animated:YES]; 300 | } 301 | 302 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated { 303 | if (self.isVisible != YES) { 304 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 305 | [delegate imagePickerWillOpen]; 306 | } 307 | self.isVisible = YES; 308 | 309 | [self setTransitioningDelegate:transitionController]; 310 | if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { 311 | self.modalPresentationStyle = UIModalPresentationOverCurrentContext; 312 | } else { 313 | self.modalPresentationStyle = UIModalPresentationCustom; 314 | } 315 | [controller presentViewController:self animated:NO completion:nil]; 316 | 317 | if (animated) { 318 | [UIView animateWithDuration:self.animationTime 319 | delay:0 320 | options:UIViewAnimationOptionCurveLinear 321 | animations:^{ 322 | [self.imagePickerView setFrame:self.imagePickerFrame]; 323 | [self.backgroundView setAlpha:1]; 324 | } 325 | completion:^(BOOL finished) { 326 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 327 | [delegate imagePickerDidOpen]; 328 | } 329 | }]; 330 | } else { 331 | [self.imagePickerView setFrame:self.imagePickerFrame]; 332 | [self.backgroundView setAlpha:0]; 333 | } 334 | } 335 | } 336 | 337 | #pragma mark - Dismiss 338 | 339 | - (void)dismiss { 340 | [self dismissAnimated:YES]; 341 | } 342 | 343 | - (void)dismissAnimated:(BOOL)animated { 344 | if (self.isVisible == YES) { 345 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 346 | [delegate imagePickerWillClose]; 347 | } 348 | if (animated) { 349 | [UIView animateWithDuration:self.animationTime 350 | delay:0 351 | options:UIViewAnimationOptionCurveEaseIn 352 | animations:^{ 353 | [self.imagePickerView setFrame:self.hiddenFrame]; 354 | [self.backgroundView setAlpha:0]; 355 | } 356 | completion:^(BOOL finished) { 357 | [self.imagePickerView removeFromSuperview]; 358 | [self.backgroundView removeFromSuperview]; 359 | [self dismissViewControllerAnimated:NO completion:nil]; 360 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 361 | [delegate imagePickerDidClose]; 362 | } 363 | }]; 364 | } else { 365 | [self.imagePickerView setFrame:self.imagePickerFrame]; 366 | [self.backgroundView setAlpha:0]; 367 | } 368 | 369 | // Set everything to nil 370 | } 371 | } 372 | 373 | @end 374 | 375 | 376 | 377 | #pragma mark - TransitionDelegate - 378 | @implementation TransitionDelegate 379 | 380 | - (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 381 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 382 | controller.isPresenting = YES; 383 | return controller; 384 | } 385 | 386 | @end 387 | 388 | 389 | 390 | 391 | #pragma mark - AnimatedTransitioning - 392 | @implementation AnimatedTransitioning 393 | 394 | - (NSTimeInterval)transitionDuration:(id )transitionContext { 395 | return 0.25f; 396 | } 397 | 398 | - (void)animateTransition:(id )transitionContext { 399 | UIView *inView = [transitionContext containerView]; 400 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 401 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 402 | 403 | [inView addSubview:toVC.view]; 404 | 405 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 406 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 407 | 408 | [UIView animateWithDuration:0.25f 409 | animations:^{ 410 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 411 | } 412 | completion:^(BOOL finished) { 413 | [transitionContext completeTransition:YES]; 414 | }]; 415 | } 416 | 417 | 418 | @end 419 | 420 | 421 | 422 | #pragma mark - JSPhotoCell - 423 | @interface JSPhotoCell () 424 | 425 | @end 426 | 427 | @implementation JSPhotoCell 428 | 429 | @end 430 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m.BACKUP.9946.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \ 22 | blue:((float)(rgbValue & 0xFF)) / 255.0 \ 23 | alpha:1.0] 24 | 25 | @property(nonatomic, strong) UIViewController *targetController; 26 | @property(nonatomic, strong) UIWindow *window; 27 | 28 | @property(nonatomic, strong) UIView *backgroundView; 29 | @property(nonatomic, strong) UIView *imagePickerView; 30 | 31 | @property(nonatomic) NSTimeInterval animationTime; 32 | 33 | @property(nonatomic) CGRect imagePickerFrame; 34 | @property(nonatomic) CGRect hiddenFrame; 35 | 36 | @property(nonatomic) TransitionDelegate *transitionController; 37 | 38 | @property(nonatomic, strong) UICollectionView *collectionView; 39 | @property(nonatomic, strong) UIButton *photoLibraryBtn; 40 | @property(nonatomic, strong) UIButton *cameraBtn; 41 | @property(nonatomic, strong) UIButton *cancelBtn; 42 | 43 | @property(nonatomic, strong) NSMutableArray *assets; 44 | 45 | @end 46 | 47 | @implementation JSImagePickerViewController 48 | 49 | @synthesize delegate; 50 | @synthesize transitionController; 51 | 52 | - (id)init 53 | { 54 | self = [super init]; 55 | if (self) { 56 | self.assets = [[NSMutableArray alloc] init]; 57 | [self setupView]; 58 | } 59 | return self; 60 | } 61 | 62 | - (void)setupView 63 | { 64 | self.view.backgroundColor = [UIColor clearColor]; 65 | self.window = [UIApplication sharedApplication].keyWindow; 66 | 67 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 68 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 69 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 70 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 71 | 72 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 73 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 74 | self.backgroundView.alpha = 0; 75 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 76 | self.backgroundView.userInteractionEnabled = YES; 77 | [self.backgroundView addGestureRecognizer:dismissTap]; 78 | 79 | self.animationTime = 0.2; 80 | 81 | [self.window addSubview:self.backgroundView]; 82 | [self.window addSubview:self.imagePickerView]; 83 | 84 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 85 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 86 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 87 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 88 | 89 | [self.imagePickerView addSubview:btn]; 90 | 91 | [self imagePickerViewSetup]; 92 | [self getCameraRollImages]; 93 | } 94 | 95 | - (void)imagePickerViewSetup 96 | { 97 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 98 | 99 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth - 7 - 7, 122); 100 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 101 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 102 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 103 | 104 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 105 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 106 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 107 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 108 | self.collectionView.showsHorizontalScrollIndicator = NO; 109 | self.collectionView.showsVerticalScrollIndicator = NO; 110 | self.collectionView.delegate = self; 111 | self.collectionView.dataSource = self; 112 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 113 | 114 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 115 | 116 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 117 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 118 | self.photoLibraryBtn.titleLabel.font = btnFont; 119 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 120 | 121 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 122 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 123 | self.cameraBtn.titleLabel.font = btnFont; 124 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 125 | 126 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 127 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 128 | self.cancelBtn.titleLabel.font = btnFont; 129 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 130 | 131 | for (UIButton *btn in @[ self.photoLibraryBtn, self.cameraBtn, self.cancelBtn ]) { 132 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 133 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 134 | } 135 | 136 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 137 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 138 | [self.imagePickerView addSubview:separator1]; 139 | 140 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth - 25, 1)]; 141 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 142 | [self.imagePickerView addSubview:separator2]; 143 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth - 25, 1)]; 144 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 145 | [self.imagePickerView addSubview:separator3]; 146 | 147 | [self.imagePickerView addSubview:self.collectionView]; 148 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 149 | [self.imagePickerView addSubview:self.cameraBtn]; 150 | [self.imagePickerView addSubview:self.cancelBtn]; 151 | } 152 | 153 | #pragma mark - Collection view 154 | 155 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 156 | { 157 | return 1; 158 | } 159 | 160 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 161 | { 162 | return MIN(20, self.assets.count); 163 | } 164 | 165 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 166 | { 167 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 168 | 169 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 170 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 171 | imageView.clipsToBounds = YES; 172 | imageView.contentMode = UIViewContentModeScaleAspectFill; 173 | [cell addSubview:imageView]; 174 | 175 | return cell; 176 | } 177 | 178 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 179 | { 180 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 181 | <<<<<<< HEAD 182 | 183 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 184 | UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; 185 | 186 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 187 | [delegate imagePicker:self didSelectImage:image]; 188 | ======= 189 | 190 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 191 | ALAssetRepresentation* representation = [asset defaultRepresentation]; 192 | UIImageOrientation orientation = UIImageOrientationUp; 193 | NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"]; 194 | if (orientationValue != nil) { 195 | orientation = [orientationValue intValue]; 196 | } 197 | 198 | CGFloat scale = 1; 199 | UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage] 200 | scale:scale orientation:orientation]; 201 | 202 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 203 | [delegate imagePickerDidSelectImage:image]; 204 | >>>>>>> 53567d0f0ff945d610e0d646003c2030aa1b09b5 205 | } 206 | 207 | [self dismissAnimated:YES]; 208 | } 209 | 210 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 211 | { 212 | return CGSizeMake(170, 114); 213 | } 214 | 215 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 216 | { 217 | return 10.0f; 218 | } 219 | 220 | #pragma mark - Image library 221 | 222 | - (void)getCameraRollImages 223 | { 224 | _assets = [@[] mutableCopy]; 225 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 226 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 227 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 228 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 229 | if(result) 230 | { 231 | [tmpAssets addObject:result]; 232 | } 233 | }]; 234 | 235 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 236 | if (result) { 237 | [self.assets addObject:result]; 238 | } 239 | }; 240 | 241 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 242 | [group setAssetsFilter:onlyPhotosFilter]; 243 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 244 | 245 | [self.collectionView reloadData]; 246 | } failureBlock:^(NSError *error) { 247 | NSLog(@"Error loading images %@", error); 248 | }]; 249 | } 250 | 251 | + (ALAssetsLibrary *)defaultAssetsLibrary 252 | { 253 | static dispatch_once_t pred = 0; 254 | static ALAssetsLibrary *library = nil; 255 | dispatch_once(&pred, ^{ 256 | library = [[ALAssetsLibrary alloc] init]; 257 | }); 258 | return library; 259 | } 260 | 261 | #pragma mark - Image picker 262 | 263 | - (void)takePhotoWasPressed 264 | { 265 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 266 | 267 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 268 | message:@"Device has no camera" 269 | delegate:nil 270 | cancelButtonTitle:@"OK" 271 | otherButtonTitles:nil]; 272 | 273 | [myAlertView show]; 274 | 275 | } else { 276 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 277 | picker.delegate = self; 278 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 279 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 280 | 281 | [self presentViewController:picker animated:YES completion:nil]; 282 | } 283 | } 284 | 285 | - (void)selectFromLibraryWasPressed 286 | { 287 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 288 | picker.delegate = self; 289 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 290 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 291 | 292 | [self presentViewController:picker animated:YES completion:nil]; 293 | } 294 | 295 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 296 | { 297 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 298 | 299 | [picker dismissViewControllerAnimated:YES completion:^{ 300 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 301 | [delegate imagePicker:self didSelectImage:chosenImage]; 302 | } 303 | [self dismissAnimated:YES]; 304 | }]; 305 | } 306 | 307 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 308 | { 309 | [picker dismissViewControllerAnimated:YES completion:nil]; 310 | } 311 | 312 | #pragma mark - Show 313 | 314 | - (void)showImagePickerInController:(UIViewController *)controller 315 | { 316 | [self showImagePickerInController:controller animated:YES]; 317 | } 318 | 319 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated 320 | { 321 | if (self.isVisible != YES) { 322 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 323 | [delegate imagePickerWillOpen]; 324 | } 325 | self.isVisible = YES; 326 | 327 | [self setTransitioningDelegate:transitionController]; 328 | if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { 329 | self.modalPresentationStyle = UIModalPresentationOverCurrentContext; 330 | } else { 331 | self.modalPresentationStyle = UIModalPresentationCustom; 332 | } 333 | [controller presentViewController:self animated:NO completion:nil]; 334 | 335 | if (animated) { 336 | [UIView animateWithDuration:self.animationTime 337 | delay:0 338 | options:UIViewAnimationOptionCurveLinear 339 | animations:^{ 340 | [self.imagePickerView setFrame:self.imagePickerFrame]; 341 | [self.backgroundView setAlpha:1]; 342 | } 343 | completion:^(BOOL finished) { 344 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 345 | [delegate imagePickerDidOpen]; 346 | } 347 | }]; 348 | } else { 349 | [self.imagePickerView setFrame:self.imagePickerFrame]; 350 | [self.backgroundView setAlpha:0]; 351 | } 352 | } 353 | } 354 | 355 | #pragma mark - Dismiss 356 | 357 | - (void)dismiss 358 | { 359 | [self dismissAnimated:YES]; 360 | } 361 | 362 | - (void)dismissAnimated:(BOOL)animated 363 | { 364 | if (self.isVisible == YES) { 365 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 366 | [delegate imagePickerWillClose]; 367 | } 368 | if (animated) { 369 | [UIView animateWithDuration:self.animationTime 370 | delay:0 371 | options:UIViewAnimationOptionCurveEaseIn 372 | animations:^{ 373 | [self.imagePickerView setFrame:self.hiddenFrame]; 374 | [self.backgroundView setAlpha:0]; 375 | } 376 | completion:^(BOOL finished) { 377 | [self.imagePickerView removeFromSuperview]; 378 | [self.backgroundView removeFromSuperview]; 379 | [self dismissViewControllerAnimated:NO completion:nil]; 380 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 381 | [delegate imagePickerDidClose]; 382 | } 383 | }]; 384 | } else { 385 | [self.imagePickerView setFrame:self.imagePickerFrame]; 386 | [self.backgroundView setAlpha:0]; 387 | } 388 | 389 | // Set everything to nil 390 | } 391 | } 392 | 393 | @end 394 | 395 | #pragma mark - TransitionDelegate - 396 | @implementation TransitionDelegate 397 | 398 | - (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source 399 | { 400 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 401 | controller.isPresenting = YES; 402 | return controller; 403 | } 404 | 405 | @end 406 | 407 | #pragma mark - AnimatedTransitioning - 408 | @implementation AnimatedTransitioning 409 | 410 | - (NSTimeInterval)transitionDuration:(id)transitionContext 411 | { 412 | return 0.25f; 413 | } 414 | 415 | - (void)animateTransition:(id)transitionContext 416 | { 417 | UIView *inView = [transitionContext containerView]; 418 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 419 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 420 | 421 | [inView addSubview:toVC.view]; 422 | 423 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 424 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 425 | 426 | [UIView animateWithDuration:0.25f 427 | animations:^{ 428 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 429 | } 430 | completion:^(BOOL finished) { 431 | [transitionContext completeTransition:YES]; 432 | }]; 433 | } 434 | 435 | @end 436 | 437 | #pragma mark - JSPhotoCell - 438 | @interface JSPhotoCell () 439 | 440 | @end 441 | 442 | @implementation JSPhotoCell 443 | 444 | @end 445 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m.BASE.9946.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 22 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 23 | 24 | @property (readwrite) bool isVisible; 25 | 26 | @property (nonatomic, strong) UIViewController *targetController; 27 | @property (nonatomic, strong) UIWindow *window; 28 | 29 | @property (nonatomic, strong) UIView *backgroundView; 30 | @property (nonatomic, strong) UIView *imagePickerView; 31 | 32 | @property (nonatomic) CGRect imagePickerFrame; 33 | @property (nonatomic) CGRect hiddenFrame; 34 | 35 | @property (nonatomic) TransitionDelegate *transitionController; 36 | 37 | @property (nonatomic, strong) NSMutableArray *assets; 38 | 39 | @end 40 | 41 | @implementation JSImagePickerViewController 42 | 43 | @synthesize delegate; 44 | @synthesize transitionController; 45 | 46 | - (id)init { 47 | self = [super init]; 48 | if (self) { 49 | self.assets = [[NSMutableArray alloc] init]; 50 | [self setupView]; 51 | } 52 | return self; 53 | } 54 | 55 | - (void)setupView { 56 | self.view.backgroundColor = [UIColor clearColor]; 57 | self.window = [UIApplication sharedApplication].keyWindow; 58 | 59 | 60 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 61 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 62 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 63 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 64 | 65 | 66 | 67 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 68 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 69 | self.backgroundView.alpha = 0; 70 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 71 | self.backgroundView.userInteractionEnabled = YES; 72 | [self.backgroundView addGestureRecognizer:dismissTap]; 73 | 74 | 75 | 76 | self.animationTime = 0.2; 77 | 78 | [self.window addSubview:self.backgroundView]; 79 | [self.window addSubview:self.imagePickerView]; 80 | 81 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 82 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 83 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 84 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 85 | 86 | [self.imagePickerView addSubview:btn]; 87 | 88 | [self imagePickerViewSetup]; 89 | [self getCameraRollImages]; 90 | } 91 | 92 | - (void)imagePickerViewSetup { 93 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 94 | 95 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth-7-7, 122); 96 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 97 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 98 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 99 | 100 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 101 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 102 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 103 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 104 | self.collectionView.showsHorizontalScrollIndicator = NO; 105 | self.collectionView.showsVerticalScrollIndicator = NO; 106 | self.collectionView.delegate = self; 107 | self.collectionView.dataSource = self; 108 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 109 | 110 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 111 | 112 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 113 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 114 | self.photoLibraryBtn.titleLabel.font = btnFont; 115 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 116 | 117 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 118 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 119 | self.cameraBtn.titleLabel.font = btnFont; 120 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 121 | 122 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 123 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 124 | self.cancelBtn.titleLabel.font = btnFont; 125 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 126 | 127 | for (UIButton *btn in @[self.photoLibraryBtn, self.cameraBtn, self.cancelBtn]) { 128 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 129 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 130 | } 131 | 132 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 133 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 134 | [self.imagePickerView addSubview:separator1]; 135 | 136 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth-25, 1)]; 137 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 138 | [self.imagePickerView addSubview:separator2]; 139 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth-25, 1)]; 140 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 141 | [self.imagePickerView addSubview:separator3]; 142 | 143 | [self.imagePickerView addSubview:self.collectionView]; 144 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 145 | [self.imagePickerView addSubview:self.cameraBtn]; 146 | [self.imagePickerView addSubview:self.cancelBtn]; 147 | } 148 | 149 | #pragma mark - Collection view 150 | 151 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 152 | return 1; 153 | } 154 | 155 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 156 | return MIN(20, self.assets.count); 157 | } 158 | 159 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 160 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 161 | 162 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 163 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 164 | imageView.clipsToBounds = YES; 165 | imageView.contentMode = UIViewContentModeScaleAspectFill; 166 | [cell addSubview:imageView]; 167 | 168 | return cell; 169 | } 170 | 171 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 172 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 173 | 174 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 175 | UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; 176 | 177 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 178 | [delegate imagePickerDidSelectImage:image]; 179 | } 180 | 181 | [self dismissAnimated:YES]; 182 | } 183 | 184 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 185 | return CGSizeMake(170, 114); 186 | } 187 | 188 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { 189 | return 10.0f; 190 | } 191 | 192 | #pragma mark - Image library 193 | 194 | 195 | - (void)getCameraRollImages { 196 | _assets = [@[] mutableCopy]; 197 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 198 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 199 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 200 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 201 | if(result) 202 | { 203 | [tmpAssets addObject:result]; 204 | } 205 | }]; 206 | 207 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 208 | if (result) { 209 | [self.assets addObject:result]; 210 | } 211 | }; 212 | 213 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 214 | [group setAssetsFilter:onlyPhotosFilter]; 215 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 216 | 217 | [self.collectionView reloadData]; 218 | } failureBlock:^(NSError *error) { 219 | NSLog(@"Error loading images %@", error); 220 | }]; 221 | } 222 | 223 | + (ALAssetsLibrary *)defaultAssetsLibrary 224 | { 225 | static dispatch_once_t pred = 0; 226 | static ALAssetsLibrary *library = nil; 227 | dispatch_once(&pred, ^{ 228 | library = [[ALAssetsLibrary alloc] init]; 229 | }); 230 | return library; 231 | } 232 | 233 | #pragma mark - Image picker 234 | 235 | - (void)takePhotoWasPressed { 236 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 237 | 238 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 239 | message:@"Device has no camera" 240 | delegate:nil 241 | cancelButtonTitle:@"OK" 242 | otherButtonTitles: nil]; 243 | 244 | [myAlertView show]; 245 | 246 | } else { 247 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 248 | picker.delegate = self; 249 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 250 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 251 | 252 | [self presentViewController:picker animated:YES completion:nil]; 253 | } 254 | } 255 | 256 | - (void)selectFromLibraryWasPressed { 257 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 258 | picker.delegate = self; 259 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 260 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 261 | 262 | [self presentViewController:picker animated:YES completion:nil]; 263 | } 264 | 265 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 266 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 267 | 268 | [picker dismissViewControllerAnimated:YES completion:^{ 269 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 270 | [delegate imagePickerDidSelectImage:chosenImage]; 271 | } 272 | [self dismissAnimated:YES]; 273 | }]; 274 | } 275 | 276 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 277 | [picker dismissViewControllerAnimated:YES completion:nil]; 278 | } 279 | 280 | #pragma mark - Show 281 | 282 | - (void)showImagePickerInController:(UIViewController *)controller { 283 | [self showImagePickerInController:controller animated:YES]; 284 | } 285 | 286 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated { 287 | if (self.isVisible != YES) { 288 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 289 | [delegate imagePickerWillOpen]; 290 | } 291 | self.isVisible = YES; 292 | 293 | [self setTransitioningDelegate:transitionController]; 294 | self.modalPresentationStyle = UIModalPresentationCustom; 295 | [controller presentViewController:self animated:NO completion:nil]; 296 | 297 | if (animated) { 298 | [UIView animateWithDuration:self.animationTime 299 | delay:0 300 | options:UIViewAnimationOptionCurveLinear 301 | animations:^{ 302 | [self.imagePickerView setFrame:self.imagePickerFrame]; 303 | [self.backgroundView setAlpha:1]; 304 | } 305 | completion:^(BOOL finished) { 306 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 307 | [delegate imagePickerDidOpen]; 308 | } 309 | }]; 310 | } else { 311 | [self.imagePickerView setFrame:self.imagePickerFrame]; 312 | [self.backgroundView setAlpha:0]; 313 | } 314 | } 315 | } 316 | 317 | #pragma mark - Dismiss 318 | 319 | - (void)dismiss { 320 | [self dismissAnimated:YES]; 321 | } 322 | 323 | - (void)dismissAnimated:(BOOL)animated { 324 | if (self.isVisible == YES) { 325 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 326 | [delegate imagePickerWillClose]; 327 | } 328 | if (animated) { 329 | [UIView animateWithDuration:self.animationTime 330 | delay:0 331 | options:UIViewAnimationOptionCurveEaseIn 332 | animations:^{ 333 | [self.imagePickerView setFrame:self.hiddenFrame]; 334 | [self.backgroundView setAlpha:0]; 335 | } 336 | completion:^(BOOL finished) { 337 | [self.imagePickerView removeFromSuperview]; 338 | [self.backgroundView removeFromSuperview]; 339 | [self dismissViewControllerAnimated:NO completion:nil]; 340 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 341 | [delegate imagePickerDidClose]; 342 | } 343 | }]; 344 | } else { 345 | [self.imagePickerView setFrame:self.imagePickerFrame]; 346 | [self.backgroundView setAlpha:0]; 347 | } 348 | 349 | // Set everything to nil 350 | } 351 | } 352 | 353 | @end 354 | 355 | 356 | 357 | #pragma mark - TransitionDelegate - 358 | @implementation TransitionDelegate 359 | 360 | - (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 361 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 362 | controller.isPresenting = YES; 363 | return controller; 364 | } 365 | 366 | @end 367 | 368 | 369 | 370 | 371 | #pragma mark - AnimatedTransitioning - 372 | @implementation AnimatedTransitioning 373 | 374 | - (NSTimeInterval)transitionDuration:(id )transitionContext { 375 | return 0.25f; 376 | } 377 | 378 | - (void)animateTransition:(id )transitionContext { 379 | UIView *inView = [transitionContext containerView]; 380 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 381 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 382 | 383 | [inView addSubview:toVC.view]; 384 | 385 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 386 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 387 | 388 | [UIView animateWithDuration:0.25f 389 | animations:^{ 390 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 391 | } 392 | completion:^(BOOL finished) { 393 | [transitionContext completeTransition:YES]; 394 | }]; 395 | } 396 | 397 | 398 | @end 399 | 400 | 401 | 402 | #pragma mark - JSPhotoCell - 403 | @interface JSPhotoCell () 404 | 405 | @end 406 | 407 | @implementation JSPhotoCell 408 | 409 | @end 410 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m.LOCAL.9946.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \ 22 | blue:((float)(rgbValue & 0xFF)) / 255.0 \ 23 | alpha:1.0] 24 | 25 | @property(nonatomic, strong) UIViewController *targetController; 26 | @property(nonatomic, strong) UIWindow *window; 27 | 28 | @property(nonatomic, strong) UIView *backgroundView; 29 | @property(nonatomic, strong) UIView *imagePickerView; 30 | 31 | @property(nonatomic) NSTimeInterval animationTime; 32 | 33 | @property(nonatomic) CGRect imagePickerFrame; 34 | @property(nonatomic) CGRect hiddenFrame; 35 | 36 | @property(nonatomic) TransitionDelegate *transitionController; 37 | 38 | @property(nonatomic, strong) UICollectionView *collectionView; 39 | @property(nonatomic, strong) UIButton *photoLibraryBtn; 40 | @property(nonatomic, strong) UIButton *cameraBtn; 41 | @property(nonatomic, strong) UIButton *cancelBtn; 42 | 43 | @property(nonatomic, strong) NSMutableArray *assets; 44 | 45 | @end 46 | 47 | @implementation JSImagePickerViewController 48 | 49 | @synthesize delegate; 50 | @synthesize transitionController; 51 | 52 | - (id)init 53 | { 54 | self = [super init]; 55 | if (self) { 56 | self.assets = [[NSMutableArray alloc] init]; 57 | [self setupView]; 58 | } 59 | return self; 60 | } 61 | 62 | - (void)setupView 63 | { 64 | self.view.backgroundColor = [UIColor clearColor]; 65 | self.window = [UIApplication sharedApplication].keyWindow; 66 | 67 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 68 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 69 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 70 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 71 | 72 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 73 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 74 | self.backgroundView.alpha = 0; 75 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 76 | self.backgroundView.userInteractionEnabled = YES; 77 | [self.backgroundView addGestureRecognizer:dismissTap]; 78 | 79 | self.animationTime = 0.2; 80 | 81 | [self.window addSubview:self.backgroundView]; 82 | [self.window addSubview:self.imagePickerView]; 83 | 84 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 85 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 86 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 87 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 88 | 89 | [self.imagePickerView addSubview:btn]; 90 | 91 | [self imagePickerViewSetup]; 92 | [self getCameraRollImages]; 93 | } 94 | 95 | - (void)imagePickerViewSetup 96 | { 97 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 98 | 99 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth - 7 - 7, 122); 100 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 101 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 102 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 103 | 104 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 105 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 106 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 107 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 108 | self.collectionView.showsHorizontalScrollIndicator = NO; 109 | self.collectionView.showsVerticalScrollIndicator = NO; 110 | self.collectionView.delegate = self; 111 | self.collectionView.dataSource = self; 112 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 113 | 114 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 115 | 116 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 117 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 118 | self.photoLibraryBtn.titleLabel.font = btnFont; 119 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 120 | 121 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 122 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 123 | self.cameraBtn.titleLabel.font = btnFont; 124 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 125 | 126 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 127 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 128 | self.cancelBtn.titleLabel.font = btnFont; 129 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 130 | 131 | for (UIButton *btn in @[ self.photoLibraryBtn, self.cameraBtn, self.cancelBtn ]) { 132 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 133 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 134 | } 135 | 136 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 137 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 138 | [self.imagePickerView addSubview:separator1]; 139 | 140 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth - 25, 1)]; 141 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 142 | [self.imagePickerView addSubview:separator2]; 143 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth - 25, 1)]; 144 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 145 | [self.imagePickerView addSubview:separator3]; 146 | 147 | [self.imagePickerView addSubview:self.collectionView]; 148 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 149 | [self.imagePickerView addSubview:self.cameraBtn]; 150 | [self.imagePickerView addSubview:self.cancelBtn]; 151 | } 152 | 153 | #pragma mark - Collection view 154 | 155 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 156 | { 157 | return 1; 158 | } 159 | 160 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 161 | { 162 | return MIN(20, self.assets.count); 163 | } 164 | 165 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 166 | { 167 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 168 | 169 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 170 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 171 | imageView.clipsToBounds = YES; 172 | imageView.contentMode = UIViewContentModeScaleAspectFill; 173 | [cell addSubview:imageView]; 174 | 175 | return cell; 176 | } 177 | 178 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 179 | { 180 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 181 | 182 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 183 | UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; 184 | 185 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 186 | [delegate imagePicker:self didSelectImage:image]; 187 | } 188 | 189 | [self dismissAnimated:YES]; 190 | } 191 | 192 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 193 | { 194 | return CGSizeMake(170, 114); 195 | } 196 | 197 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 198 | { 199 | return 10.0f; 200 | } 201 | 202 | #pragma mark - Image library 203 | 204 | - (void)getCameraRollImages 205 | { 206 | _assets = [@[] mutableCopy]; 207 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 208 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 209 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 210 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 211 | if(result) 212 | { 213 | [tmpAssets addObject:result]; 214 | } 215 | }]; 216 | 217 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 218 | if (result) { 219 | [self.assets addObject:result]; 220 | } 221 | }; 222 | 223 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 224 | [group setAssetsFilter:onlyPhotosFilter]; 225 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 226 | 227 | [self.collectionView reloadData]; 228 | } failureBlock:^(NSError *error) { 229 | NSLog(@"Error loading images %@", error); 230 | }]; 231 | } 232 | 233 | + (ALAssetsLibrary *)defaultAssetsLibrary 234 | { 235 | static dispatch_once_t pred = 0; 236 | static ALAssetsLibrary *library = nil; 237 | dispatch_once(&pred, ^{ 238 | library = [[ALAssetsLibrary alloc] init]; 239 | }); 240 | return library; 241 | } 242 | 243 | #pragma mark - Image picker 244 | 245 | - (void)takePhotoWasPressed 246 | { 247 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 248 | 249 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 250 | message:@"Device has no camera" 251 | delegate:nil 252 | cancelButtonTitle:@"OK" 253 | otherButtonTitles:nil]; 254 | 255 | [myAlertView show]; 256 | 257 | } else { 258 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 259 | picker.delegate = self; 260 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 261 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 262 | 263 | [self presentViewController:picker animated:YES completion:nil]; 264 | } 265 | } 266 | 267 | - (void)selectFromLibraryWasPressed 268 | { 269 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 270 | picker.delegate = self; 271 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 272 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 273 | 274 | [self presentViewController:picker animated:YES completion:nil]; 275 | } 276 | 277 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 278 | { 279 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 280 | 281 | [picker dismissViewControllerAnimated:YES completion:^{ 282 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 283 | [delegate imagePicker:self didSelectImage:chosenImage]; 284 | } 285 | [self dismissAnimated:YES]; 286 | }]; 287 | } 288 | 289 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 290 | { 291 | [picker dismissViewControllerAnimated:YES completion:nil]; 292 | } 293 | 294 | #pragma mark - Show 295 | 296 | - (void)showImagePickerInController:(UIViewController *)controller 297 | { 298 | [self showImagePickerInController:controller animated:YES]; 299 | } 300 | 301 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated 302 | { 303 | if (self.isVisible != YES) { 304 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 305 | [delegate imagePickerWillOpen]; 306 | } 307 | self.isVisible = YES; 308 | 309 | [self setTransitioningDelegate:transitionController]; 310 | self.modalPresentationStyle = UIModalPresentationCustom; 311 | [controller presentViewController:self animated:NO completion:nil]; 312 | 313 | if (animated) { 314 | [UIView animateWithDuration:self.animationTime 315 | delay:0 316 | options:UIViewAnimationOptionCurveLinear 317 | animations:^{ 318 | [self.imagePickerView setFrame:self.imagePickerFrame]; 319 | [self.backgroundView setAlpha:1]; 320 | } 321 | completion:^(BOOL finished) { 322 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 323 | [delegate imagePickerDidOpen]; 324 | } 325 | }]; 326 | } else { 327 | [self.imagePickerView setFrame:self.imagePickerFrame]; 328 | [self.backgroundView setAlpha:0]; 329 | } 330 | } 331 | } 332 | 333 | #pragma mark - Dismiss 334 | 335 | - (void)dismiss 336 | { 337 | [self dismissAnimated:YES]; 338 | } 339 | 340 | - (void)dismissAnimated:(BOOL)animated 341 | { 342 | if (self.isVisible == YES) { 343 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 344 | [delegate imagePickerWillClose]; 345 | } 346 | if (animated) { 347 | [UIView animateWithDuration:self.animationTime 348 | delay:0 349 | options:UIViewAnimationOptionCurveEaseIn 350 | animations:^{ 351 | [self.imagePickerView setFrame:self.hiddenFrame]; 352 | [self.backgroundView setAlpha:0]; 353 | } 354 | completion:^(BOOL finished) { 355 | [self.imagePickerView removeFromSuperview]; 356 | [self.backgroundView removeFromSuperview]; 357 | [self dismissViewControllerAnimated:NO completion:nil]; 358 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 359 | [delegate imagePickerDidClose]; 360 | } 361 | }]; 362 | } else { 363 | [self.imagePickerView setFrame:self.imagePickerFrame]; 364 | [self.backgroundView setAlpha:0]; 365 | } 366 | 367 | // Set everything to nil 368 | } 369 | } 370 | 371 | @end 372 | 373 | #pragma mark - TransitionDelegate - 374 | @implementation TransitionDelegate 375 | 376 | - (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source 377 | { 378 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 379 | controller.isPresenting = YES; 380 | return controller; 381 | } 382 | 383 | @end 384 | 385 | #pragma mark - AnimatedTransitioning - 386 | @implementation AnimatedTransitioning 387 | 388 | - (NSTimeInterval)transitionDuration:(id)transitionContext 389 | { 390 | return 0.25f; 391 | } 392 | 393 | - (void)animateTransition:(id)transitionContext 394 | { 395 | UIView *inView = [transitionContext containerView]; 396 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 397 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 398 | 399 | [inView addSubview:toVC.view]; 400 | 401 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 402 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 403 | 404 | [UIView animateWithDuration:0.25f 405 | animations:^{ 406 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 407 | } 408 | completion:^(BOOL finished) { 409 | [transitionContext completeTransition:YES]; 410 | }]; 411 | } 412 | 413 | @end 414 | 415 | #pragma mark - JSPhotoCell - 416 | @interface JSPhotoCell () 417 | 418 | @end 419 | 420 | @implementation JSPhotoCell 421 | 422 | @end -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m.REMOTE.9946.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 22 | blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 23 | 24 | @property (readwrite) bool isVisible; 25 | 26 | @property (nonatomic, strong) UIViewController *targetController; 27 | @property (nonatomic, strong) UIWindow *window; 28 | 29 | @property (nonatomic, strong) UIView *backgroundView; 30 | @property (nonatomic, strong) UIView *imagePickerView; 31 | 32 | @property (nonatomic) CGRect imagePickerFrame; 33 | @property (nonatomic) CGRect hiddenFrame; 34 | 35 | @property (nonatomic) TransitionDelegate *transitionController; 36 | 37 | @property (nonatomic, strong) NSMutableArray *assets; 38 | 39 | @end 40 | 41 | @implementation JSImagePickerViewController 42 | 43 | @synthesize delegate; 44 | @synthesize transitionController; 45 | 46 | - (id)init { 47 | self = [super init]; 48 | if (self) { 49 | self.assets = [[NSMutableArray alloc] init]; 50 | [self setupView]; 51 | } 52 | return self; 53 | } 54 | 55 | - (void)setupView { 56 | self.view.backgroundColor = [UIColor clearColor]; 57 | self.window = [UIApplication sharedApplication].keyWindow; 58 | 59 | 60 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 61 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 62 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 63 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 64 | 65 | 66 | 67 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 68 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 69 | self.backgroundView.alpha = 0; 70 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 71 | self.backgroundView.userInteractionEnabled = YES; 72 | [self.backgroundView addGestureRecognizer:dismissTap]; 73 | 74 | 75 | 76 | self.animationTime = 0.2; 77 | 78 | [self.window addSubview:self.backgroundView]; 79 | [self.window addSubview:self.imagePickerView]; 80 | 81 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 82 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 83 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 84 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 85 | 86 | [self.imagePickerView addSubview:btn]; 87 | 88 | [self imagePickerViewSetup]; 89 | [self getCameraRollImages]; 90 | } 91 | 92 | - (void)imagePickerViewSetup { 93 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 94 | 95 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth-7-7, 122); 96 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 97 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 98 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 99 | 100 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 101 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 102 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 103 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 104 | self.collectionView.showsHorizontalScrollIndicator = NO; 105 | self.collectionView.showsVerticalScrollIndicator = NO; 106 | self.collectionView.delegate = self; 107 | self.collectionView.dataSource = self; 108 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 109 | 110 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 111 | 112 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 113 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 114 | self.photoLibraryBtn.titleLabel.font = btnFont; 115 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 116 | 117 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 118 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 119 | self.cameraBtn.titleLabel.font = btnFont; 120 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 121 | 122 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 123 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 124 | self.cancelBtn.titleLabel.font = btnFont; 125 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 126 | 127 | for (UIButton *btn in @[self.photoLibraryBtn, self.cameraBtn, self.cancelBtn]) { 128 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 129 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 130 | } 131 | 132 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 133 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 134 | [self.imagePickerView addSubview:separator1]; 135 | 136 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth-25, 1)]; 137 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 138 | [self.imagePickerView addSubview:separator2]; 139 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth-25, 1)]; 140 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 141 | [self.imagePickerView addSubview:separator3]; 142 | 143 | [self.imagePickerView addSubview:self.collectionView]; 144 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 145 | [self.imagePickerView addSubview:self.cameraBtn]; 146 | [self.imagePickerView addSubview:self.cancelBtn]; 147 | } 148 | 149 | #pragma mark - Collection view 150 | 151 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 152 | return 1; 153 | } 154 | 155 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 156 | return MIN(20, self.assets.count); 157 | } 158 | 159 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 160 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 161 | 162 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 163 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 164 | imageView.clipsToBounds = YES; 165 | imageView.contentMode = UIViewContentModeScaleAspectFill; 166 | [cell addSubview:imageView]; 167 | 168 | return cell; 169 | } 170 | 171 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 172 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 173 | 174 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 175 | ALAssetRepresentation* representation = [asset defaultRepresentation]; 176 | UIImageOrientation orientation = UIImageOrientationUp; 177 | NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"]; 178 | if (orientationValue != nil) { 179 | orientation = [orientationValue intValue]; 180 | } 181 | 182 | CGFloat scale = 1; 183 | UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage] 184 | scale:scale orientation:orientation]; 185 | 186 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 187 | [delegate imagePickerDidSelectImage:image]; 188 | } 189 | 190 | [self dismissAnimated:YES]; 191 | } 192 | 193 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 194 | return CGSizeMake(170, 114); 195 | } 196 | 197 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { 198 | return 10.0f; 199 | } 200 | 201 | #pragma mark - Image library 202 | 203 | 204 | - (void)getCameraRollImages { 205 | _assets = [@[] mutableCopy]; 206 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 207 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 208 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 209 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 210 | if(result) 211 | { 212 | [tmpAssets addObject:result]; 213 | } 214 | }]; 215 | 216 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 217 | if (result) { 218 | [self.assets addObject:result]; 219 | } 220 | }; 221 | 222 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 223 | [group setAssetsFilter:onlyPhotosFilter]; 224 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 225 | 226 | [self.collectionView reloadData]; 227 | } failureBlock:^(NSError *error) { 228 | NSLog(@"Error loading images %@", error); 229 | }]; 230 | } 231 | 232 | + (ALAssetsLibrary *)defaultAssetsLibrary 233 | { 234 | static dispatch_once_t pred = 0; 235 | static ALAssetsLibrary *library = nil; 236 | dispatch_once(&pred, ^{ 237 | library = [[ALAssetsLibrary alloc] init]; 238 | }); 239 | return library; 240 | } 241 | 242 | #pragma mark - Image picker 243 | 244 | - (void)takePhotoWasPressed { 245 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 246 | 247 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 248 | message:@"Device has no camera" 249 | delegate:nil 250 | cancelButtonTitle:@"OK" 251 | otherButtonTitles: nil]; 252 | 253 | [myAlertView show]; 254 | 255 | } else { 256 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 257 | picker.delegate = self; 258 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 259 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 260 | 261 | [self presentViewController:picker animated:YES completion:nil]; 262 | } 263 | } 264 | 265 | - (void)selectFromLibraryWasPressed { 266 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 267 | picker.delegate = self; 268 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 269 | picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; 270 | 271 | [self presentViewController:picker animated:YES completion:nil]; 272 | } 273 | 274 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 275 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 276 | 277 | [picker dismissViewControllerAnimated:YES completion:^{ 278 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 279 | [delegate imagePickerDidSelectImage:chosenImage]; 280 | } 281 | [self dismissAnimated:YES]; 282 | }]; 283 | } 284 | 285 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 286 | [picker dismissViewControllerAnimated:YES completion:nil]; 287 | } 288 | 289 | #pragma mark - Show 290 | 291 | - (void)showImagePickerInController:(UIViewController *)controller { 292 | [self showImagePickerInController:controller animated:YES]; 293 | } 294 | 295 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated { 296 | if (self.isVisible != YES) { 297 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 298 | [delegate imagePickerWillOpen]; 299 | } 300 | self.isVisible = YES; 301 | 302 | [self setTransitioningDelegate:transitionController]; 303 | if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { 304 | self.modalPresentationStyle = UIModalPresentationOverCurrentContext; 305 | } else { 306 | self.modalPresentationStyle = UIModalPresentationCustom; 307 | } 308 | [controller presentViewController:self animated:NO completion:nil]; 309 | 310 | if (animated) { 311 | [UIView animateWithDuration:self.animationTime 312 | delay:0 313 | options:UIViewAnimationOptionCurveLinear 314 | animations:^{ 315 | [self.imagePickerView setFrame:self.imagePickerFrame]; 316 | [self.backgroundView setAlpha:1]; 317 | } 318 | completion:^(BOOL finished) { 319 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 320 | [delegate imagePickerDidOpen]; 321 | } 322 | }]; 323 | } else { 324 | [self.imagePickerView setFrame:self.imagePickerFrame]; 325 | [self.backgroundView setAlpha:0]; 326 | } 327 | } 328 | } 329 | 330 | #pragma mark - Dismiss 331 | 332 | - (void)dismiss { 333 | [self dismissAnimated:YES]; 334 | } 335 | 336 | - (void)dismissAnimated:(BOOL)animated { 337 | if (self.isVisible == YES) { 338 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 339 | [delegate imagePickerWillClose]; 340 | } 341 | if (animated) { 342 | [UIView animateWithDuration:self.animationTime 343 | delay:0 344 | options:UIViewAnimationOptionCurveEaseIn 345 | animations:^{ 346 | [self.imagePickerView setFrame:self.hiddenFrame]; 347 | [self.backgroundView setAlpha:0]; 348 | } 349 | completion:^(BOOL finished) { 350 | [self.imagePickerView removeFromSuperview]; 351 | [self.backgroundView removeFromSuperview]; 352 | [self dismissViewControllerAnimated:NO completion:nil]; 353 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 354 | [delegate imagePickerDidClose]; 355 | } 356 | }]; 357 | } else { 358 | [self.imagePickerView setFrame:self.imagePickerFrame]; 359 | [self.backgroundView setAlpha:0]; 360 | } 361 | 362 | // Set everything to nil 363 | } 364 | } 365 | 366 | @end 367 | 368 | 369 | 370 | #pragma mark - TransitionDelegate - 371 | @implementation TransitionDelegate 372 | 373 | - (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 374 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 375 | controller.isPresenting = YES; 376 | return controller; 377 | } 378 | 379 | @end 380 | 381 | 382 | 383 | 384 | #pragma mark - AnimatedTransitioning - 385 | @implementation AnimatedTransitioning 386 | 387 | - (NSTimeInterval)transitionDuration:(id )transitionContext { 388 | return 0.25f; 389 | } 390 | 391 | - (void)animateTransition:(id )transitionContext { 392 | UIView *inView = [transitionContext containerView]; 393 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 394 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 395 | 396 | [inView addSubview:toVC.view]; 397 | 398 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 399 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 400 | 401 | [UIView animateWithDuration:0.25f 402 | animations:^{ 403 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 404 | } 405 | completion:^(BOOL finished) { 406 | [transitionContext completeTransition:YES]; 407 | }]; 408 | } 409 | 410 | 411 | @end 412 | 413 | 414 | 415 | #pragma mark - JSPhotoCell - 416 | @interface JSPhotoCell () 417 | 418 | @end 419 | 420 | @implementation JSPhotoCell 421 | 422 | @end 423 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSImagePickerViewController.m.orig: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \ 22 | blue:((float)(rgbValue & 0xFF)) / 255.0 \ 23 | alpha:1.0] 24 | 25 | @property(nonatomic, strong) UIViewController *targetController; 26 | @property(nonatomic, strong) UIWindow *window; 27 | 28 | @property(nonatomic, strong) UIView *backgroundView; 29 | @property(nonatomic, strong) UIView *imagePickerView; 30 | 31 | @property(nonatomic) NSTimeInterval animationTime; 32 | 33 | @property(nonatomic) CGRect imagePickerFrame; 34 | @property(nonatomic) CGRect hiddenFrame; 35 | 36 | @property(nonatomic) TransitionDelegate *transitionController; 37 | 38 | @property(nonatomic, strong) UICollectionView *collectionView; 39 | @property(nonatomic, strong) UIButton *photoLibraryBtn; 40 | @property(nonatomic, strong) UIButton *cameraBtn; 41 | @property(nonatomic, strong) UIButton *cancelBtn; 42 | 43 | @property(nonatomic, strong) NSMutableArray *assets; 44 | 45 | @end 46 | 47 | @implementation JSImagePickerViewController 48 | 49 | @synthesize delegate; 50 | @synthesize transitionController; 51 | 52 | - (id)init 53 | { 54 | self = [super init]; 55 | if (self) { 56 | self.assets = [[NSMutableArray alloc] init]; 57 | [self setupView]; 58 | } 59 | return self; 60 | } 61 | 62 | - (void)setupView 63 | { 64 | self.view.backgroundColor = [UIColor clearColor]; 65 | self.window = [UIApplication sharedApplication].keyWindow; 66 | 67 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 68 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 69 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 70 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 71 | 72 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 73 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 74 | self.backgroundView.alpha = 0; 75 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 76 | self.backgroundView.userInteractionEnabled = YES; 77 | [self.backgroundView addGestureRecognizer:dismissTap]; 78 | 79 | self.animationTime = 0.2; 80 | 81 | [self.window addSubview:self.backgroundView]; 82 | [self.window addSubview:self.imagePickerView]; 83 | 84 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 85 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 86 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 87 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 88 | 89 | [self.imagePickerView addSubview:btn]; 90 | 91 | [self imagePickerViewSetup]; 92 | [self getCameraRollImages]; 93 | } 94 | 95 | - (void)imagePickerViewSetup 96 | { 97 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 98 | 99 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth - 7 - 7, 122); 100 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 101 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 102 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 103 | 104 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 105 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 106 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 107 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 108 | self.collectionView.showsHorizontalScrollIndicator = NO; 109 | self.collectionView.showsVerticalScrollIndicator = NO; 110 | self.collectionView.delegate = self; 111 | self.collectionView.dataSource = self; 112 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 113 | 114 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 115 | 116 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 117 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 118 | self.photoLibraryBtn.titleLabel.font = btnFont; 119 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 120 | 121 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 122 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 123 | self.cameraBtn.titleLabel.font = btnFont; 124 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 125 | 126 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 127 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 128 | self.cancelBtn.titleLabel.font = btnFont; 129 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 130 | 131 | for (UIButton *btn in @[ self.photoLibraryBtn, self.cameraBtn, self.cancelBtn ]) { 132 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 133 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 134 | } 135 | 136 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 137 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 138 | [self.imagePickerView addSubview:separator1]; 139 | 140 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth - 25, 1)]; 141 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 142 | [self.imagePickerView addSubview:separator2]; 143 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth - 25, 1)]; 144 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 145 | [self.imagePickerView addSubview:separator3]; 146 | 147 | [self.imagePickerView addSubview:self.collectionView]; 148 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 149 | [self.imagePickerView addSubview:self.cameraBtn]; 150 | [self.imagePickerView addSubview:self.cancelBtn]; 151 | } 152 | 153 | #pragma mark - Collection view 154 | 155 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 156 | { 157 | return 1; 158 | } 159 | 160 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 161 | { 162 | return MIN(20, self.assets.count); 163 | } 164 | 165 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 166 | { 167 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 168 | 169 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 170 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 171 | imageView.clipsToBounds = YES; 172 | imageView.contentMode = UIViewContentModeScaleAspectFill; 173 | [cell addSubview:imageView]; 174 | 175 | return cell; 176 | } 177 | 178 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 179 | { 180 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 181 | <<<<<<< HEAD 182 | 183 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 184 | UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; 185 | 186 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 187 | [delegate imagePicker:self didSelectImage:image]; 188 | ======= 189 | 190 | ALAsset *asset = self.assets[self.assets.count-1 - indexPath.row]; 191 | ALAssetRepresentation* representation = [asset defaultRepresentation]; 192 | UIImageOrientation orientation = UIImageOrientationUp; 193 | NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"]; 194 | if (orientationValue != nil) { 195 | orientation = [orientationValue intValue]; 196 | } 197 | 198 | CGFloat scale = 1; 199 | UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage] 200 | scale:scale orientation:orientation]; 201 | 202 | if ([delegate respondsToSelector:@selector(imagePickerDidSelectImage:)]) { 203 | [delegate imagePickerDidSelectImage:image]; 204 | >>>>>>> 53567d0f0ff945d610e0d646003c2030aa1b09b5 205 | } 206 | 207 | [self dismissAnimated:YES]; 208 | } 209 | 210 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 211 | { 212 | return CGSizeMake(170, 114); 213 | } 214 | 215 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 216 | { 217 | return 10.0f; 218 | } 219 | 220 | #pragma mark - Image library 221 | 222 | - (void)getCameraRollImages 223 | { 224 | _assets = [@[] mutableCopy]; 225 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 226 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 227 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 228 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 229 | if(result) 230 | { 231 | [tmpAssets addObject:result]; 232 | } 233 | }]; 234 | 235 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 236 | if (result) { 237 | [self.assets addObject:result]; 238 | } 239 | }; 240 | 241 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 242 | [group setAssetsFilter:onlyPhotosFilter]; 243 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 244 | 245 | [self.collectionView reloadData]; 246 | } failureBlock:^(NSError *error) { 247 | NSLog(@"Error loading images %@", error); 248 | }]; 249 | } 250 | 251 | + (ALAssetsLibrary *)defaultAssetsLibrary 252 | { 253 | static dispatch_once_t pred = 0; 254 | static ALAssetsLibrary *library = nil; 255 | dispatch_once(&pred, ^{ 256 | library = [[ALAssetsLibrary alloc] init]; 257 | }); 258 | return library; 259 | } 260 | 261 | #pragma mark - Image picker 262 | 263 | - (void)takePhotoWasPressed 264 | { 265 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 266 | 267 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 268 | message:@"Device has no camera" 269 | delegate:nil 270 | cancelButtonTitle:@"OK" 271 | otherButtonTitles:nil]; 272 | 273 | [myAlertView show]; 274 | 275 | } else { 276 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 277 | picker.delegate = self; 278 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 279 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 280 | 281 | [self presentViewController:picker animated:YES completion:nil]; 282 | } 283 | } 284 | 285 | - (void)selectFromLibraryWasPressed 286 | { 287 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 288 | picker.delegate = self; 289 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 290 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 291 | 292 | [self presentViewController:picker animated:YES completion:nil]; 293 | } 294 | 295 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 296 | { 297 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 298 | 299 | [picker dismissViewControllerAnimated:YES completion:^{ 300 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImage:)]) { 301 | [delegate imagePicker:self didSelectImage:chosenImage]; 302 | } 303 | [self dismissAnimated:YES]; 304 | }]; 305 | } 306 | 307 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 308 | { 309 | [picker dismissViewControllerAnimated:YES completion:nil]; 310 | } 311 | 312 | #pragma mark - Show 313 | 314 | - (void)showImagePickerInController:(UIViewController *)controller 315 | { 316 | [self showImagePickerInController:controller animated:YES]; 317 | } 318 | 319 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated 320 | { 321 | if (self.isVisible != YES) { 322 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 323 | [delegate imagePickerWillOpen]; 324 | } 325 | self.isVisible = YES; 326 | 327 | [self setTransitioningDelegate:transitionController]; 328 | if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { 329 | self.modalPresentationStyle = UIModalPresentationOverCurrentContext; 330 | } else { 331 | self.modalPresentationStyle = UIModalPresentationCustom; 332 | } 333 | [controller presentViewController:self animated:NO completion:nil]; 334 | 335 | if (animated) { 336 | [UIView animateWithDuration:self.animationTime 337 | delay:0 338 | options:UIViewAnimationOptionCurveLinear 339 | animations:^{ 340 | [self.imagePickerView setFrame:self.imagePickerFrame]; 341 | [self.backgroundView setAlpha:1]; 342 | } 343 | completion:^(BOOL finished) { 344 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 345 | [delegate imagePickerDidOpen]; 346 | } 347 | }]; 348 | } else { 349 | [self.imagePickerView setFrame:self.imagePickerFrame]; 350 | [self.backgroundView setAlpha:0]; 351 | } 352 | } 353 | } 354 | 355 | #pragma mark - Dismiss 356 | 357 | - (void)dismiss 358 | { 359 | [self dismissAnimated:YES]; 360 | } 361 | 362 | - (void)dismissAnimated:(BOOL)animated 363 | { 364 | if (self.isVisible == YES) { 365 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 366 | [delegate imagePickerWillClose]; 367 | } 368 | if (animated) { 369 | [UIView animateWithDuration:self.animationTime 370 | delay:0 371 | options:UIViewAnimationOptionCurveEaseIn 372 | animations:^{ 373 | [self.imagePickerView setFrame:self.hiddenFrame]; 374 | [self.backgroundView setAlpha:0]; 375 | } 376 | completion:^(BOOL finished) { 377 | [self.imagePickerView removeFromSuperview]; 378 | [self.backgroundView removeFromSuperview]; 379 | [self dismissViewControllerAnimated:NO completion:nil]; 380 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 381 | [delegate imagePickerDidClose]; 382 | } 383 | }]; 384 | } else { 385 | [self.imagePickerView setFrame:self.imagePickerFrame]; 386 | [self.backgroundView setAlpha:0]; 387 | } 388 | 389 | // Set everything to nil 390 | } 391 | } 392 | 393 | @end 394 | 395 | #pragma mark - TransitionDelegate - 396 | @implementation TransitionDelegate 397 | 398 | - (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source 399 | { 400 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 401 | controller.isPresenting = YES; 402 | return controller; 403 | } 404 | 405 | @end 406 | 407 | #pragma mark - AnimatedTransitioning - 408 | @implementation AnimatedTransitioning 409 | 410 | - (NSTimeInterval)transitionDuration:(id)transitionContext 411 | { 412 | return 0.25f; 413 | } 414 | 415 | - (void)animateTransition:(id)transitionContext 416 | { 417 | UIView *inView = [transitionContext containerView]; 418 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 419 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 420 | 421 | [inView addSubview:toVC.view]; 422 | 423 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 424 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 425 | 426 | [UIView animateWithDuration:0.25f 427 | animations:^{ 428 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 429 | } 430 | completion:^(BOOL finished) { 431 | [transitionContext completeTransition:YES]; 432 | }]; 433 | } 434 | 435 | @end 436 | 437 | #pragma mark - JSPhotoCell - 438 | @interface JSPhotoCell () 439 | 440 | @end 441 | 442 | @implementation JSPhotoCell 443 | 444 | @end 445 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSViewController.h 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JSViewController : UIViewController 12 | 13 | @property (nonatomic, weak) IBOutlet UIButton *showButton; 14 | - (IBAction)showBtnWasPressed:(id)sender; 15 | 16 | @property (nonatomic, weak) IBOutlet UIImageView *imageView; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/JSViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSViewController.h" 10 | #import "JSImagePickerViewController.h" 11 | 12 | @interface JSViewController () 13 | 14 | @end 15 | 16 | @implementation JSViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | self.imageView.contentMode = UIViewContentModeScaleAspectFit; 22 | self.imageView.backgroundColor = [UIColor colorWithRed:0.616 green:0.825 blue:1.000 alpha:1.000]; 23 | 24 | self.showButton.layer.masksToBounds = YES; 25 | self.showButton.layer.cornerRadius = 3; 26 | self.imageView.layer.masksToBounds = YES; 27 | self.imageView.layer.cornerRadius = 3; 28 | } 29 | 30 | - (void)didReceiveMemoryWarning { 31 | [super didReceiveMemoryWarning]; 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | - (void)showBtnWasPressed:(id)sender { 36 | JSImagePickerViewController *imagePicker = [[JSImagePickerViewController alloc] init]; 37 | imagePicker.delegate = self; 38 | [imagePicker showImagePickerInController:self animated:YES]; 39 | } 40 | 41 | #pragma mark - JSImagePikcerViewControllerDelegate 42 | 43 | - (void)imagePicker:(JSImagePickerViewController *)imagePicker didSelectImage:(UIImage *)image { 44 | self.imageView.image = image; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePicker/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePickerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.Sieradzki.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Demo/iOS8Style-ImagePickerTests/iOS8Style_ImagePickerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // iOS8Style_ImagePickerTests.m 3 | // iOS8Style-ImagePickerTests 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface iOS8Style_ImagePickerTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation iOS8Style_ImagePickerTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /JSImagePickerController Source/JSImagePickerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.h 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class JSImagePickerViewController; 12 | @protocol JSImagePickerViewControllerDelegate 13 | 14 | - (void)imagePicker:(JSImagePickerViewController *)imagePicker didSelectImages:(NSArray *)images; 15 | 16 | @optional 17 | 18 | - (void)imagePickerDidOpen; 19 | - (void)imagePickerWillOpen; 20 | 21 | - (void)imagePickerWillClose; 22 | - (void)imagePickerDidClose; 23 | 24 | - (void)imagePickerDidCancel; 25 | 26 | @end 27 | 28 | @interface JSImagePickerViewController : UIViewController { 29 | __unsafe_unretained id delegate; 30 | } 31 | 32 | @property(nonatomic, assign) id delegate; 33 | 34 | @property bool isVisible; 35 | 36 | @property(assign, nonatomic) NSUInteger tag; 37 | 38 | - (void)showImagePickerInController:(UIViewController *)controller; 39 | 40 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated; 41 | 42 | - (void)dismiss; 43 | 44 | - (void)dismissAnimated:(BOOL)animated; 45 | 46 | @end 47 | 48 | @interface TransitionDelegate : NSObject 49 | 50 | @end 51 | 52 | @interface AnimatedTransitioning : NSObject 53 | 54 | @property(nonatomic, assign) BOOL isPresenting; 55 | 56 | @end 57 | 58 | @interface JSPhotoCell : UICollectionViewCell 59 | 60 | @end -------------------------------------------------------------------------------- /JSImagePickerController Source/JSImagePickerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JSImagePickerViewController.m 3 | // iOS8Style-ImagePicker 4 | // 5 | // Created by Jake Sieradzki on 09/01/2015. 6 | // Copyright (c) 2015 Jake Sieradzki. All rights reserved. 7 | // 8 | 9 | #import "JSImagePickerViewController.h" 10 | #import 11 | #import 12 | 13 | #pragma mark - JSImagePickerViewController - 14 | 15 | @interface JSImagePickerViewController () 16 | 17 | #define imagePickerHeight 280.0f 18 | 19 | #define UIColorFromRGB(rgbValue) [UIColor \ 20 | colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \ 21 | green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \ 22 | blue:((float)(rgbValue & 0xFF)) / 255.0 \ 23 | alpha:1.0] 24 | 25 | @property(nonatomic, strong) UIViewController *targetController; 26 | @property(nonatomic, strong) UIWindow *window; 27 | 28 | @property(nonatomic, strong) UIView *backgroundView; 29 | @property(nonatomic, strong) UIView *imagePickerView; 30 | 31 | @property(nonatomic) NSTimeInterval animationTime; 32 | 33 | @property(nonatomic) CGRect imagePickerFrame; 34 | @property(nonatomic) CGRect hiddenFrame; 35 | 36 | @property(nonatomic) TransitionDelegate *transitionController; 37 | 38 | @property(nonatomic, strong) UICollectionView *collectionView; 39 | @property(nonatomic, strong) UIButton *photoLibraryBtn; 40 | @property(nonatomic, strong) UIButton *cameraBtn; 41 | @property(nonatomic, strong) UIButton *cancelBtn; 42 | 43 | @property(nonatomic, strong) NSMutableArray *assets; 44 | @property(nonatomic, strong) NSMutableArray *selectedPhotos; 45 | 46 | @end 47 | 48 | @implementation JSImagePickerViewController 49 | 50 | @synthesize delegate; 51 | @synthesize transitionController; 52 | @synthesize selectedPhotos; 53 | 54 | - (id)init 55 | { 56 | self = [super init]; 57 | if (self) { 58 | self.assets = [[NSMutableArray alloc] init]; 59 | [self setupView]; 60 | } 61 | return self; 62 | } 63 | 64 | - (void)setupView 65 | { 66 | self.view.backgroundColor = [UIColor clearColor]; 67 | self.window = [UIApplication sharedApplication].keyWindow; 68 | 69 | self.imagePickerFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - imagePickerHeight, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 70 | self.hiddenFrame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, imagePickerHeight); 71 | self.imagePickerView = [[UIView alloc] initWithFrame:self.hiddenFrame]; 72 | self.imagePickerView.backgroundColor = [UIColor whiteColor]; 73 | 74 | self.backgroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 75 | self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.7]; 76 | self.backgroundView.alpha = 0; 77 | UITapGestureRecognizer *dismissTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 78 | self.backgroundView.userInteractionEnabled = YES; 79 | [self.backgroundView addGestureRecognizer:dismissTap]; 80 | 81 | self.animationTime = 0.2; 82 | 83 | [self.window addSubview:self.backgroundView]; 84 | [self.window addSubview:self.imagePickerView]; 85 | 86 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.imagePickerView.frame.size.width, 50)]; 87 | [btn setTitle:@"Hello!" forState:UIControlStateNormal]; 88 | [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 89 | [btn addTarget:self action:@selector(setDefaults) forControlEvents:UIControlEventTouchUpInside]; 90 | 91 | [self.imagePickerView addSubview:btn]; 92 | 93 | selectedPhotos = [NSMutableArray new]; 94 | 95 | [self imagePickerViewSetup]; 96 | [self getCameraRollImages]; 97 | } 98 | 99 | - (void)imagePickerViewSetup 100 | { 101 | CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; 102 | 103 | const CGRect collectionViewFrame = CGRectMake(7, 8, screenWidth - 7 - 7, 122); 104 | const CGRect libraryBtnFrame = CGRectMake(0, 149, screenWidth, 30); 105 | const CGRect cameraBtnFrame = CGRectMake(0, 196, screenWidth, 30); 106 | const CGRect cancelBtnFrame = CGRectMake(0, 242, screenWidth, 30); 107 | 108 | UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; 109 | [aFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; 110 | self.collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:aFlowLayout]; 111 | [self.collectionView setBackgroundColor:[UIColor whiteColor]]; 112 | self.collectionView.showsHorizontalScrollIndicator = NO; 113 | self.collectionView.showsVerticalScrollIndicator = NO; 114 | self.collectionView.delegate = self; 115 | self.collectionView.dataSource = self; 116 | [self.collectionView registerClass:[JSPhotoCell class] forCellWithReuseIdentifier:@"Cell"]; 117 | 118 | UIFont *btnFont = [UIFont systemFontOfSize:19.0]; 119 | 120 | self.photoLibraryBtn = [[UIButton alloc] initWithFrame:libraryBtnFrame]; 121 | [self.photoLibraryBtn setTitle:@"Photo Library" forState:UIControlStateNormal]; 122 | self.photoLibraryBtn.titleLabel.font = btnFont; 123 | [self.photoLibraryBtn addTarget:self action:@selector(selectFromLibraryWasPressed) forControlEvents:UIControlEventTouchUpInside]; 124 | 125 | self.cameraBtn = [[UIButton alloc] initWithFrame:cameraBtnFrame]; 126 | [self.cameraBtn setTitle:@"Take Photo" forState:UIControlStateNormal]; 127 | self.cameraBtn.titleLabel.font = btnFont; 128 | [self.cameraBtn addTarget:self action:@selector(takePhotoWasPressed) forControlEvents:UIControlEventTouchUpInside]; 129 | 130 | self.cancelBtn = [[UIButton alloc] initWithFrame:cancelBtnFrame]; 131 | [self.cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 132 | self.cancelBtn.titleLabel.font = btnFont; 133 | [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside]; 134 | 135 | for (UIButton *btn in @[ self.photoLibraryBtn, self.cameraBtn, self.cancelBtn ]) { 136 | [btn setTitleColor:UIColorFromRGB(0x0b60fe) forState:UIControlStateNormal]; 137 | [btn setTitleColor:UIColorFromRGB(0x70B3FD) forState:UIControlStateHighlighted]; 138 | } 139 | 140 | UIView *separator1 = [[UIView alloc] initWithFrame:CGRectMake(0, 140, screenWidth, 1)]; 141 | separator1.backgroundColor = UIColorFromRGB(0xDDDDDD); 142 | [self.imagePickerView addSubview:separator1]; 143 | 144 | UIView *separator2 = [[UIView alloc] initWithFrame:CGRectMake(25, 187, screenWidth - 25, 1)]; 145 | separator2.backgroundColor = UIColorFromRGB(0xDDDDDD); 146 | [self.imagePickerView addSubview:separator2]; 147 | UIView *separator3 = [[UIView alloc] initWithFrame:CGRectMake(25, 234, screenWidth - 25, 1)]; 148 | separator3.backgroundColor = UIColorFromRGB(0xDDDDDD); 149 | [self.imagePickerView addSubview:separator3]; 150 | 151 | [self.imagePickerView addSubview:self.collectionView]; 152 | [self.imagePickerView addSubview:self.photoLibraryBtn]; 153 | [self.imagePickerView addSubview:self.cameraBtn]; 154 | [self.imagePickerView addSubview:self.cancelBtn]; 155 | } 156 | 157 | - (void)setDefaults { 158 | #warning defaults!! 159 | } 160 | 161 | #pragma mark - Collection view 162 | 163 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 164 | { 165 | return 1; 166 | } 167 | 168 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 169 | { 170 | return MIN(20, self.assets.count); 171 | } 172 | 173 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 174 | { 175 | JSPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 176 | 177 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 178 | UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]]; 179 | imageView.clipsToBounds = YES; 180 | imageView.contentMode = UIViewContentModeScaleAspectFill; 181 | [cell addSubview:imageView]; 182 | 183 | UIImageView *sel = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PreviewSupplementaryView-Checkmark.png"]]; 184 | [sel setFrame:CGRectMake(95, 5, 25, 25)]; 185 | //[sel setBackgroundColor:[UIColor blackColor]]; 186 | 187 | if ([selectedPhotos containsObject:asset]) { 188 | [sel setImage:[UIImage imageNamed:@"PreviewSupplementaryView-Checkmark-Selected.png"]]; 189 | } 190 | 191 | [cell addSubview:sel]; 192 | 193 | return cell; 194 | } 195 | 196 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 197 | { 198 | [collectionView deselectItemAtIndexPath:indexPath animated:YES]; 199 | ALAsset *asset = self.assets[self.assets.count - 1 - indexPath.row]; 200 | if([selectedPhotos containsObject:asset]) { 201 | [selectedPhotos removeObject:asset]; 202 | } else { 203 | [selectedPhotos addObject:asset]; 204 | } 205 | [collectionView reloadData]; 206 | [self updateButtons]; 207 | } 208 | 209 | -(void)updateButtons { 210 | if (selectedPhotos.count > 0) { 211 | [self.photoLibraryBtn setTitle:[NSString stringWithFormat:@"Send %lu photos", (unsigned long)selectedPhotos.count] forState:UIControlStateNormal]; 212 | } else { 213 | [self.photoLibraryBtn setTitle:@"Image library" forState:UIControlStateNormal]; 214 | } 215 | } 216 | 217 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 218 | { 219 | return CGSizeMake(125, 114); 220 | } 221 | 222 | - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 223 | { 224 | return 10.0f; 225 | } 226 | 227 | #pragma mark - Image library 228 | 229 | - (void)getCameraRollImages 230 | { 231 | _assets = [@[] mutableCopy]; 232 | __block NSMutableArray *tmpAssets = [@[] mutableCopy]; 233 | ALAssetsLibrary *assetsLibrary = [JSImagePickerViewController defaultAssetsLibrary]; 234 | [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 235 | [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 236 | if(result) 237 | { 238 | [tmpAssets addObject:result]; 239 | } 240 | }]; 241 | 242 | ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 243 | if (result) { 244 | [self.assets addObject:result]; 245 | } 246 | }; 247 | 248 | ALAssetsFilter *onlyPhotosFilter = [ALAssetsFilter allPhotos]; 249 | [group setAssetsFilter:onlyPhotosFilter]; 250 | [group enumerateAssetsUsingBlock:assetsEnumerationBlock]; 251 | 252 | [self.collectionView reloadData]; 253 | } failureBlock:^(NSError *error) { 254 | NSLog(@"Error loading images %@", error); 255 | }]; 256 | } 257 | 258 | + (ALAssetsLibrary *)defaultAssetsLibrary 259 | { 260 | static dispatch_once_t pred = 0; 261 | static ALAssetsLibrary *library = nil; 262 | dispatch_once(&pred, ^{ 263 | library = [[ALAssetsLibrary alloc] init]; 264 | }); 265 | return library; 266 | } 267 | 268 | #pragma mark - Image picker 269 | 270 | - (void)takePhotoWasPressed 271 | { 272 | if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 273 | 274 | UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 275 | message:@"Device has no camera" 276 | delegate:nil 277 | cancelButtonTitle:@"OK" 278 | otherButtonTitles:nil]; 279 | 280 | [myAlertView show]; 281 | 282 | } else { 283 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 284 | picker.delegate = self; 285 | picker.sourceType = UIImagePickerControllerSourceTypeCamera; 286 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 287 | 288 | [self presentViewController:picker animated:YES completion:nil]; 289 | } 290 | } 291 | 292 | - (void)selectFromLibraryWasPressed 293 | { 294 | if (selectedPhotos.count > 0) { 295 | NSMutableArray *images = [NSMutableArray new]; 296 | for (ALAsset *asset in selectedPhotos) { 297 | UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; 298 | [images addObject:image]; 299 | } 300 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImages:)]) { 301 | [delegate imagePicker:self didSelectImages:images]; 302 | } 303 | 304 | [self dismissAnimated:YES]; 305 | return; 306 | } 307 | UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 308 | picker.delegate = self; 309 | picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 310 | picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]; 311 | 312 | [self presentViewController:picker animated:YES completion:nil]; 313 | } 314 | 315 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 316 | { 317 | UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; 318 | 319 | [picker dismissViewControllerAnimated:YES completion:^{ 320 | if ([delegate respondsToSelector:@selector(imagePicker:didSelectImages:)]) { 321 | [delegate imagePicker:self didSelectImages:@[chosenImage]]; 322 | } 323 | [self dismissAnimated:YES]; 324 | }]; 325 | } 326 | 327 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 328 | { 329 | [picker dismissViewControllerAnimated:YES completion:nil]; 330 | } 331 | 332 | #pragma mark - Show 333 | 334 | - (void)showImagePickerInController:(UIViewController *)controller 335 | { 336 | [self showImagePickerInController:controller animated:YES]; 337 | } 338 | 339 | - (void)showImagePickerInController:(UIViewController *)controller animated:(BOOL)animated 340 | { 341 | if (self.isVisible != YES) { 342 | if ([delegate respondsToSelector:@selector(imagePickerWillOpen)]) { 343 | [delegate imagePickerWillOpen]; 344 | } 345 | self.isVisible = YES; 346 | 347 | [self setTransitioningDelegate:transitionController]; 348 | self.modalPresentationStyle = UIModalPresentationCustom; 349 | [controller presentViewController:self animated:NO completion:nil]; 350 | 351 | if (animated) { 352 | [UIView animateWithDuration:self.animationTime 353 | delay:0 354 | options:UIViewAnimationOptionCurveLinear 355 | animations:^{ 356 | [self.imagePickerView setFrame:self.imagePickerFrame]; 357 | [self.backgroundView setAlpha:1]; 358 | } 359 | completion:^(BOOL finished) { 360 | if ([delegate respondsToSelector:@selector(imagePickerDidOpen)]) { 361 | [delegate imagePickerDidOpen]; 362 | } 363 | }]; 364 | } else { 365 | [self.imagePickerView setFrame:self.imagePickerFrame]; 366 | [self.backgroundView setAlpha:0]; 367 | } 368 | } 369 | } 370 | 371 | #pragma mark - Dismiss 372 | 373 | - (void)dismiss 374 | { 375 | [self dismissAnimated:YES]; 376 | } 377 | 378 | - (void)dismissAnimated:(BOOL)animated 379 | { 380 | if (self.isVisible == YES) { 381 | if ([delegate respondsToSelector:@selector(imagePickerWillClose)]) { 382 | [delegate imagePickerWillClose]; 383 | } 384 | if (animated) { 385 | [UIView animateWithDuration:self.animationTime 386 | delay:0 387 | options:UIViewAnimationOptionCurveEaseIn 388 | animations:^{ 389 | [self.imagePickerView setFrame:self.hiddenFrame]; 390 | [self.backgroundView setAlpha:0]; 391 | } 392 | completion:^(BOOL finished) { 393 | [self.imagePickerView removeFromSuperview]; 394 | [self.backgroundView removeFromSuperview]; 395 | [self dismissViewControllerAnimated:NO completion:nil]; 396 | if ([delegate respondsToSelector:@selector(imagePickerDidClose)]) { 397 | [delegate imagePickerDidClose]; 398 | } 399 | }]; 400 | } else { 401 | [self.imagePickerView setFrame:self.imagePickerFrame]; 402 | [self.backgroundView setAlpha:0]; 403 | } 404 | 405 | // Set everything to nil 406 | } 407 | } 408 | 409 | @end 410 | 411 | #pragma mark - TransitionDelegate - 412 | @implementation TransitionDelegate 413 | 414 | - (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source 415 | { 416 | AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; 417 | controller.isPresenting = YES; 418 | return controller; 419 | } 420 | 421 | @end 422 | 423 | #pragma mark - AnimatedTransitioning - 424 | @implementation AnimatedTransitioning 425 | 426 | - (NSTimeInterval)transitionDuration:(id)transitionContext 427 | { 428 | return 0.25f; 429 | } 430 | 431 | - (void)animateTransition:(id)transitionContext 432 | { 433 | UIView *inView = [transitionContext containerView]; 434 | UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 435 | UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 436 | 437 | [inView addSubview:toVC.view]; 438 | 439 | CGRect screenRect = [[UIScreen mainScreen] bounds]; 440 | [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 441 | 442 | [UIView animateWithDuration:0.25f 443 | animations:^{ 444 | [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; 445 | } 446 | completion:^(BOOL finished) { 447 | [transitionContext completeTransition:YES]; 448 | }]; 449 | } 450 | 451 | @end 452 | 453 | #pragma mark - JSPhotoCell - 454 | @interface JSPhotoCell () 455 | 456 | @end 457 | 458 | @implementation JSPhotoCell 459 | 460 | @end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 jacobsieradzki 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 | # JSImagePickerController 2 | A photo picker controller that resembles the style of the image picker in iOS 8's messages app. 3 | 4 | ![Demo](https://github.com/jacobsieradzki/JSImagePickerController/blob/master/Demo.gif) 5 | 6 | ## Installation 7 | 8 | Just drop the two files for the JSImagePickerViewController class into your project and import them into whichever view controllers you want: 9 | 10 | ```Objective-C 11 | #import "JSImagePickerViewController.h" 12 | ``` 13 | 14 | Next, put this code in your project to create and show the image picker: 15 | 16 | ```Objective-C 17 | JSImagePickerViewController *imagePicker = [[JSImagePickerViewController alloc] init]; 18 | imagePicker.delegate = self; 19 | [imagePicker showImagePickerInController:self animated:YES]; 20 | ``` 21 | 22 | and add this delegate method to your code: 23 | 24 | ```Objective-C 25 | - (void)imagePicker:(JSImagePickerController)imagePicker didSelectImage:(UIImage *)image; 26 | ``` 27 | 28 | and if you want there are a choice of different delegate methods to choose from: 29 | 30 | ```Objective-C 31 | - (void)imagePickerDidOpen; 32 | - (void)imagePickerWillOpen; 33 | 34 | - (void)imagePickerWillClose; 35 | - (void)imagePickerDidClose; 36 | 37 | - (void)imagePickerDidCancel; 38 | ``` 39 | 40 | and for personalization you can edit the public propertys and methods of the image picker: 41 | 42 | ```Objective-C 43 | - (void)setAnimationTime:(NSTimeInterval)timeInterval; 44 | 45 | @property (nonatomic, strong) UICollectionView *collectionView; 46 | @property (nonatomic, strong) UIButton *photoLibraryBtn; 47 | @property (nonatomic, strong) UIButton *cameraBtn; 48 | @property (nonatomic, strong) UIButton *cancelBtn; 49 | ``` 50 | ## License 51 | 52 | You can use this freely in your projects as you wish but please email me at some point at jacob.sieradzki@gmail.com just so I can see how you have used it, thanks. 53 | 54 | ``` 55 | The MIT License (MIT) 56 | 57 | Copyright (c) 2015 jacobsieradzki 58 | 59 | Permission is hereby granted, free of charge, to any person obtaining a copy 60 | of this software and associated documentation files (the "Software"), to deal 61 | in the Software without restriction, including without limitation the rights 62 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 63 | copies of the Software, and to permit persons to whom the Software is 64 | furnished to do so, subject to the following conditions: 65 | 66 | The above copyright notice and this permission notice shall be included in all 67 | copies or substantial portions of the Software. 68 | 69 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 70 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 71 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 72 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 73 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 74 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 75 | SOFTWARE. 76 | ``` 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Screenshots/imagePicker1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jacobsieradzki/JSImagePickerController/099752cf30bb8e7d5f048d978d3f421ece5a7c88/Screenshots/imagePicker1.png --------------------------------------------------------------------------------