├── .gitignore ├── Demo ├── YRImagePickerDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── YRImagePickerDemo │ ├── Classes │ ├── AppDelegate.h │ ├── AppDelegate.m │ └── ViewControllers │ │ ├── DemoViewController.h │ │ └── DemoViewController.m │ ├── Resources │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Common │ │ │ └── Contents.json │ │ ├── Contents.json │ │ └── no_photo.imageset │ │ │ ├── Contents.json │ │ │ ├── no_photo.png │ │ │ └── no_photo@2x.png │ └── Storyboards │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ └── Supporting Files │ ├── Info.plist │ └── main.m ├── DemoImages └── demo.gif ├── LICENSE ├── README.md └── YRImagePicker ├── YRImagePicker.h └── YRImagePicker.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7D7F5D691C3E6BFE00351ABC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D7F5D5D1C3E6BFE00351ABC /* AppDelegate.m */; }; 11 | 7D7F5D6A1C3E6BFE00351ABC /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D7F5D601C3E6BFE00351ABC /* DemoViewController.m */; }; 12 | 7D7F5D6B1C3E6BFE00351ABC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D7F5D621C3E6BFE00351ABC /* Assets.xcassets */; }; 13 | 7D7F5D6C1C3E6BFE00351ABC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7D7F5D641C3E6BFE00351ABC /* LaunchScreen.storyboard */; }; 14 | 7D7F5D6D1C3E6BFE00351ABC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7D7F5D651C3E6BFE00351ABC /* Main.storyboard */; }; 15 | 7D7F5D6F1C3E6BFE00351ABC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D7F5D681C3E6BFE00351ABC /* main.m */; }; 16 | 7D7F5D741C3E89A900351ABC /* YRImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D7F5D731C3E89A900351ABC /* YRImagePicker.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 7D7F5D401C3E6A8900351ABC /* YRImagePickerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YRImagePickerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 7D7F5D5C1C3E6BFE00351ABC /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 22 | 7D7F5D5D1C3E6BFE00351ABC /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 23 | 7D7F5D5F1C3E6BFE00351ABC /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = ""; }; 24 | 7D7F5D601C3E6BFE00351ABC /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = ""; }; 25 | 7D7F5D621C3E6BFE00351ABC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 7D7F5D641C3E6BFE00351ABC /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 27 | 7D7F5D651C3E6BFE00351ABC /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 28 | 7D7F5D671C3E6BFE00351ABC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | 7D7F5D681C3E6BFE00351ABC /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 30 | 7D7F5D721C3E89A900351ABC /* YRImagePicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YRImagePicker.h; sourceTree = ""; }; 31 | 7D7F5D731C3E89A900351ABC /* YRImagePicker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YRImagePicker.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | 7D7F5D3D1C3E6A8900351ABC /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 7D7F5D371C3E6A8900351ABC = { 46 | isa = PBXGroup; 47 | children = ( 48 | 7D7F5D5A1C3E6BFE00351ABC /* YRImagePickerDemo */, 49 | 7D7F5D411C3E6A8900351ABC /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | 7D7F5D411C3E6A8900351ABC /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 7D7F5D401C3E6A8900351ABC /* YRImagePickerDemo.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | 7D7F5D5A1C3E6BFE00351ABC /* YRImagePickerDemo */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 7D7F5D5B1C3E6BFE00351ABC /* Classes */, 65 | 7D7F5D611C3E6BFE00351ABC /* Resources */, 66 | 7D7F5D661C3E6BFE00351ABC /* Supporting Files */, 67 | ); 68 | path = YRImagePickerDemo; 69 | sourceTree = ""; 70 | }; 71 | 7D7F5D5B1C3E6BFE00351ABC /* Classes */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 7D7F5D5C1C3E6BFE00351ABC /* AppDelegate.h */, 75 | 7D7F5D5D1C3E6BFE00351ABC /* AppDelegate.m */, 76 | 7D7F5D701C3E898900351ABC /* Components */, 77 | 7D7F5D5E1C3E6BFE00351ABC /* ViewControllers */, 78 | ); 79 | path = Classes; 80 | sourceTree = ""; 81 | }; 82 | 7D7F5D5E1C3E6BFE00351ABC /* ViewControllers */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 7D7F5D5F1C3E6BFE00351ABC /* DemoViewController.h */, 86 | 7D7F5D601C3E6BFE00351ABC /* DemoViewController.m */, 87 | ); 88 | path = ViewControllers; 89 | sourceTree = ""; 90 | }; 91 | 7D7F5D611C3E6BFE00351ABC /* Resources */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 7D7F5D621C3E6BFE00351ABC /* Assets.xcassets */, 95 | 7D7F5D631C3E6BFE00351ABC /* Storyboards */, 96 | ); 97 | path = Resources; 98 | sourceTree = ""; 99 | }; 100 | 7D7F5D631C3E6BFE00351ABC /* Storyboards */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 7D7F5D641C3E6BFE00351ABC /* LaunchScreen.storyboard */, 104 | 7D7F5D651C3E6BFE00351ABC /* Main.storyboard */, 105 | ); 106 | path = Storyboards; 107 | sourceTree = ""; 108 | }; 109 | 7D7F5D661C3E6BFE00351ABC /* Supporting Files */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 7D7F5D671C3E6BFE00351ABC /* Info.plist */, 113 | 7D7F5D681C3E6BFE00351ABC /* main.m */, 114 | ); 115 | path = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 7D7F5D701C3E898900351ABC /* Components */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 7D7F5D711C3E89A900351ABC /* YRImagePicker */, 122 | ); 123 | name = Components; 124 | sourceTree = ""; 125 | }; 126 | 7D7F5D711C3E89A900351ABC /* YRImagePicker */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 7D7F5D721C3E89A900351ABC /* YRImagePicker.h */, 130 | 7D7F5D731C3E89A900351ABC /* YRImagePicker.m */, 131 | ); 132 | name = YRImagePicker; 133 | path = ../../../YRImagePicker; 134 | sourceTree = ""; 135 | }; 136 | /* End PBXGroup section */ 137 | 138 | /* Begin PBXNativeTarget section */ 139 | 7D7F5D3F1C3E6A8900351ABC /* YRImagePickerDemo */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = 7D7F5D571C3E6A8900351ABC /* Build configuration list for PBXNativeTarget "YRImagePickerDemo" */; 142 | buildPhases = ( 143 | 7D7F5D3C1C3E6A8900351ABC /* Sources */, 144 | 7D7F5D3D1C3E6A8900351ABC /* Frameworks */, 145 | 7D7F5D3E1C3E6A8900351ABC /* Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | ); 151 | name = YRImagePickerDemo; 152 | productName = YRImagePickerDemo; 153 | productReference = 7D7F5D401C3E6A8900351ABC /* YRImagePickerDemo.app */; 154 | productType = "com.apple.product-type.application"; 155 | }; 156 | /* End PBXNativeTarget section */ 157 | 158 | /* Begin PBXProject section */ 159 | 7D7F5D381C3E6A8900351ABC /* Project object */ = { 160 | isa = PBXProject; 161 | attributes = { 162 | LastUpgradeCheck = 0720; 163 | ORGANIZATIONNAME = solomidSF; 164 | TargetAttributes = { 165 | 7D7F5D3F1C3E6A8900351ABC = { 166 | CreatedOnToolsVersion = 7.2; 167 | }; 168 | }; 169 | }; 170 | buildConfigurationList = 7D7F5D3B1C3E6A8900351ABC /* Build configuration list for PBXProject "YRImagePickerDemo" */; 171 | compatibilityVersion = "Xcode 3.2"; 172 | developmentRegion = English; 173 | hasScannedForEncodings = 0; 174 | knownRegions = ( 175 | en, 176 | Base, 177 | ); 178 | mainGroup = 7D7F5D371C3E6A8900351ABC; 179 | productRefGroup = 7D7F5D411C3E6A8900351ABC /* Products */; 180 | projectDirPath = ""; 181 | projectRoot = ""; 182 | targets = ( 183 | 7D7F5D3F1C3E6A8900351ABC /* YRImagePickerDemo */, 184 | ); 185 | }; 186 | /* End PBXProject section */ 187 | 188 | /* Begin PBXResourcesBuildPhase section */ 189 | 7D7F5D3E1C3E6A8900351ABC /* Resources */ = { 190 | isa = PBXResourcesBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | 7D7F5D6D1C3E6BFE00351ABC /* Main.storyboard in Resources */, 194 | 7D7F5D6B1C3E6BFE00351ABC /* Assets.xcassets in Resources */, 195 | 7D7F5D6C1C3E6BFE00351ABC /* LaunchScreen.storyboard in Resources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | /* End PBXResourcesBuildPhase section */ 200 | 201 | /* Begin PBXSourcesBuildPhase section */ 202 | 7D7F5D3C1C3E6A8900351ABC /* Sources */ = { 203 | isa = PBXSourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 7D7F5D6A1C3E6BFE00351ABC /* DemoViewController.m in Sources */, 207 | 7D7F5D6F1C3E6BFE00351ABC /* main.m in Sources */, 208 | 7D7F5D741C3E89A900351ABC /* YRImagePicker.m in Sources */, 209 | 7D7F5D691C3E6BFE00351ABC /* AppDelegate.m in Sources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | /* End PBXSourcesBuildPhase section */ 214 | 215 | /* Begin XCBuildConfiguration section */ 216 | 7D7F5D551C3E6A8900351ABC /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 221 | CLANG_CXX_LIBRARY = "libc++"; 222 | CLANG_ENABLE_MODULES = YES; 223 | CLANG_ENABLE_OBJC_ARC = YES; 224 | CLANG_WARN_BOOL_CONVERSION = YES; 225 | CLANG_WARN_CONSTANT_CONVERSION = YES; 226 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 227 | CLANG_WARN_EMPTY_BODY = YES; 228 | CLANG_WARN_ENUM_CONVERSION = YES; 229 | CLANG_WARN_INT_CONVERSION = YES; 230 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 231 | CLANG_WARN_UNREACHABLE_CODE = YES; 232 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 233 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 234 | COPY_PHASE_STRIP = NO; 235 | DEBUG_INFORMATION_FORMAT = dwarf; 236 | ENABLE_STRICT_OBJC_MSGSEND = YES; 237 | ENABLE_TESTABILITY = YES; 238 | GCC_C_LANGUAGE_STANDARD = gnu99; 239 | GCC_DYNAMIC_NO_PIC = NO; 240 | GCC_NO_COMMON_BLOCKS = YES; 241 | GCC_OPTIMIZATION_LEVEL = 0; 242 | GCC_PREPROCESSOR_DEFINITIONS = ( 243 | "DEBUG=1", 244 | "$(inherited)", 245 | ); 246 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 247 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 248 | GCC_WARN_UNDECLARED_SELECTOR = YES; 249 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 250 | GCC_WARN_UNUSED_FUNCTION = YES; 251 | GCC_WARN_UNUSED_VARIABLE = YES; 252 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 253 | MTL_ENABLE_DEBUG_INFO = YES; 254 | ONLY_ACTIVE_ARCH = YES; 255 | SDKROOT = iphoneos; 256 | }; 257 | name = Debug; 258 | }; 259 | 7D7F5D561C3E6A8900351ABC /* Release */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ALWAYS_SEARCH_USER_PATHS = NO; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_CONSTANT_CONVERSION = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_EMPTY_BODY = YES; 271 | CLANG_WARN_ENUM_CONVERSION = YES; 272 | CLANG_WARN_INT_CONVERSION = YES; 273 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 274 | CLANG_WARN_UNREACHABLE_CODE = YES; 275 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 276 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu99; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | SDKROOT = iphoneos; 292 | VALIDATE_PRODUCT = YES; 293 | }; 294 | name = Release; 295 | }; 296 | 7D7F5D581C3E6A8900351ABC /* Debug */ = { 297 | isa = XCBuildConfiguration; 298 | buildSettings = { 299 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 300 | INFOPLIST_FILE = "$(SRCROOT)/YRImagePickerDemo/Supporting Files/Info.plist"; 301 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 302 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 303 | PRODUCT_BUNDLE_IDENTIFIER = solomidSF.YRImagePickerDemo; 304 | PRODUCT_NAME = "$(TARGET_NAME)"; 305 | }; 306 | name = Debug; 307 | }; 308 | 7D7F5D591C3E6A8900351ABC /* Release */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 312 | INFOPLIST_FILE = "$(SRCROOT)/YRImagePickerDemo/Supporting Files/Info.plist"; 313 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 314 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 315 | PRODUCT_BUNDLE_IDENTIFIER = solomidSF.YRImagePickerDemo; 316 | PRODUCT_NAME = "$(TARGET_NAME)"; 317 | }; 318 | name = Release; 319 | }; 320 | /* End XCBuildConfiguration section */ 321 | 322 | /* Begin XCConfigurationList section */ 323 | 7D7F5D3B1C3E6A8900351ABC /* Build configuration list for PBXProject "YRImagePickerDemo" */ = { 324 | isa = XCConfigurationList; 325 | buildConfigurations = ( 326 | 7D7F5D551C3E6A8900351ABC /* Debug */, 327 | 7D7F5D561C3E6A8900351ABC /* Release */, 328 | ); 329 | defaultConfigurationIsVisible = 0; 330 | defaultConfigurationName = Release; 331 | }; 332 | 7D7F5D571C3E6A8900351ABC /* Build configuration list for PBXNativeTarget "YRImagePickerDemo" */ = { 333 | isa = XCConfigurationList; 334 | buildConfigurations = ( 335 | 7D7F5D581C3E6A8900351ABC /* Debug */, 336 | 7D7F5D591C3E6A8900351ABC /* Release */, 337 | ); 338 | defaultConfigurationIsVisible = 0; 339 | defaultConfigurationName = Release; 340 | }; 341 | /* End XCConfigurationList section */ 342 | }; 343 | rootObject = 7D7F5D381C3E6A8900351ABC /* Project object */; 344 | } 345 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // YRImagePickerDemo 4 | // 5 | // Created by Yuriy Romanchenko on 1/7/16. 6 | // Copyright © 2016 solomidSF. 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/YRImagePickerDemo/Classes/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // YRImagePickerDemo 4 | // 5 | // Created by Yuriy Romanchenko on 1/7/16. 6 | // Copyright © 2016 solomidSF. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 14 | // Override point for customization after application launch. 15 | return YES; 16 | } 17 | 18 | - (void)applicationWillResignActive:(UIApplication *)application { 19 | // 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. 20 | // 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. 21 | } 22 | 23 | - (void)applicationDidEnterBackground:(UIApplication *)application { 24 | // 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. 25 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 26 | } 27 | 28 | - (void)applicationWillEnterForeground:(UIApplication *)application { 29 | // 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. 30 | } 31 | 32 | - (void)applicationDidBecomeActive:(UIApplication *)application { 33 | // 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. 34 | } 35 | 36 | - (void)applicationWillTerminate:(UIApplication *)application { 37 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Classes/ViewControllers/DemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // YRImagePickerDemo 4 | // 5 | // Created by Yuriy Romanchenko on 1/7/16. 6 | // Copyright © 2016 solomidSF. All rights reserved. 7 | // 8 | 9 | @import UIKit; 10 | 11 | @interface DemoViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Classes/ViewControllers/DemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // YRImagePickerDemo 4 | // 5 | // Created by Yuriy Romanchenko on 1/7/16. 6 | // Copyright © 2016 solomidSF. All rights reserved. 7 | // 8 | 9 | // Controllers 10 | #import "DemoViewController.h" 11 | 12 | // Components 13 | #import "YRImagePicker.h" 14 | 15 | @interface DemoViewController () 16 | 17 | @end 18 | 19 | @implementation DemoViewController { 20 | __weak IBOutlet UIImageView *_pickedImageImageView; 21 | } 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view, typically from a nib. 26 | } 27 | 28 | - (IBAction)pickImageClicked:(id)sender { 29 | [YRImagePicker startPickingFromViewController:self 30 | sourceTypes:kYRImagePickerSourceTypeAll 31 | completion:^(UIImage *pickedImage) { 32 | _pickedImageImageView.image = pickedImage; 33 | }]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/Common/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/no_photo.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "no_photo.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "no_photo@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/no_photo.imageset/no_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomidSF/YRImagePicker/cb389f055ad4568af910704d4db6ffdf4057a5b1/Demo/YRImagePickerDemo/Resources/Assets.xcassets/no_photo.imageset/no_photo.png -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Assets.xcassets/no_photo.imageset/no_photo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomidSF/YRImagePicker/cb389f055ad4568af910704d4db6ffdf4057a5b1/Demo/YRImagePickerDemo/Resources/Assets.xcassets/no_photo.imageset/no_photo@2x.png -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Storyboards/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Resources/Storyboards/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 34 | 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 | -------------------------------------------------------------------------------- /Demo/YRImagePickerDemo/Supporting Files/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 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/YRImagePickerDemo/Supporting Files/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // YRImagePickerDemo 4 | // 5 | // Created by Yuriy Romanchenko on 1/7/16. 6 | // Copyright © 2016 solomidSF. 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 | -------------------------------------------------------------------------------- /DemoImages/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/solomidSF/YRImagePicker/cb389f055ad4568af910704d4db6ffdf4057a5b1/DemoImages/demo.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yuri R. 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 | # YRImagePicker 2 | `YRImagePicker` is a simple wrapper around default UIKit image picker. 3 | 4 | ## Description 5 | 6 | `YRImagePicker` encapsulates image picking using default `UIImagePickerController` saving your time to write default picking behaviour. 7 | 8 | ## Installation 9 | 10 | Simply drag&drop source into your project. 11 | 12 | ## Usage 13 | 14 | To start picking image you need to write... 0 lines of code! 15 | This requires a bit of setup in Interface Builder, but it's worth it. 16 | 17 | ![Usage example](/DemoImages/demo.gif) 18 | 19 | 1. Drag 'object' element into your view controller. 20 | 2. Set 'object' class to YRImagePicker 21 | 3. Navigate to connections tab of YRImagePicker and connect corresponding outlets. 22 | 4. Drag 'pickImageClicked:' action to button by which you want to instantiate image picking. 23 | 24 | Or you can use following code snipper: 25 | 26 | [YRImagePicker startPickingFromViewController:self 27 | sourceTypes:kYRImagePickerSourceTypeAll 28 | completion:^(UIImage *pickedImage) { 29 | <#Your image view#>.image = pickedImage; 30 | }]; 31 | 32 | 33 | ## Customization 34 | 35 | You can prompt user to pick image from specific place as defined by `YRImagePickerSourceType` 36 | 37 | typedef enum { 38 | kYRImagePickerSourceTypeNone = 0, 39 | kYRImagePickerSourceTypeCamera = 1 << 0, 40 | kYRImagePickerSourceTypePhotoLibrary = 1 << 1, 41 | kYRImagePickerSourceTypeSavedPhotosAlbum = 1 << 2, 42 | 43 | kYRImagePickerSourceTypeAll = 0x7, 44 | kYRImagePickerSourceTypeTypesMask = kYRImagePickerSourceTypeAll 45 | } YRImagePickerSourceType; 46 | 47 | ## Version 48 | 49 | v1.0.0 -------------------------------------------------------------------------------- /YRImagePicker/YRImagePicker.h: -------------------------------------------------------------------------------- 1 | // 2 | // YRImagePicker.h 3 | // 4 | // The MIT License (MIT) 5 | // 6 | // Copyright (c) 2015 Yuri R. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | 26 | @import UIKit; 27 | 28 | typedef void (^YRImagePickerCompletionBlock) (UIImage *pickedImage); 29 | 30 | typedef enum { 31 | kYRImagePickerSourceTypeNone = 0, 32 | kYRImagePickerSourceTypeCamera = 1 << 0, 33 | kYRImagePickerSourceTypePhotoLibrary = 1 << 1, 34 | kYRImagePickerSourceTypeSavedPhotosAlbum = 1 << 2, 35 | 36 | kYRImagePickerSourceTypeAll = 0x7, 37 | kYRImagePickerSourceTypeTypesMask = kYRImagePickerSourceTypeAll 38 | } YRImagePickerSourceType; 39 | 40 | /** 41 | * Simple image picker that encapsulates image picking from camera/photo library. 42 | */ 43 | @interface YRImagePicker : NSObject 44 | 45 | + (void)startPickingFromViewController:(UIViewController *)controller 46 | sourceTypes:(YRImagePickerSourceType)type 47 | completion:(YRImagePickerCompletionBlock)completion; 48 | 49 | - (void)startPickingFromViewController:(UIViewController *)controller 50 | sourceTypes:(YRImagePickerSourceType)type 51 | completion:(YRImagePickerCompletionBlock)completion; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /YRImagePicker/YRImagePicker.m: -------------------------------------------------------------------------------- 1 | // 2 | // YRImagePicker.m 3 | // 4 | // The MIT License (MIT) 5 | // 6 | // Copyright (c) 2015 Yuri R. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | 26 | // Components 27 | #import "YRImagePicker.h" 28 | 29 | // Other 30 | #import 31 | 32 | static const void *kYRImagePickerDummyKey = &kYRImagePickerDummyKey; 33 | 34 | @interface YRImagePicker () 35 | < 36 | UIActionSheetDelegate, 37 | UIImagePickerControllerDelegate, 38 | UINavigationControllerDelegate 39 | > 40 | @end 41 | 42 | @interface YRImagePicker () 43 | @property (nonatomic, weak) IBOutlet UIViewController *owner; 44 | @property (nonatomic, weak) IBOutlet UIImageView *destinationImageView; 45 | @end 46 | 47 | @implementation YRImagePicker { 48 | UIViewController __weak *_presenterController; 49 | YRImagePickerCompletionBlock _completionBlock; 50 | YRImagePickerSourceType _currentSourceTypes; 51 | 52 | BOOL _isPicking; 53 | } 54 | 55 | #pragma mark - Public 56 | 57 | + (void)startPickingFromViewController:(UIViewController *)controller 58 | sourceTypes:(YRImagePickerSourceType)types 59 | completion:(YRImagePickerCompletionBlock)completion { 60 | types = [self filterSourceTypesByAvailability:types]; 61 | 62 | if (types == kYRImagePickerSourceTypeNone) { 63 | return; 64 | } 65 | 66 | YRImagePicker *picker = objc_getAssociatedObject(controller, 67 | kYRImagePickerDummyKey); 68 | 69 | if (!picker) { 70 | picker = [self new]; 71 | } 72 | 73 | [picker startPickingFromViewController:controller sourceTypes:types completion:completion]; 74 | } 75 | 76 | - (void)startPickingFromViewController:(UIViewController *)controller 77 | sourceTypes:(YRImagePickerSourceType)types 78 | completion:(YRImagePickerCompletionBlock)completion { 79 | if (!_isPicking) { 80 | NSAssert(controller, @"[YRImagePicker]: Can't pick from nil controller."); 81 | 82 | // Retain current instance while picking stuff. 83 | objc_setAssociatedObject(controller, kYRImagePickerDummyKey, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 84 | 85 | _presenterController = controller; 86 | _completionBlock = completion; 87 | _currentSourceTypes = types; 88 | _isPicking = YES; 89 | 90 | UIAlertController *sheetController = [self sheetForSourceTypes:types]; 91 | 92 | if (sheetController) { 93 | [controller presentViewController:sheetController animated:YES completion:NULL]; 94 | } else { 95 | [self presentImagePickerWithSourceType:[[self class] pickerSourceTypeFromYRSourceType:types]]; 96 | } 97 | } else { 98 | NSLog(@"[YRImagePicker]: Can't start picking, because already picking from %@ controller", controller); 99 | } 100 | } 101 | 102 | #pragma mark - IBActions 103 | 104 | - (IBAction)pickImageClicked:(id)sender { 105 | NSAssert(self.owner, @"[YRImagePicker]: Couldn't find YRImagePicker owner (kindof UIViewController), probably you forgot to set it in storyboard/xib?"); 106 | NSAssert(self.destinationImageView, @"[YRImagePicker]: Couldn't find destination image view."); 107 | 108 | YRImagePickerSourceType resultingTypes = kYRImagePickerSourceTypeNone; 109 | 110 | if (_currentSourceTypes == kYRImagePickerSourceTypeNone) { 111 | resultingTypes = [[self class] filterSourceTypesByAvailability:kYRImagePickerSourceTypeAll]; 112 | } else { 113 | resultingTypes = [[self class] filterSourceTypesByAvailability:_currentSourceTypes]; 114 | } 115 | 116 | if (resultingTypes != kYRImagePickerSourceTypeNone) { 117 | [self startPickingFromViewController:self.owner 118 | sourceTypes:resultingTypes 119 | completion:^(UIImage *pickedImage) { 120 | _destinationImageView.image = pickedImage; 121 | }]; 122 | } 123 | } 124 | 125 | #pragma mark - Private 126 | 127 | + (YRImagePickerSourceType)filterSourceTypesByAvailability:(YRImagePickerSourceType)types { 128 | // First of all check if we have at least one type. 129 | NSAssert(types & kYRImagePickerSourceTypeTypesMask, @"[YRImagePicker]: You must specify source type for picking."); 130 | 131 | if (types & kYRImagePickerSourceTypeCamera) { 132 | if (![UIImagePickerController isSourceTypeAvailable:[self pickerSourceTypeFromYRSourceType:kYRImagePickerSourceTypeCamera]]) { 133 | types &= ~kYRImagePickerSourceTypeCamera; 134 | } 135 | } 136 | 137 | if (types & kYRImagePickerSourceTypePhotoLibrary) { 138 | if (![UIImagePickerController isSourceTypeAvailable:[self pickerSourceTypeFromYRSourceType:kYRImagePickerSourceTypePhotoLibrary]]) { 139 | types &= ~kYRImagePickerSourceTypePhotoLibrary; 140 | } 141 | } 142 | 143 | if (types & kYRImagePickerSourceTypeSavedPhotosAlbum) { 144 | if (![UIImagePickerController isSourceTypeAvailable:[self pickerSourceTypeFromYRSourceType:kYRImagePickerSourceTypeSavedPhotosAlbum]]) { 145 | types &= ~kYRImagePickerSourceTypeSavedPhotosAlbum; 146 | } 147 | } 148 | 149 | return types; 150 | } 151 | 152 | - (UIAlertController *)sheetForSourceTypes:(YRImagePickerSourceType)types { 153 | NSArray *readableTypes = [self readableSourceTypesFromSourceTypesEnumeration:types]; 154 | NSArray *sourceTypes = [self separatedSourceTypesFromType:types]; 155 | 156 | if (readableTypes.count > 1) { 157 | UIAlertController *resultingController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Pick from where?", @"") 158 | message:nil 159 | preferredStyle:UIAlertControllerStyleActionSheet]; 160 | 161 | [resultingController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"") 162 | style:UIAlertActionStyleCancel 163 | handler:^(UIAlertAction *action) { 164 | _isPicking = NO; 165 | _completionBlock = NULL; 166 | _currentSourceTypes = 0; 167 | 168 | objc_setAssociatedObject(_presenterController, 169 | kYRImagePickerDummyKey, 170 | nil, 171 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 172 | }]]; 173 | 174 | [readableTypes enumerateObjectsUsingBlock:^(NSString *readableType, NSUInteger idx, BOOL *stop) { 175 | void (^sheetAction)(UIAlertAction *action) = ^(UIAlertAction *action) { 176 | YRImagePickerSourceType pickedType = (YRImagePickerSourceType)[sourceTypes[idx] intValue]; 177 | 178 | [self presentImagePickerWithSourceType:[[self class] pickerSourceTypeFromYRSourceType:pickedType]]; 179 | }; 180 | 181 | UIAlertAction *action = [UIAlertAction actionWithTitle:readableType 182 | style:UIAlertActionStyleDefault 183 | handler:sheetAction]; 184 | 185 | [resultingController addAction:action]; 186 | }]; 187 | 188 | return resultingController; 189 | } else { 190 | // There is no need to create action sheet - only one source type specified. 191 | return nil; 192 | } 193 | } 194 | 195 | - (NSArray *)readableSourceTypesFromSourceTypesEnumeration:(YRImagePickerSourceType)types { 196 | NSMutableArray *resultingSourceTypes = [NSMutableArray new]; 197 | 198 | if (types & kYRImagePickerSourceTypeCamera) { 199 | [resultingSourceTypes addObject:@"Camera"]; 200 | } 201 | 202 | if (types & kYRImagePickerSourceTypePhotoLibrary) { 203 | [resultingSourceTypes addObject:@"Photo Library"]; 204 | } 205 | 206 | if (types & kYRImagePickerSourceTypeSavedPhotosAlbum) { 207 | [resultingSourceTypes addObject:@"Saved Photos Album"]; 208 | } 209 | 210 | return [NSArray arrayWithArray:resultingSourceTypes]; 211 | } 212 | 213 | - (void)presentImagePickerWithSourceType:(UIImagePickerControllerSourceType)type { 214 | UIImagePickerController *pickerController = [UIImagePickerController new]; 215 | 216 | pickerController.delegate = self; 217 | pickerController.sourceType = type; 218 | 219 | [_presenterController presentViewController:pickerController 220 | animated:YES 221 | completion:NULL]; 222 | } 223 | 224 | - (NSArray *)separatedSourceTypesFromType:(YRImagePickerSourceType)types { 225 | NSMutableArray *resultingSourceTypes = [NSMutableArray new]; 226 | 227 | if (types & kYRImagePickerSourceTypeCamera) { 228 | [resultingSourceTypes addObject:@(kYRImagePickerSourceTypeCamera)]; 229 | } 230 | 231 | if (types & kYRImagePickerSourceTypePhotoLibrary) { 232 | [resultingSourceTypes addObject:@(kYRImagePickerSourceTypePhotoLibrary)]; 233 | } 234 | 235 | if (types & kYRImagePickerSourceTypeSavedPhotosAlbum) { 236 | [resultingSourceTypes addObject:@(kYRImagePickerSourceTypeSavedPhotosAlbum)]; 237 | } 238 | 239 | return [NSArray arrayWithArray:resultingSourceTypes]; 240 | } 241 | 242 | + (UIImagePickerControllerSourceType)pickerSourceTypeFromYRSourceType:(YRImagePickerSourceType)type { 243 | if (type & kYRImagePickerSourceTypeCamera) { 244 | return UIImagePickerControllerSourceTypeCamera; 245 | } else if (type & kYRImagePickerSourceTypePhotoLibrary) { 246 | return UIImagePickerControllerSourceTypePhotoLibrary; 247 | } else if (type & kYRImagePickerSourceTypeSavedPhotosAlbum) { 248 | return UIImagePickerControllerSourceTypeSavedPhotosAlbum; 249 | } else { 250 | NSAssert(NO, @"Couldn't transform YRImagePickerSourceType to UIImagePickerControllerSourceType!"); 251 | return NSNotFound; 252 | } 253 | } 254 | 255 | #pragma mark - UIImagePickerControllerDelegate 256 | 257 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 258 | _isPicking = NO; 259 | _completionBlock = NULL; 260 | _currentSourceTypes = kYRImagePickerSourceTypeNone; 261 | 262 | [picker dismissViewControllerAnimated:YES 263 | completion:^{ 264 | // Remove strong reference from controller to current instance. 265 | objc_setAssociatedObject(_presenterController, 266 | kYRImagePickerDummyKey, 267 | nil, 268 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 269 | }]; 270 | } 271 | 272 | - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 273 | [picker dismissViewControllerAnimated:YES 274 | completion:^{ 275 | !_completionBlock ? : _completionBlock(info[UIImagePickerControllerOriginalImage]); 276 | _isPicking = NO; 277 | _completionBlock = NULL; 278 | _currentSourceTypes = kYRImagePickerSourceTypeNone; 279 | 280 | // Remove strong reference from controller to current instance. 281 | objc_setAssociatedObject(_presenterController, 282 | kYRImagePickerDummyKey, 283 | nil, 284 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 285 | }]; 286 | } 287 | 288 | @end 289 | --------------------------------------------------------------------------------