├── JFImagePicker.podspec ├── JFImagePickerController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── JFImagePickerController.xccheckout │ └── xcuserdata │ │ └── Johnil.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ └── Johnil.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── JFImagePickerController.xcscheme │ └── xcschememanagement.plist ├── JFImagePickerController ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── JFImagePickerController │ ├── JFAssetHelper.h │ ├── JFAssetHelper.m │ ├── JFImageCollectionViewController.h │ ├── JFImageCollectionViewController.m │ ├── JFImageGroupTableViewController.h │ ├── JFImageGroupTableViewController.m │ ├── JFImageManager.h │ ├── JFImageManager.m │ ├── JFImagePickerController.h │ ├── JFImagePickerController.m │ ├── JFImagePickerViewCell.h │ ├── JFImagePickerViewCell.m │ ├── JFPhotoBrowserViewController.h │ ├── JFPhotoBrowserViewController.m │ ├── JFPhotoView.h │ └── JFPhotoView.m ├── ViewController.h ├── ViewController.m └── main.m ├── JFImagePickerControllerTests ├── Info.plist └── JFImagePickerControllerTests.m ├── LICENSE ├── README.md └── assets ├── screenshot1.png └── screenshot2.png /JFImagePicker.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'JFImagePicker' 3 | s.version = '1.0.0' 4 | s.license = 'MIT' 5 | s.summary = 'A fast ImagePicker for iOS.' 6 | s.homepage = 'https://github.com/johnil/JFImagePickerController' 7 | s.social_media_url = 'http://weibo.com/u/3732851864' 8 | s.authors = { 'Johnil' => 'johnil@me.com' } 9 | s.source = { :git => 'https://github.com/johnil/JFImagePickerController.git', :tag => s.version, :submodules => true } 10 | s.requires_arc = true 11 | 12 | s.ios.deployment_target = '7.0' 13 | 14 | s.source_files = 'JFImagePickerController/JFImagePickerController/*' 15 | 16 | s.frameworks = 'Foundation', 'CoreGraphics', 'UIKit', 'ImageIO', 'AssetsLibrary' 17 | 18 | end 19 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C4BC0E991B463C4E00162734 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0E981B463C4E00162734 /* main.m */; }; 11 | C4BC0E9C1B463C4E00162734 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0E9B1B463C4E00162734 /* AppDelegate.m */; }; 12 | C4BC0E9F1B463C4E00162734 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0E9E1B463C4E00162734 /* ViewController.m */; }; 13 | C4BC0EA21B463C4E00162734 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C4BC0EA01B463C4E00162734 /* Main.storyboard */; }; 14 | C4BC0EA41B463C4E00162734 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C4BC0EA31B463C4E00162734 /* Images.xcassets */; }; 15 | C4BC0EA71B463C4E00162734 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = C4BC0EA51B463C4E00162734 /* LaunchScreen.xib */; }; 16 | C4BC0EB31B463C4F00162734 /* JFImagePickerControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EB21B463C4F00162734 /* JFImagePickerControllerTests.m */; }; 17 | C4BC0EC91B463C8B00162734 /* JFImageCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EBE1B463C8B00162734 /* JFImageCollectionViewController.m */; }; 18 | C4BC0ECA1B463C8B00162734 /* JFImageGroupTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EC01B463C8B00162734 /* JFImageGroupTableViewController.m */; }; 19 | C4BC0ECB1B463C8B00162734 /* JFImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EC21B463C8B00162734 /* JFImagePickerController.m */; }; 20 | C4BC0ECC1B463C8B00162734 /* JFImagePickerViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EC41B463C8B00162734 /* JFImagePickerViewCell.m */; }; 21 | C4BC0ECD1B463C8B00162734 /* JFPhotoBrowserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EC61B463C8B00162734 /* JFPhotoBrowserViewController.m */; }; 22 | C4BC0ECE1B463C8B00162734 /* JFAssetHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0EC81B463C8B00162734 /* JFAssetHelper.m */; }; 23 | C4BC0ED11B463DA600162734 /* JFPhotoView.m in Sources */ = {isa = PBXBuildFile; fileRef = C4BC0ED01B463DA600162734 /* JFPhotoView.m */; }; 24 | C4F4C98B1B47A25E009FC9D7 /* JFImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C4F4C98A1B47A25E009FC9D7 /* JFImageManager.m */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXContainerItemProxy section */ 28 | C4BC0EAD1B463C4F00162734 /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = C4BC0E8B1B463C4E00162734 /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = C4BC0E921B463C4E00162734; 33 | remoteInfo = JFImagePickerController; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | C4BC0E931B463C4E00162734 /* JFImagePickerController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JFImagePickerController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | C4BC0E971B463C4E00162734 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | C4BC0E981B463C4E00162734 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 41 | C4BC0E9A1B463C4E00162734 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 42 | C4BC0E9B1B463C4E00162734 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43 | C4BC0E9D1B463C4E00162734 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 44 | C4BC0E9E1B463C4E00162734 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 45 | C4BC0EA11B463C4E00162734 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | C4BC0EA31B463C4E00162734 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 47 | C4BC0EA61B463C4E00162734 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 48 | C4BC0EAC1B463C4F00162734 /* JFImagePickerControllerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JFImagePickerControllerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | C4BC0EB11B463C4F00162734 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | C4BC0EB21B463C4F00162734 /* JFImagePickerControllerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JFImagePickerControllerTests.m; sourceTree = ""; }; 51 | C4BC0EBD1B463C8B00162734 /* JFImageCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImageCollectionViewController.h; sourceTree = ""; }; 52 | C4BC0EBE1B463C8B00162734 /* JFImageCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImageCollectionViewController.m; sourceTree = ""; }; 53 | C4BC0EBF1B463C8B00162734 /* JFImageGroupTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImageGroupTableViewController.h; sourceTree = ""; }; 54 | C4BC0EC01B463C8B00162734 /* JFImageGroupTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImageGroupTableViewController.m; sourceTree = ""; }; 55 | C4BC0EC11B463C8B00162734 /* JFImagePickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImagePickerController.h; sourceTree = ""; }; 56 | C4BC0EC21B463C8B00162734 /* JFImagePickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImagePickerController.m; sourceTree = ""; }; 57 | C4BC0EC31B463C8B00162734 /* JFImagePickerViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImagePickerViewCell.h; sourceTree = ""; }; 58 | C4BC0EC41B463C8B00162734 /* JFImagePickerViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImagePickerViewCell.m; sourceTree = ""; }; 59 | C4BC0EC51B463C8B00162734 /* JFPhotoBrowserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFPhotoBrowserViewController.h; sourceTree = ""; }; 60 | C4BC0EC61B463C8B00162734 /* JFPhotoBrowserViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFPhotoBrowserViewController.m; sourceTree = ""; }; 61 | C4BC0EC71B463C8B00162734 /* JFAssetHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFAssetHelper.h; sourceTree = ""; }; 62 | C4BC0EC81B463C8B00162734 /* JFAssetHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFAssetHelper.m; sourceTree = ""; }; 63 | C4BC0ECF1B463DA600162734 /* JFPhotoView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFPhotoView.h; sourceTree = ""; }; 64 | C4BC0ED01B463DA600162734 /* JFPhotoView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFPhotoView.m; sourceTree = ""; }; 65 | C4F4C9891B47A25E009FC9D7 /* JFImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImageManager.h; sourceTree = ""; }; 66 | C4F4C98A1B47A25E009FC9D7 /* JFImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImageManager.m; sourceTree = ""; }; 67 | /* End PBXFileReference section */ 68 | 69 | /* Begin PBXFrameworksBuildPhase section */ 70 | C4BC0E901B463C4E00162734 /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | C4BC0EA91B463C4F00162734 /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | C4BC0E8A1B463C4E00162734 = { 88 | isa = PBXGroup; 89 | children = ( 90 | C4BC0E951B463C4E00162734 /* JFImagePickerController */, 91 | C4BC0EAF1B463C4F00162734 /* JFImagePickerControllerTests */, 92 | C4BC0E941B463C4E00162734 /* Products */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | C4BC0E941B463C4E00162734 /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | C4BC0E931B463C4E00162734 /* JFImagePickerController.app */, 100 | C4BC0EAC1B463C4F00162734 /* JFImagePickerControllerTests.xctest */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | C4BC0E951B463C4E00162734 /* JFImagePickerController */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | C4BC0EBC1B463C8B00162734 /* classes */, 109 | C4BC0E9A1B463C4E00162734 /* AppDelegate.h */, 110 | C4BC0E9B1B463C4E00162734 /* AppDelegate.m */, 111 | C4BC0E9D1B463C4E00162734 /* ViewController.h */, 112 | C4BC0E9E1B463C4E00162734 /* ViewController.m */, 113 | C4BC0EA01B463C4E00162734 /* Main.storyboard */, 114 | C4BC0EA31B463C4E00162734 /* Images.xcassets */, 115 | C4BC0EA51B463C4E00162734 /* LaunchScreen.xib */, 116 | C4BC0E961B463C4E00162734 /* Supporting Files */, 117 | ); 118 | path = JFImagePickerController; 119 | sourceTree = ""; 120 | }; 121 | C4BC0E961B463C4E00162734 /* Supporting Files */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | C4BC0E971B463C4E00162734 /* Info.plist */, 125 | C4BC0E981B463C4E00162734 /* main.m */, 126 | ); 127 | name = "Supporting Files"; 128 | sourceTree = ""; 129 | }; 130 | C4BC0EAF1B463C4F00162734 /* JFImagePickerControllerTests */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | C4BC0EB21B463C4F00162734 /* JFImagePickerControllerTests.m */, 134 | C4BC0EB01B463C4F00162734 /* Supporting Files */, 135 | ); 136 | path = JFImagePickerControllerTests; 137 | sourceTree = ""; 138 | }; 139 | C4BC0EB01B463C4F00162734 /* Supporting Files */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | C4BC0EB11B463C4F00162734 /* Info.plist */, 143 | ); 144 | name = "Supporting Files"; 145 | sourceTree = ""; 146 | }; 147 | C4BC0EBC1B463C8B00162734 /* classes */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | C4BC0EBD1B463C8B00162734 /* JFImageCollectionViewController.h */, 151 | C4BC0EBE1B463C8B00162734 /* JFImageCollectionViewController.m */, 152 | C4BC0EBF1B463C8B00162734 /* JFImageGroupTableViewController.h */, 153 | C4BC0EC01B463C8B00162734 /* JFImageGroupTableViewController.m */, 154 | C4BC0EC11B463C8B00162734 /* JFImagePickerController.h */, 155 | C4BC0EC21B463C8B00162734 /* JFImagePickerController.m */, 156 | C4BC0EC31B463C8B00162734 /* JFImagePickerViewCell.h */, 157 | C4BC0EC41B463C8B00162734 /* JFImagePickerViewCell.m */, 158 | C4BC0EC51B463C8B00162734 /* JFPhotoBrowserViewController.h */, 159 | C4BC0EC61B463C8B00162734 /* JFPhotoBrowserViewController.m */, 160 | C4BC0ECF1B463DA600162734 /* JFPhotoView.h */, 161 | C4BC0ED01B463DA600162734 /* JFPhotoView.m */, 162 | C4BC0EC71B463C8B00162734 /* JFAssetHelper.h */, 163 | C4BC0EC81B463C8B00162734 /* JFAssetHelper.m */, 164 | C4F4C9891B47A25E009FC9D7 /* JFImageManager.h */, 165 | C4F4C98A1B47A25E009FC9D7 /* JFImageManager.m */, 166 | ); 167 | name = classes; 168 | path = JFImagePickerController; 169 | sourceTree = ""; 170 | }; 171 | /* End PBXGroup section */ 172 | 173 | /* Begin PBXNativeTarget section */ 174 | C4BC0E921B463C4E00162734 /* JFImagePickerController */ = { 175 | isa = PBXNativeTarget; 176 | buildConfigurationList = C4BC0EB61B463C4F00162734 /* Build configuration list for PBXNativeTarget "JFImagePickerController" */; 177 | buildPhases = ( 178 | C4BC0E8F1B463C4E00162734 /* Sources */, 179 | C4BC0E901B463C4E00162734 /* Frameworks */, 180 | C4BC0E911B463C4E00162734 /* Resources */, 181 | ); 182 | buildRules = ( 183 | ); 184 | dependencies = ( 185 | ); 186 | name = JFImagePickerController; 187 | productName = JFImagePickerController; 188 | productReference = C4BC0E931B463C4E00162734 /* JFImagePickerController.app */; 189 | productType = "com.apple.product-type.application"; 190 | }; 191 | C4BC0EAB1B463C4F00162734 /* JFImagePickerControllerTests */ = { 192 | isa = PBXNativeTarget; 193 | buildConfigurationList = C4BC0EB91B463C4F00162734 /* Build configuration list for PBXNativeTarget "JFImagePickerControllerTests" */; 194 | buildPhases = ( 195 | C4BC0EA81B463C4F00162734 /* Sources */, 196 | C4BC0EA91B463C4F00162734 /* Frameworks */, 197 | C4BC0EAA1B463C4F00162734 /* Resources */, 198 | ); 199 | buildRules = ( 200 | ); 201 | dependencies = ( 202 | C4BC0EAE1B463C4F00162734 /* PBXTargetDependency */, 203 | ); 204 | name = JFImagePickerControllerTests; 205 | productName = JFImagePickerControllerTests; 206 | productReference = C4BC0EAC1B463C4F00162734 /* JFImagePickerControllerTests.xctest */; 207 | productType = "com.apple.product-type.bundle.unit-test"; 208 | }; 209 | /* End PBXNativeTarget section */ 210 | 211 | /* Begin PBXProject section */ 212 | C4BC0E8B1B463C4E00162734 /* Project object */ = { 213 | isa = PBXProject; 214 | attributes = { 215 | LastUpgradeCheck = 0630; 216 | ORGANIZATIONNAME = Johnil; 217 | TargetAttributes = { 218 | C4BC0E921B463C4E00162734 = { 219 | CreatedOnToolsVersion = 6.3.2; 220 | }; 221 | C4BC0EAB1B463C4F00162734 = { 222 | CreatedOnToolsVersion = 6.3.2; 223 | TestTargetID = C4BC0E921B463C4E00162734; 224 | }; 225 | }; 226 | }; 227 | buildConfigurationList = C4BC0E8E1B463C4E00162734 /* Build configuration list for PBXProject "JFImagePickerController" */; 228 | compatibilityVersion = "Xcode 3.2"; 229 | developmentRegion = English; 230 | hasScannedForEncodings = 0; 231 | knownRegions = ( 232 | en, 233 | Base, 234 | ); 235 | mainGroup = C4BC0E8A1B463C4E00162734; 236 | productRefGroup = C4BC0E941B463C4E00162734 /* Products */; 237 | projectDirPath = ""; 238 | projectRoot = ""; 239 | targets = ( 240 | C4BC0E921B463C4E00162734 /* JFImagePickerController */, 241 | C4BC0EAB1B463C4F00162734 /* JFImagePickerControllerTests */, 242 | ); 243 | }; 244 | /* End PBXProject section */ 245 | 246 | /* Begin PBXResourcesBuildPhase section */ 247 | C4BC0E911B463C4E00162734 /* Resources */ = { 248 | isa = PBXResourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | C4BC0EA21B463C4E00162734 /* Main.storyboard in Resources */, 252 | C4BC0EA71B463C4E00162734 /* LaunchScreen.xib in Resources */, 253 | C4BC0EA41B463C4E00162734 /* Images.xcassets in Resources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | C4BC0EAA1B463C4F00162734 /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXResourcesBuildPhase section */ 265 | 266 | /* Begin PBXSourcesBuildPhase section */ 267 | C4BC0E8F1B463C4E00162734 /* Sources */ = { 268 | isa = PBXSourcesBuildPhase; 269 | buildActionMask = 2147483647; 270 | files = ( 271 | C4BC0ECE1B463C8B00162734 /* JFAssetHelper.m in Sources */, 272 | C4F4C98B1B47A25E009FC9D7 /* JFImageManager.m in Sources */, 273 | C4BC0ECA1B463C8B00162734 /* JFImageGroupTableViewController.m in Sources */, 274 | C4BC0E9F1B463C4E00162734 /* ViewController.m in Sources */, 275 | C4BC0ECC1B463C8B00162734 /* JFImagePickerViewCell.m in Sources */, 276 | C4BC0EC91B463C8B00162734 /* JFImageCollectionViewController.m in Sources */, 277 | C4BC0E9C1B463C4E00162734 /* AppDelegate.m in Sources */, 278 | C4BC0ECD1B463C8B00162734 /* JFPhotoBrowserViewController.m in Sources */, 279 | C4BC0ED11B463DA600162734 /* JFPhotoView.m in Sources */, 280 | C4BC0ECB1B463C8B00162734 /* JFImagePickerController.m in Sources */, 281 | C4BC0E991B463C4E00162734 /* main.m in Sources */, 282 | ); 283 | runOnlyForDeploymentPostprocessing = 0; 284 | }; 285 | C4BC0EA81B463C4F00162734 /* Sources */ = { 286 | isa = PBXSourcesBuildPhase; 287 | buildActionMask = 2147483647; 288 | files = ( 289 | C4BC0EB31B463C4F00162734 /* JFImagePickerControllerTests.m in Sources */, 290 | ); 291 | runOnlyForDeploymentPostprocessing = 0; 292 | }; 293 | /* End PBXSourcesBuildPhase section */ 294 | 295 | /* Begin PBXTargetDependency section */ 296 | C4BC0EAE1B463C4F00162734 /* PBXTargetDependency */ = { 297 | isa = PBXTargetDependency; 298 | target = C4BC0E921B463C4E00162734 /* JFImagePickerController */; 299 | targetProxy = C4BC0EAD1B463C4F00162734 /* PBXContainerItemProxy */; 300 | }; 301 | /* End PBXTargetDependency section */ 302 | 303 | /* Begin PBXVariantGroup section */ 304 | C4BC0EA01B463C4E00162734 /* Main.storyboard */ = { 305 | isa = PBXVariantGroup; 306 | children = ( 307 | C4BC0EA11B463C4E00162734 /* Base */, 308 | ); 309 | name = Main.storyboard; 310 | sourceTree = ""; 311 | }; 312 | C4BC0EA51B463C4E00162734 /* LaunchScreen.xib */ = { 313 | isa = PBXVariantGroup; 314 | children = ( 315 | C4BC0EA61B463C4E00162734 /* Base */, 316 | ); 317 | name = LaunchScreen.xib; 318 | sourceTree = ""; 319 | }; 320 | /* End PBXVariantGroup section */ 321 | 322 | /* Begin XCBuildConfiguration section */ 323 | C4BC0EB41B463C4F00162734 /* Debug */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ALWAYS_SEARCH_USER_PATHS = NO; 327 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 328 | CLANG_CXX_LIBRARY = "libc++"; 329 | CLANG_ENABLE_MODULES = YES; 330 | CLANG_ENABLE_OBJC_ARC = YES; 331 | CLANG_WARN_BOOL_CONVERSION = YES; 332 | CLANG_WARN_CONSTANT_CONVERSION = YES; 333 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 334 | CLANG_WARN_EMPTY_BODY = YES; 335 | CLANG_WARN_ENUM_CONVERSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 338 | CLANG_WARN_UNREACHABLE_CODE = YES; 339 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 340 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 341 | COPY_PHASE_STRIP = NO; 342 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 343 | ENABLE_STRICT_OBJC_MSGSEND = YES; 344 | GCC_C_LANGUAGE_STANDARD = gnu99; 345 | GCC_DYNAMIC_NO_PIC = NO; 346 | GCC_NO_COMMON_BLOCKS = YES; 347 | GCC_OPTIMIZATION_LEVEL = 0; 348 | GCC_PREPROCESSOR_DEFINITIONS = ( 349 | "DEBUG=1", 350 | "$(inherited)", 351 | ); 352 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 353 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 354 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 355 | GCC_WARN_UNDECLARED_SELECTOR = YES; 356 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 357 | GCC_WARN_UNUSED_FUNCTION = YES; 358 | GCC_WARN_UNUSED_VARIABLE = YES; 359 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 360 | MTL_ENABLE_DEBUG_INFO = YES; 361 | ONLY_ACTIVE_ARCH = YES; 362 | SDKROOT = iphoneos; 363 | }; 364 | name = Debug; 365 | }; 366 | C4BC0EB51B463C4F00162734 /* Release */ = { 367 | isa = XCBuildConfiguration; 368 | buildSettings = { 369 | ALWAYS_SEARCH_USER_PATHS = NO; 370 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 371 | CLANG_CXX_LIBRARY = "libc++"; 372 | CLANG_ENABLE_MODULES = YES; 373 | CLANG_ENABLE_OBJC_ARC = YES; 374 | CLANG_WARN_BOOL_CONVERSION = YES; 375 | CLANG_WARN_CONSTANT_CONVERSION = YES; 376 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 377 | CLANG_WARN_EMPTY_BODY = YES; 378 | CLANG_WARN_ENUM_CONVERSION = YES; 379 | CLANG_WARN_INT_CONVERSION = YES; 380 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 381 | CLANG_WARN_UNREACHABLE_CODE = YES; 382 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 384 | COPY_PHASE_STRIP = NO; 385 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 386 | ENABLE_NS_ASSERTIONS = NO; 387 | ENABLE_STRICT_OBJC_MSGSEND = YES; 388 | GCC_C_LANGUAGE_STANDARD = gnu99; 389 | GCC_NO_COMMON_BLOCKS = YES; 390 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 391 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 392 | GCC_WARN_UNDECLARED_SELECTOR = YES; 393 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 394 | GCC_WARN_UNUSED_FUNCTION = YES; 395 | GCC_WARN_UNUSED_VARIABLE = YES; 396 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 397 | MTL_ENABLE_DEBUG_INFO = NO; 398 | SDKROOT = iphoneos; 399 | VALIDATE_PRODUCT = YES; 400 | }; 401 | name = Release; 402 | }; 403 | C4BC0EB71B463C4F00162734 /* Debug */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 407 | INFOPLIST_FILE = JFImagePickerController/Info.plist; 408 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 409 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 410 | PRODUCT_NAME = "$(TARGET_NAME)"; 411 | }; 412 | name = Debug; 413 | }; 414 | C4BC0EB81B463C4F00162734 /* Release */ = { 415 | isa = XCBuildConfiguration; 416 | buildSettings = { 417 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 418 | INFOPLIST_FILE = JFImagePickerController/Info.plist; 419 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 420 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | }; 423 | name = Release; 424 | }; 425 | C4BC0EBA1B463C4F00162734 /* Debug */ = { 426 | isa = XCBuildConfiguration; 427 | buildSettings = { 428 | BUNDLE_LOADER = "$(TEST_HOST)"; 429 | FRAMEWORK_SEARCH_PATHS = ( 430 | "$(SDKROOT)/Developer/Library/Frameworks", 431 | "$(inherited)", 432 | ); 433 | GCC_PREPROCESSOR_DEFINITIONS = ( 434 | "DEBUG=1", 435 | "$(inherited)", 436 | ); 437 | INFOPLIST_FILE = JFImagePickerControllerTests/Info.plist; 438 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JFImagePickerController.app/JFImagePickerController"; 441 | }; 442 | name = Debug; 443 | }; 444 | C4BC0EBB1B463C4F00162734 /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | buildSettings = { 447 | BUNDLE_LOADER = "$(TEST_HOST)"; 448 | FRAMEWORK_SEARCH_PATHS = ( 449 | "$(SDKROOT)/Developer/Library/Frameworks", 450 | "$(inherited)", 451 | ); 452 | INFOPLIST_FILE = JFImagePickerControllerTests/Info.plist; 453 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 454 | PRODUCT_NAME = "$(TARGET_NAME)"; 455 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JFImagePickerController.app/JFImagePickerController"; 456 | }; 457 | name = Release; 458 | }; 459 | /* End XCBuildConfiguration section */ 460 | 461 | /* Begin XCConfigurationList section */ 462 | C4BC0E8E1B463C4E00162734 /* Build configuration list for PBXProject "JFImagePickerController" */ = { 463 | isa = XCConfigurationList; 464 | buildConfigurations = ( 465 | C4BC0EB41B463C4F00162734 /* Debug */, 466 | C4BC0EB51B463C4F00162734 /* Release */, 467 | ); 468 | defaultConfigurationIsVisible = 0; 469 | defaultConfigurationName = Release; 470 | }; 471 | C4BC0EB61B463C4F00162734 /* Build configuration list for PBXNativeTarget "JFImagePickerController" */ = { 472 | isa = XCConfigurationList; 473 | buildConfigurations = ( 474 | C4BC0EB71B463C4F00162734 /* Debug */, 475 | C4BC0EB81B463C4F00162734 /* Release */, 476 | ); 477 | defaultConfigurationIsVisible = 0; 478 | defaultConfigurationName = Release; 479 | }; 480 | C4BC0EB91B463C4F00162734 /* Build configuration list for PBXNativeTarget "JFImagePickerControllerTests" */ = { 481 | isa = XCConfigurationList; 482 | buildConfigurations = ( 483 | C4BC0EBA1B463C4F00162734 /* Debug */, 484 | C4BC0EBB1B463C4F00162734 /* Release */, 485 | ); 486 | defaultConfigurationIsVisible = 0; 487 | defaultConfigurationName = Release; 488 | }; 489 | /* End XCConfigurationList section */ 490 | }; 491 | rootObject = C4BC0E8B1B463C4E00162734 /* Project object */; 492 | } 493 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/project.xcworkspace/xcshareddata/JFImagePickerController.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | EE6A9060-C0D4-4CF1-8747-4609FF588230 9 | IDESourceControlProjectName 10 | JFImagePickerController 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 8BC251A96E85864817CAA82AB36D47B2992CC535 14 | https://github.com/johnil/JFImagePickerController.git 15 | 16 | IDESourceControlProjectPath 17 | JFImagePickerController.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 8BC251A96E85864817CAA82AB36D47B2992CC535 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/johnil/JFImagePickerController.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 8BC251A96E85864817CAA82AB36D47B2992CC535 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 8BC251A96E85864817CAA82AB36D47B2992CC535 36 | IDESourceControlWCCName 37 | JFImagePickerController 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/project.xcworkspace/xcuserdata/Johnil.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnil/JFImagePickerController/a6df67631927239af3f1a470ae4e43a16986374c/JFImagePickerController.xcodeproj/project.xcworkspace/xcuserdata/Johnil.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/project.xcworkspace/xcuserdata/Johnil.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/xcuserdata/Johnil.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/xcuserdata/Johnil.xcuserdatad/xcschemes/JFImagePickerController.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 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /JFImagePickerController.xcodeproj/xcuserdata/Johnil.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | JFImagePickerController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C4BC0E921B463C4E00162734 16 | 17 | primary 18 | 19 | 20 | C4BC0EAB1B463C4F00162734 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /JFImagePickerController/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. 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 | -------------------------------------------------------------------------------- /JFImagePickerController/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. 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 | return YES; 20 | } 21 | 22 | - (void)applicationWillResignActive:(UIApplication *)application { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | - (void)applicationDidEnterBackground:(UIApplication *)application { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | - (void)applicationWillEnterForeground:(UIApplication *)application { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | - (void)applicationWillTerminate:(UIApplication *)application { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /JFImagePickerController/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 | -------------------------------------------------------------------------------- /JFImagePickerController/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /JFImagePickerController/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 | } -------------------------------------------------------------------------------- /JFImagePickerController/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.Johnil.$(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 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UIViewControllerBasedStatusBarAppearance 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFAssetHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // AssetHelper.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #define APP_COLOR [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0] 12 | 13 | #define ASSETHELPER [JFAssetHelper sharedAssetHelper] 14 | 15 | #define ASSET_PHOTO_THUMBNAIL 0 16 | #define ASSET_PHOTO_ASPECT_THUMBNAIL 1 17 | #define ASSET_PHOTO_SCREEN_SIZE 2 18 | #define ASSET_PHOTO_FULL_RESOLUTION 3 19 | 20 | @interface JFAssetHelper : NSObject 21 | 22 | - (void)initAsset; 23 | 24 | @property (nonatomic, strong) ALAssetsLibrary *assetsLibrary; 25 | @property (nonatomic, strong) NSMutableArray *assetPhotos; 26 | @property (nonatomic, strong) NSMutableArray *assetGroups; 27 | @property (nonatomic) NSInteger currentGroupIndex; 28 | @property (nonatomic) NSInteger previewIndex; 29 | @property (readwrite) BOOL bReverse; 30 | @property (nonatomic, strong) NSMutableArray *selectdPhotos; 31 | @property (nonatomic, strong) NSMutableArray *selectdAssets; 32 | @property (nonatomic, strong) NSMutableArray *defaultAssets; 33 | @property (nonatomic, strong) NSString *originStr; 34 | @property (nonatomic, strong) ALAsset *selectdAsset; 35 | 36 | + (JFAssetHelper *)sharedAssetHelper; 37 | 38 | // get album list from asset 39 | - (void)getGroupList:(void (^)(NSArray *))result; 40 | // get photos from specific album with ALAssetsGroup object 41 | - (void)getPhotoListOfGroup:(ALAssetsGroup *)alGroup result:(void (^)(NSArray *))result; 42 | // get photos from specific album with index of album array 43 | - (void)getPhotoListOfGroupByIndex:(NSInteger)nGroupIndex result:(void (^)(NSArray *))result; 44 | // get photos from camera roll 45 | - (void)getSavedPhotoList:(void (^)(NSArray *))result error:(void (^)(NSError *))error; 46 | 47 | - (NSInteger)getGroupCount; 48 | - (NSInteger)getPhotoCountOfCurrentGroup; 49 | - (NSDictionary *)getGroupInfo:(NSInteger)nIndex; 50 | 51 | - (void)clearData; 52 | 53 | // utils 54 | - (UIImage *)getCroppedImage:(NSURL *)urlImage; 55 | - (UIImage *)getImageFromAsset:(ALAsset *)asset type:(NSInteger)nType; 56 | - (UIImage *)getImageAtIndex:(NSInteger)nIndex type:(NSInteger)nType; 57 | - (ALAsset *)getAssetAtIndex:(NSInteger)nIndex; 58 | - (ALAssetsGroup *)getGroupAtIndex:(NSInteger)nIndex; 59 | 60 | @end 61 | 62 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFAssetHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // AssetHelper.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFAssetHelper.h" 10 | 11 | @implementation JFAssetHelper 12 | 13 | 14 | + (JFAssetHelper *)sharedAssetHelper 15 | { 16 | static JFAssetHelper *_sharedInstance = nil; 17 | static dispatch_once_t onceToken; 18 | dispatch_once(&onceToken, ^{ 19 | _sharedInstance = [[JFAssetHelper alloc] init]; 20 | [_sharedInstance initAsset]; 21 | }); 22 | 23 | return _sharedInstance; 24 | } 25 | 26 | - (void)initAsset 27 | { 28 | if (_selectdPhotos==nil) { 29 | _selectdPhotos = [[NSMutableArray alloc] init]; 30 | _selectdAssets = [[NSMutableArray alloc] init]; 31 | } 32 | if (self.assetsLibrary == nil) 33 | { 34 | _assetsLibrary = [[ALAssetsLibrary alloc] init]; 35 | 36 | NSString *strVersion = [[UIDevice alloc] systemVersion]; 37 | if ([strVersion compare:@"5"] >= 0) 38 | [_assetsLibrary writeImageToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) { 39 | }]; 40 | } 41 | } 42 | 43 | - (void)setCameraRollAtFirst 44 | { 45 | for (ALAssetsGroup *group in _assetGroups) 46 | { 47 | if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos) 48 | { 49 | // send to head 50 | [_assetGroups removeObject:group]; 51 | [_assetGroups insertObject:group atIndex:0]; 52 | 53 | return; 54 | } 55 | } 56 | } 57 | 58 | - (void)getGroupList:(void (^)(NSArray *))result 59 | { 60 | [self initAsset]; 61 | 62 | void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 63 | { 64 | [group setAssetsFilter:[ALAssetsFilter allPhotos]]; 65 | 66 | if (group == nil) 67 | { 68 | if (_bReverse) 69 | _assetGroups = [[NSMutableArray alloc] initWithArray:[[_assetGroups reverseObjectEnumerator] allObjects]]; 70 | 71 | [self setCameraRollAtFirst]; 72 | 73 | // end of enumeration 74 | result(_assetGroups); 75 | return; 76 | } 77 | 78 | [_assetGroups addObject:group]; 79 | }; 80 | 81 | void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) 82 | { 83 | NSLog(@"Error : %@", [error description]); 84 | }; 85 | 86 | _assetGroups = [[NSMutableArray alloc] init]; 87 | [_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll 88 | usingBlock:assetGroupEnumerator 89 | failureBlock:assetGroupEnumberatorFailure]; 90 | } 91 | 92 | - (void)getPhotoListOfGroup:(ALAssetsGroup *)alGroup result:(void (^)(NSArray *))result 93 | { 94 | [self initAsset]; 95 | 96 | _assetPhotos = [[NSMutableArray alloc] init]; 97 | [alGroup setAssetsFilter:[ALAssetsFilter allPhotos]]; 98 | [alGroup enumerateAssetsUsingBlock:^(ALAsset *alPhoto, NSUInteger index, BOOL *stop) { 99 | 100 | if(alPhoto == nil) 101 | { 102 | if (_bReverse) { 103 | if (_defaultAssets) { 104 | [_assetPhotos addObjectsFromArray:_defaultAssets]; 105 | } 106 | 107 | [_defaultAssets addObject:@"camera"]; 108 | 109 | _assetPhotos = [[NSMutableArray alloc] initWithArray:[[_assetPhotos reverseObjectEnumerator] allObjects]]; 110 | } 111 | 112 | result(_assetPhotos); 113 | return; 114 | } 115 | 116 | [_assetPhotos addObject:alPhoto]; 117 | }]; 118 | } 119 | 120 | - (void)getPhotoListOfGroupByIndex:(NSInteger)nGroupIndex result:(void (^)(NSArray *))result 121 | { 122 | [self getPhotoListOfGroup:_assetGroups[nGroupIndex] result:^(NSArray *aResult) { 123 | 124 | result(_assetPhotos); 125 | 126 | }]; 127 | } 128 | 129 | - (void)getSavedPhotoList:(void (^)(NSArray *))result error:(void (^)(NSError *))error 130 | { 131 | [self initAsset]; 132 | 133 | dispatch_async(dispatch_get_main_queue(), ^{ 134 | 135 | void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 136 | { 137 | if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos) 138 | { 139 | [group setAssetsFilter:[ALAssetsFilter allPhotos]]; 140 | 141 | [group enumerateAssetsUsingBlock:^(ALAsset *alPhoto, NSUInteger index, BOOL *stop) { 142 | 143 | if(alPhoto == nil) 144 | { 145 | if (_bReverse) 146 | _assetPhotos = [[NSMutableArray alloc] initWithArray:[[_assetPhotos reverseObjectEnumerator] allObjects]]; 147 | 148 | result(_assetPhotos); 149 | return; 150 | } 151 | 152 | [_assetPhotos addObject:alPhoto]; 153 | }]; 154 | } 155 | }; 156 | 157 | void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *err) 158 | { 159 | NSLog(@"Error : %@", [err description]); 160 | error(err); 161 | }; 162 | 163 | _assetPhotos = [[NSMutableArray alloc] init]; 164 | [_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos 165 | usingBlock:assetGroupEnumerator 166 | failureBlock:assetGroupEnumberatorFailure]; 167 | }); 168 | } 169 | 170 | - (NSInteger)getGroupCount 171 | { 172 | return _assetGroups.count; 173 | } 174 | 175 | - (NSInteger)getPhotoCountOfCurrentGroup 176 | { 177 | return _assetPhotos.count; 178 | } 179 | 180 | - (NSDictionary *)getGroupInfo:(NSInteger)nIndex 181 | { 182 | return @{@"name" : [_assetGroups[nIndex] valueForProperty:ALAssetsGroupPropertyName], 183 | @"count" : @([_assetGroups[nIndex] numberOfAssets])}; 184 | } 185 | 186 | - (void)clearData 187 | { 188 | [_selectdAssets removeAllObjects]; 189 | _selectdAssets = nil; 190 | [_selectdPhotos removeAllObjects]; 191 | _selectdPhotos = nil; 192 | [_defaultAssets removeAllObjects]; 193 | _defaultAssets = nil; 194 | _assetGroups = nil; 195 | _assetPhotos = nil; 196 | } 197 | 198 | - (NSMutableArray *)defaultAssets{ 199 | if (_defaultAssets==nil) { 200 | _defaultAssets = [[NSMutableArray alloc] init]; 201 | } 202 | return _defaultAssets; 203 | } 204 | 205 | - (NSMutableArray *)selectdAssets{ 206 | if (_selectdAssets==nil) { 207 | _selectdAssets = [[NSMutableArray alloc] init]; 208 | } 209 | return _selectdAssets; 210 | } 211 | 212 | - (NSMutableArray *)selectdPhotos{ 213 | if (_selectdPhotos==nil) { 214 | _selectdPhotos = [[NSMutableArray alloc] init]; 215 | } 216 | return _selectdPhotos; 217 | } 218 | 219 | #pragma mark - utils 220 | - (UIImage *)getCroppedImage:(NSURL *)urlImage 221 | { 222 | __block UIImage *iImage = nil; 223 | __block BOOL bBusy = YES; 224 | 225 | ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) 226 | { 227 | ALAssetRepresentation *rep = [myasset defaultRepresentation]; 228 | NSString *strXMP = rep.metadata[@"AdjustmentXMP"]; 229 | if (strXMP == nil || [strXMP isKindOfClass:[NSNull class]]) 230 | { 231 | CGImageRef iref = [rep fullResolutionImage]; 232 | if (iref) 233 | iImage = [UIImage imageWithCGImage:iref scale:1.0 orientation:(UIImageOrientation)rep.orientation]; 234 | else 235 | iImage = nil; 236 | } 237 | else 238 | { 239 | // to get edited photo by photo app 240 | NSData *dXMP = [strXMP dataUsingEncoding:NSUTF8StringEncoding]; 241 | 242 | CIImage *image = [CIImage imageWithCGImage:rep.fullResolutionImage]; 243 | 244 | NSError *error = nil; 245 | NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:dXMP 246 | inputImageExtent:image.extent 247 | error:&error]; 248 | if (error) { 249 | NSLog(@"Error during CIFilter creation: %@", [error localizedDescription]); 250 | } 251 | 252 | for (CIFilter *filter in filterArray) { 253 | [filter setValue:image forKey:kCIInputImageKey]; 254 | image = [filter outputImage]; 255 | } 256 | 257 | iImage = [UIImage imageWithCIImage:image scale:1.0 orientation:(UIImageOrientation)rep.orientation]; 258 | } 259 | 260 | bBusy = NO; 261 | }; 262 | 263 | ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) 264 | { 265 | NSLog(@"booya, cant get image - %@",[myerror localizedDescription]); 266 | }; 267 | 268 | [_assetsLibrary assetForURL:urlImage 269 | resultBlock:resultblock 270 | failureBlock:failureblock]; 271 | 272 | while (bBusy) 273 | [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 274 | 275 | return iImage; 276 | } 277 | 278 | - (UIImage *)getImageFromAsset:(ALAsset *)asset type:(NSInteger)nType 279 | { 280 | CGImageRef iRef = nil; 281 | 282 | if (nType == ASSET_PHOTO_THUMBNAIL) 283 | iRef = [asset thumbnail]; 284 | else if (nType == ASSET_PHOTO_ASPECT_THUMBNAIL) 285 | iRef = [asset aspectRatioThumbnail]; 286 | else if (nType == ASSET_PHOTO_SCREEN_SIZE) 287 | iRef = [asset.defaultRepresentation fullScreenImage]; 288 | else if (nType == ASSET_PHOTO_FULL_RESOLUTION) 289 | { 290 | NSString *strXMP = asset.defaultRepresentation.metadata[@"AdjustmentXMP"]; 291 | if (strXMP == nil || [strXMP isKindOfClass:[NSNull class]]) 292 | { 293 | iRef = [asset.defaultRepresentation fullResolutionImage]; 294 | return [UIImage imageWithCGImage:iRef scale:1.0 orientation:(UIImageOrientation)asset.defaultRepresentation.orientation]; 295 | } 296 | else 297 | { 298 | NSData *dXMP = [strXMP dataUsingEncoding:NSUTF8StringEncoding]; 299 | 300 | CIImage *image = [CIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage]; 301 | 302 | NSError *error = nil; 303 | NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:dXMP 304 | inputImageExtent:image.extent 305 | error:&error]; 306 | if (error) { 307 | NSLog(@"Error during CIFilter creation: %@", [error localizedDescription]); 308 | } 309 | 310 | for (CIFilter *filter in filterArray) { 311 | [filter setValue:image forKey:kCIInputImageKey]; 312 | image = [filter outputImage]; 313 | } 314 | CIContext *context = [CIContext contextWithOptions:nil]; 315 | CGImageRef cgimage = [context createCGImage:image fromRect:[image extent]]; 316 | UIImage *iImage = [UIImage imageWithCGImage:cgimage scale:1.0 orientation:(UIImageOrientation)asset.defaultRepresentation.orientation]; 317 | return iImage; 318 | } 319 | } 320 | return [UIImage imageWithCGImage:iRef]; 321 | } 322 | 323 | - (UIImage *)getImageAtIndex:(NSInteger)nIndex type:(NSInteger)nType 324 | { 325 | return [self getImageFromAsset:(ALAsset *)_assetPhotos[nIndex] type:nType]; 326 | } 327 | 328 | - (ALAsset *)getAssetAtIndex:(NSInteger)nIndex 329 | { 330 | return _assetPhotos[nIndex]; 331 | } 332 | 333 | - (ALAssetsGroup *)getGroupAtIndex:(NSInteger)nIndex 334 | { 335 | return _assetGroups[nIndex]; 336 | } 337 | 338 | @end 339 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageCollectionViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageCollectionViewController.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2014年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JFImageCollectionViewController : UIViewController 12 | 13 | - (UICollectionView *)collectionView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageCollectionViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageCollectionViewController.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFImageCollectionViewController.h" 10 | #import "JFImagePickerViewCell.h" 11 | #import "JFPhotoBrowserViewController.h" 12 | #import "JFImagePickerController.h" 13 | #import "JFAssetHelper.h" 14 | #import "JFImageManager.h" 15 | #import 16 | 17 | @interface JFImageCollectionViewController () 18 | 19 | @end 20 | 21 | @implementation JFImageCollectionViewController { 22 | UICollectionView *photosList; 23 | NSInteger currentIndex; 24 | BOOL scrollToToping; 25 | NSTimer *timer; 26 | } 27 | 28 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 29 | { 30 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 31 | if (self) { 32 | } 33 | return self; 34 | } 35 | 36 | - (void)viewWillAppear:(BOOL)animated{ 37 | self.navigationItem.title = [[ASSETHELPER.assetGroups objectAtIndex:ASSETHELPER.currentGroupIndex] valueForProperty:ALAssetsGroupPropertyName]; 38 | UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; 39 | self.navigationItem.rightBarButtonItem = cancel; 40 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNormalPhotoBrowser:) name:@"showNormalPhotoBrowser" object:nil]; 41 | } 42 | 43 | - (void)viewWillDisappear:(BOOL)animated{ 44 | self.navigationItem.title = nil; 45 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 46 | } 47 | 48 | - (void)cancel{ 49 | [(JFImagePickerController *)self.navigationController cancel]; 50 | } 51 | 52 | - (UICollectionView *)collectionView{ 53 | return photosList; 54 | } 55 | 56 | - (void)viewDidLoad 57 | { 58 | [super viewDidLoad]; 59 | self.view.backgroundColor = [UIColor whiteColor]; 60 | UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 61 | flowLayout.minimumInteritemSpacing = 0; 62 | flowLayout.minimumLineSpacing = 3; 63 | NSInteger size = [UIScreen mainScreen].bounds.size.width/4-1; 64 | if (size%2!=0) { 65 | size-=1; 66 | } 67 | flowLayout.itemSize = CGSizeMake(size, size); 68 | flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); 69 | 70 | photosList = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout]; 71 | photosList.contentInset = UIEdgeInsetsMake(0, 0, 44, 0); 72 | photosList.scrollIndicatorInsets = photosList.contentInset; 73 | photosList.delegate = self; 74 | photosList.dataSource = self; 75 | photosList.backgroundColor = [UIColor whiteColor]; 76 | [self.view addSubview:photosList]; 77 | [photosList registerClass:[JFImagePickerViewCell class] forCellWithReuseIdentifier:@"imagePickerCell"]; 78 | [ASSETHELPER getPhotoListOfGroupByIndex:ASSETHELPER.currentGroupIndex result:^(NSArray *r) { 79 | [[JFImageManager sharedManager] startCahcePhotoThumbWithSize:CGSizeMake(size, size)]; 80 | [photosList reloadData]; 81 | if (ASSETHELPER.previewIndex>=0) { 82 | JFPhotoBrowserViewController *photoBrowser = [[JFPhotoBrowserViewController alloc] initWithPreview]; 83 | photoBrowser.delegate = self.navigationController; 84 | [self.navigationController pushViewController:photoBrowser animated:YES]; 85 | } 86 | 87 | for (NSDictionary *dict in ASSETHELPER.selectdPhotos) { 88 | NSArray *temp = [[[dict allKeys] firstObject] componentsSeparatedByString:@"-"]; 89 | NSInteger row = [temp[0] integerValue]; 90 | NSInteger group = [temp[1] integerValue]; 91 | if (group==ASSETHELPER.currentGroupIndex) { 92 | [photosList scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; 93 | break; 94 | } 95 | } 96 | }]; 97 | } 98 | 99 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 100 | return 1; 101 | } 102 | 103 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 104 | return [ASSETHELPER getPhotoCountOfCurrentGroup]; 105 | } 106 | 107 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 108 | JFImagePickerViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imagePickerCell" forIndexPath:indexPath]; 109 | cell.indexPath = indexPath; 110 | cell.tag = indexPath.item; 111 | ALAsset *asset = [ASSETHELPER getAssetAtIndex:indexPath.row]; 112 | [[JFImageManager sharedManager] thumbWithAsset:asset resultHandler:^(UIImage *result) { 113 | if (cell.tag==indexPath.item) { 114 | cell.imageView.image = result; 115 | } 116 | }]; 117 | BOOL hasItem = NO; 118 | int num = 0; 119 | for (NSDictionary *temp in ASSETHELPER.selectdPhotos) { 120 | if ([[[temp allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld",(long)indexPath.row, (long)ASSETHELPER.currentGroupIndex]]) { 121 | num = [[[temp allValues] firstObject] intValue]; 122 | hasItem = YES; 123 | } 124 | } 125 | if (hasItem) { 126 | [cell selectOfNum:num]; 127 | } else { 128 | [cell selectOfNum:-1]; 129 | } 130 | return cell; 131 | } 132 | 133 | - (void)showNormalPhotoBrowser:(NSNotification *)notifi{ 134 | currentIndex = [notifi.object row]; 135 | JFPhotoBrowserViewController *photoBrowser = [[JFPhotoBrowserViewController alloc] initWithNormal]; 136 | photoBrowser.delegate = self; 137 | [self.navigationController pushViewController:photoBrowser animated:YES]; 138 | } 139 | 140 | - (NSInteger)numOfPhotosFromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 141 | return [ASSETHELPER getPhotoCountOfCurrentGroup]; 142 | } 143 | 144 | - (NSInteger)currentIndexFromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 145 | return currentIndex; 146 | } 147 | 148 | - (ALAsset *)assetWithIndex:(NSInteger)index fromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 149 | return [ASSETHELPER getAssetAtIndex:index]; 150 | } 151 | 152 | - (void)photoBrowser:(JFPhotoBrowserViewController *)browser didShowPage:(NSInteger)page{ 153 | [photosList scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:page inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO]; 154 | } 155 | 156 | - (JFImagePickerViewCell *)cellForRow:(NSInteger)row{ 157 | return (JFImagePickerViewCell *)[photosList cellForItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]]; 158 | } 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageGroupTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageGroupTableViewController.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JFImageGroupTableViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageGroupTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageGroupTableViewController.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFImageGroupTableViewController.h" 10 | #import "JFImageCollectionViewController.h" 11 | #import "JFImagePickerController.h" 12 | #import "JFAssetHelper.h" 13 | 14 | @interface JFImageGroupTableViewController () 15 | 16 | @end 17 | 18 | @implementation JFImageGroupTableViewController 19 | 20 | - (id)initWithStyle:(UITableViewStyle)style 21 | { 22 | self = [super initWithStyle:style]; 23 | if (self) { 24 | // Custom initialization 25 | } 26 | return self; 27 | } 28 | 29 | - (void)viewWillAppear:(BOOL)animated{ 30 | self.navigationItem.title = @"相册"; 31 | UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; 32 | self.navigationItem.rightBarButtonItem = cancel; 33 | } 34 | 35 | - (void)cancel{ 36 | [(JFImagePickerController *)self.navigationController cancel]; 37 | } 38 | 39 | - (void)viewDidLoad 40 | { 41 | [super viewDidLoad]; 42 | self.navigationController.navigationBar.translucent = YES; 43 | self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 44 | self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 45 | self.tableView.tableFooterView = [UIView new]; 46 | ASSETHELPER.bReverse = YES; 47 | [ASSETHELPER getGroupList:^(NSArray *a) { 48 | [self.tableView reloadData]; 49 | ASSETHELPER.currentGroupIndex = 0; 50 | JFImageCollectionViewController *picker = [[JFImageCollectionViewController alloc] initWithNibName:nil bundle:nil]; 51 | [self.navigationController pushViewController:picker animated:NO]; 52 | }]; 53 | } 54 | 55 | - (void)didReceiveMemoryWarning 56 | { 57 | [super didReceiveMemoryWarning]; 58 | // Dispose of any resources that can be recreated. 59 | } 60 | 61 | #pragma mark - Table view data source 62 | 63 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 64 | { 65 | return 1; 66 | } 67 | 68 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 69 | { 70 | return [[JFAssetHelper sharedAssetHelper] getGroupCount]; 71 | } 72 | 73 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 74 | { 75 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier"]; 76 | if (cell==nil) { 77 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"reuseIdentifier"]; 78 | } 79 | ALAssetsGroup *group = [ASSETHELPER getGroupAtIndex:indexPath.row]; 80 | cell.imageView.image = [UIImage imageWithCGImage:[group posterImage]]; 81 | cell.textLabel.text = [group valueForProperty:ALAssetsGroupPropertyName]; 82 | cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld", (long)[group numberOfAssets]]; 83 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 84 | return cell; 85 | } 86 | 87 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 88 | return 80; 89 | } 90 | 91 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 92 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 93 | ASSETHELPER.currentGroupIndex = indexPath.row; 94 | JFImageCollectionViewController *picker = [[JFImageCollectionViewController alloc] initWithNibName:nil bundle:nil]; 95 | [self.navigationController pushViewController:picker animated:YES]; 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageManager.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/4. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | @interface JFImageManager : NSObject 12 | 13 | + (JFImageManager *)sharedManager; 14 | - (void)clearMem; 15 | - (void)startCahcePhotoThumbWithSize:(CGSize)size; 16 | - (void)thumbWithAsset:(ALAsset *)asset 17 | resultHandler:(void (^)(UIImage *result))resultHandler; 18 | - (void)imageWithAsset:(ALAsset *)asset 19 | resultHandler:(void (^)(CGImageRef imageRef, BOOL longImage))resultHandler; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImageManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImageManager.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/4. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFImageManager.h" 10 | #import "JFAssetHelper.h" 11 | #import 12 | 13 | @implementation JFImageManager { 14 | NSCache *memCache; 15 | NSMutableDictionary *resuleHandlers; 16 | } 17 | 18 | + (JFImageManager *)sharedManager{ 19 | static JFImageManager *_sharedInstance = nil; 20 | static dispatch_once_t onceToken; 21 | dispatch_once(&onceToken, ^{ 22 | _sharedInstance = [[JFImageManager alloc] init]; 23 | }); 24 | return _sharedInstance; 25 | } 26 | 27 | - (instancetype)init{ 28 | self = [super init]; 29 | if (self) { 30 | resuleHandlers = [[NSMutableDictionary alloc] init]; 31 | memCache = [[NSCache alloc] init]; 32 | memCache.name = @"com.johnil.JFImagePickerController.caches"; 33 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)clearMem{ 39 | [memCache removeAllObjects]; 40 | } 41 | 42 | - (void)memoryWarning{ 43 | [self clearMem]; 44 | } 45 | 46 | - (void)startCahcePhotoThumbWithSize:(CGSize)toSize{ 47 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 48 | NSArray *assets = ASSETHELPER.assetPhotos; 49 | for (ALAsset *asset in assets) { 50 | CGImageRef fullImageRef = nil; 51 | CGSize screenSize = [UIScreen mainScreen].bounds.size; 52 | screenSize.height *= [UIScreen mainScreen].scale; 53 | screenSize.width *= [UIScreen mainScreen].scale; 54 | CGSize size; 55 | CGRect partRect = CGRectZero; 56 | CGSize dimensions = asset.defaultRepresentation.dimensions; 57 | float maxPixel = 0; 58 | if (dimensions.width>dimensions.height) { 59 | if (dimensions.width/2>dimensions.height&&dimensions.width/2>screenSize.width&&dimensions.height>toSize.height*[UIScreen mainScreen].scale) { 60 | float scale = (dimensions.height/(toSize.width*[UIScreen mainScreen].scale)); 61 | if (scale<1) { 62 | maxPixel = dimensions.width; 63 | } else { 64 | maxPixel = dimensions.width/scale; 65 | } 66 | fullImageRef = [self thumbnailForAsset:asset maxPixelSize:maxPixel]; 67 | size = CGSizeMake(CGImageGetWidth(fullImageRef), CGImageGetHeight(fullImageRef)); 68 | partRect = CGRectMake(size.width/2-size.height/2, 0, size.height, size.height); 69 | } 70 | } else { 71 | if (dimensions.height/2>dimensions.width&&dimensions.height/2>screenSize.height&&dimensions.width>toSize.width*[UIScreen mainScreen].scale) { 72 | float scale = (dimensions.width/(toSize.width*[UIScreen mainScreen].scale)); 73 | if (scale<1) { 74 | maxPixel = dimensions.height; 75 | } else { 76 | maxPixel = dimensions.height/scale; 77 | } 78 | fullImageRef = [self thumbnailForAsset:asset maxPixelSize:maxPixel]; 79 | size = CGSizeMake(CGImageGetWidth(fullImageRef), CGImageGetHeight(fullImageRef)); 80 | partRect = CGRectMake(0, size.height/2-size.width/2, size.width, size.width); 81 | } 82 | } 83 | UIImage *temp; 84 | if (fullImageRef) { 85 | CGImageRef part = CGImageCreateWithImageInRect(fullImageRef, partRect); 86 | CGImageRef tempRef = [self normalizeImage:part]; 87 | temp =[UIImage imageWithCGImage:tempRef]; 88 | [memCache setObject:temp forKey:asset.defaultRepresentation.filename]; 89 | CGImageRelease(tempRef); 90 | CGImageRelease(part); 91 | tempRef = nil; 92 | part = nil; 93 | void (^resultHandler)(UIImage *result) = resuleHandlers[asset.defaultRepresentation.filename]; 94 | if (resultHandler) { 95 | [resuleHandlers removeObjectForKey:asset.defaultRepresentation.filename]; 96 | dispatch_async(dispatch_get_main_queue(), ^{ 97 | resultHandler(temp); 98 | }); 99 | } 100 | } else { 101 | [memCache setObject:@"normal" forKey:asset.defaultRepresentation.filename]; 102 | } 103 | } 104 | }); 105 | 106 | } 107 | 108 | - (void)thumbWithAsset:(ALAsset *)asset 109 | resultHandler:(void (^)(UIImage *result))resultHandler{ 110 | if (!resultHandler) { 111 | return; 112 | } 113 | UIImage *image = [UIImage imageWithCGImage:asset.thumbnail]; 114 | resultHandler(image); 115 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 116 | id thumb = [memCache objectForKey:asset.defaultRepresentation.filename]; 117 | if (thumb) { 118 | if ([thumb isKindOfClass:[UIImage class]]) { 119 | dispatch_async(dispatch_get_main_queue(), ^{ 120 | resultHandler(thumb); 121 | }); 122 | } else { 123 | UIImage *image = [UIImage imageWithCGImage:asset.aspectRatioThumbnail]; 124 | dispatch_async(dispatch_get_main_queue(), ^{ 125 | resultHandler(image); 126 | }); 127 | } 128 | } else { 129 | [resuleHandlers setValue:resultHandler forKey:asset.defaultRepresentation.filename]; 130 | } 131 | }); 132 | 133 | } 134 | 135 | - (void)imageWithAsset:(ALAsset *)asset 136 | resultHandler:(void (^)(CGImageRef imageRef, BOOL longImage))resultHandler { 137 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 138 | CGSize dimensions = asset.defaultRepresentation.dimensions; 139 | CGSize screenSize = [UIScreen mainScreen].bounds.size; 140 | float maxPixel = 0; 141 | CGImageRef fullImageRef = nil; 142 | BOOL isLong = NO; 143 | if (dimensions.width>dimensions.height) { 144 | if (dimensions.width/2>dimensions.height&&dimensions.width/2>screenSize.width*[UIScreen mainScreen].scale) { 145 | float scale = (dimensions.height/(screenSize.width*[UIScreen mainScreen].scale)); 146 | if (scale<1) { 147 | maxPixel = dimensions.width; 148 | } else { 149 | maxPixel = dimensions.width/scale; 150 | } 151 | fullImageRef = [self thumbnailForAsset:asset maxPixelSize:maxPixel]; 152 | isLong = YES; 153 | } else { 154 | fullImageRef = [asset.defaultRepresentation fullScreenImage]; 155 | } 156 | } else { 157 | if (dimensions.height/2>dimensions.width&&dimensions.height/2>screenSize.height*[UIScreen mainScreen].scale) { 158 | float scale = (dimensions.width/(screenSize.width*[UIScreen mainScreen].scale)); 159 | if (scale<1) { 160 | maxPixel = dimensions.height; 161 | } else { 162 | maxPixel = dimensions.height/scale; 163 | } 164 | fullImageRef = [self thumbnailForAsset:asset maxPixelSize:maxPixel]; 165 | isLong = YES; 166 | } else { 167 | fullImageRef = [asset.defaultRepresentation fullScreenImage]; 168 | } 169 | } 170 | resultHandler(fullImageRef, isLong); 171 | }); 172 | 173 | } 174 | 175 | - (CGImageRef)normalizeImage:(CGImageRef)imageRef{ 176 | NSInteger width = CGImageGetWidth(imageRef); 177 | NSInteger height = CGImageGetHeight(imageRef); 178 | CGRect destRect = CGRectMake(0, 0, width, height); 179 | CGColorSpaceRef genericColorSpace = CGColorSpaceCreateDeviceRGB(); 180 | CGContextRef thumbBitmapCtxt = CGBitmapContextCreate(NULL, 181 | width, 182 | height, 183 | 8, (4 * width), 184 | genericColorSpace, 185 | (CGBitmapInfo)kCGImageAlphaPremultipliedLast); 186 | CGColorSpaceRelease(genericColorSpace); 187 | CGContextSetInterpolationQuality(thumbBitmapCtxt, kCGInterpolationDefault); 188 | CGContextDrawImage(thumbBitmapCtxt, destRect, imageRef); 189 | CGImageRef tmpThumbImage = CGBitmapContextCreateImage(thumbBitmapCtxt); 190 | CGContextRelease(thumbBitmapCtxt); 191 | return tmpThumbImage; 192 | } 193 | 194 | // Helper methods for thumbnailForAsset:maxPixelSize: 195 | static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) { 196 | ALAssetRepresentation *rep = (__bridge id)info; 197 | 198 | NSError *error = nil; 199 | size_t countRead = [rep getBytes:(uint8_t *)buffer fromOffset:position length:count error:&error]; 200 | 201 | if (countRead == 0 && error) { 202 | // We have no way of passing this info back to the caller, so we log it, at least. 203 | NSLog(@"thumbnailForAsset:maxPixelSize: got an error reading an asset: %@", error); 204 | } 205 | 206 | return countRead; 207 | } 208 | 209 | static void releaseAssetCallback(void *info) { 210 | // The info here is an ALAssetRepresentation which we CFRetain in thumbnailForAsset:maxPixelSize:. 211 | // This release balances that retain. 212 | CFRelease(info); 213 | } 214 | 215 | // Returns a UIImage for the given asset, with size length at most the passed size. 216 | // The resulting UIImage will be already rotated to UIImageOrientationUp, so its CGImageRef 217 | // can be used directly without additional rotation handling. 218 | // This is done synchronously, so you should call this method on a background queue/thread. 219 | - (CGImageRef)thumbnailForAsset:(ALAsset *)asset maxPixelSize:(NSUInteger)size { 220 | NSParameterAssert(asset != nil); 221 | NSParameterAssert(size > 0); 222 | 223 | ALAssetRepresentation *rep = [asset defaultRepresentation]; 224 | 225 | CGDataProviderDirectCallbacks callbacks = { 226 | .version = 0, 227 | .getBytePointer = NULL, 228 | .releaseBytePointer = NULL, 229 | .getBytesAtPosition = getAssetBytesCallback, 230 | .releaseInfo = releaseAssetCallback, 231 | }; 232 | 233 | CGDataProviderRef provider = CGDataProviderCreateDirect((void *)CFBridgingRetain(rep), [rep size], &callbacks); 234 | CGImageSourceRef source = CGImageSourceCreateWithDataProvider(provider, NULL); 235 | 236 | CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(source, 0, (__bridge CFDictionaryRef) @{ 237 | (NSString *)kCGImageSourceCreateThumbnailFromImageAlways : @YES, 238 | (NSString *)kCGImageSourceThumbnailMaxPixelSize : @(size), 239 | (NSString *)kCGImageSourceCreateThumbnailWithTransform : @YES, 240 | }); 241 | CFRelease(source); 242 | CFRelease(provider); 243 | 244 | if (!imageRef) { 245 | return nil; 246 | } 247 | 248 | return imageRef; 249 | } 250 | 251 | @end 252 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImagePickerController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFImagePickerController.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JFAssetHelper.h" 11 | #import "JFImageManager.h" 12 | 13 | @interface JFImagePickerController : UINavigationController 14 | 15 | - (JFImagePickerController *)initWithPreviewIndex:(NSInteger)index; 16 | @property (nonatomic, weak) id pickerDelegate; 17 | 18 | /** 19 | 当退出编辑模式时需调用clear,用来清理内存,已选择照片的缓存 20 | **/ 21 | + (void)clear; 22 | - (UIToolbar *)customToolbar; 23 | - (void)setLeftTitle:(NSString *)title; 24 | - (void)cancel; 25 | 26 | - (NSArray *)imagesWithType:(NSInteger)type; 27 | - (NSArray *)assets; 28 | 29 | @end 30 | 31 | @protocol JFImagePickerDelegate 32 | 33 | - (void)imagePickerDidFinished:(JFImagePickerController *)picker; 34 | - (void)imagePickerDidCancel:(JFImagePickerController *)picker; 35 | 36 | @end -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImagePickerController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImagePickerController.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFImagePickerController.h" 10 | #import "JFImageGroupTableViewController.h" 11 | #import "JFPhotoBrowserViewController.h" 12 | #import "JFImageCollectionViewController.h" 13 | #import "JFAssetHelper.h" 14 | #import "JFImageManager.h" 15 | 16 | @interface JFImagePickerController () 17 | 18 | @end 19 | 20 | @implementation JFImagePickerController { 21 | UIBarButtonItem *selectNum; 22 | UIBarButtonItem *preview; 23 | UIToolbar *toolbar; 24 | JFImageCollectionViewController *collectionViewController; 25 | UIStatusBarStyle tempBarStyle; 26 | } 27 | 28 | - (JFImagePickerController *)initWithPreviewIndex:(NSInteger)index{ 29 | self = [super initWithRootViewController:[JFImageGroupTableViewController new]]; 30 | if (self) { 31 | ASSETHELPER.previewIndex = index; 32 | } 33 | return self; 34 | } 35 | 36 | - (id)initWithRootViewController:(UIViewController *)rootViewController{ 37 | self = [super initWithRootViewController:[JFImageGroupTableViewController new]]; 38 | if (self) { 39 | ASSETHELPER.previewIndex = -1; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)viewWillAppear:(BOOL)animated{ 45 | [super viewWillAppear:animated]; 46 | if (ASSETHELPER.selectdPhotos.count>0) { 47 | preview.title = @"预览"; 48 | } else { 49 | preview.title = @""; 50 | } 51 | } 52 | 53 | - (void)viewDidAppear:(BOOL)animated{ 54 | [super viewDidAppear:animated]; 55 | } 56 | 57 | - (void)viewDidLoad 58 | { 59 | [super viewDidLoad]; 60 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 61 | tempBarStyle = [UIApplication sharedApplication].statusBarStyle; 62 | if (tempBarStyle!=UIStatusBarStyleLightContent) { 63 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; 64 | } 65 | }); 66 | 67 | toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-44, [UIScreen mainScreen].bounds.size.width, 44)]; 68 | toolbar.tintColor = [UIColor whiteColor]; 69 | toolbar.barStyle = UIBarStyleBlack; 70 | [self.view addSubview:toolbar]; 71 | UIBarButtonItem *leftFix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 72 | UIBarButtonItem *rightFix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 73 | preview = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(preview)]; 74 | UIBarButtonItem *fix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 75 | selectNum = [[UIBarButtonItem alloc] initWithTitle:@"0/9" style:UIBarButtonItemStylePlain target:nil action:nil]; 76 | UIBarButtonItem *fix2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 77 | UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(choiceDone)]; 78 | [toolbar setItems:@[leftFix, preview, fix, selectNum, fix2, done, rightFix]]; 79 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeCount:) name:@"selectdPhotos" object:nil]; 80 | selectNum.title = [NSString stringWithFormat:@"%ld/9", (unsigned long)ASSETHELPER.selectdPhotos.count]; 81 | } 82 | 83 | - (void)setLeftTitle:(NSString *)title{ 84 | preview.title = title; 85 | } 86 | 87 | - (UIToolbar *)customToolbar{ 88 | return toolbar; 89 | } 90 | 91 | - (void)changeCount:(NSNotification *)notifi{ 92 | selectNum.title = [NSString stringWithFormat:@"%ld/9", (unsigned long)ASSETHELPER.selectdPhotos.count]; 93 | if (![preview.title isEqualToString:@"取消"]) { 94 | if (ASSETHELPER.selectdPhotos.count>0) { 95 | preview.title = @"预览"; 96 | } else { 97 | preview.title = @""; 98 | } 99 | } 100 | } 101 | 102 | - (void)cancel{ 103 | if (_pickerDelegate) { 104 | if (tempBarStyle!=UIStatusBarStyleLightContent) { 105 | [[UIApplication sharedApplication] setStatusBarStyle:tempBarStyle animated:NO]; 106 | } 107 | [_pickerDelegate imagePickerDidCancel:self]; 108 | } 109 | } 110 | 111 | - (void)preview{ 112 | if (preview.title.length<=0) { 113 | return; 114 | } 115 | if ([preview.title isEqualToString:@"取消"]) { 116 | [self cancel]; 117 | return; 118 | } 119 | if ([preview.title isEqualToString:@"预览"]) { 120 | preview.title = @"取消"; 121 | ASSETHELPER.previewIndex = 0; 122 | collectionViewController = (JFImageCollectionViewController *)self.visibleViewController; 123 | JFPhotoBrowserViewController *photoBrowser = [[JFPhotoBrowserViewController alloc] initWithPreview]; 124 | photoBrowser.delegate = self; 125 | [self pushViewController:photoBrowser animated:YES]; 126 | } else { 127 | [self cancel]; 128 | } 129 | } 130 | 131 | - (void)choiceDone{ 132 | if (_pickerDelegate) { 133 | if (tempBarStyle!=UIStatusBarStyleLightContent) { 134 | [[UIApplication sharedApplication] setStatusBarStyle:tempBarStyle animated:NO]; 135 | } 136 | [_pickerDelegate imagePickerDidFinished:self]; 137 | } 138 | } 139 | 140 | - (void)didReceiveMemoryWarning 141 | { 142 | [super didReceiveMemoryWarning]; 143 | // Dispose of any resources that can be recreated. 144 | } 145 | 146 | - (NSInteger)numOfPhotosFromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 147 | return ASSETHELPER.selectdPhotos.count; 148 | } 149 | 150 | - (NSInteger)currentIndexFromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 151 | return ASSETHELPER.previewIndex; 152 | } 153 | 154 | - (ALAsset *)assetWithIndex:(NSInteger)index fromPhotoBrowser:(JFPhotoBrowserViewController *)browser{ 155 | return ASSETHELPER.selectdAssets[index]; 156 | } 157 | 158 | - (JFImagePickerViewCell *)cellForRow:(NSInteger)row{ 159 | return (JFImagePickerViewCell *)[[collectionViewController collectionView] cellForItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]]; 160 | } 161 | 162 | - (NSArray *)imagesWithType:(NSInteger)type{ 163 | NSMutableArray *temp = [NSMutableArray array]; 164 | for (ALAsset *asset in ASSETHELPER.selectdAssets) { 165 | [temp addObject:[ASSETHELPER getImageFromAsset:asset type:type]]; 166 | } 167 | return temp; 168 | } 169 | 170 | - (NSArray *)assets{ 171 | return ASSETHELPER.selectdAssets; 172 | } 173 | 174 | + (void)clear{ 175 | [ASSETHELPER clearData]; 176 | [[JFImageManager sharedManager] clearMem]; 177 | } 178 | 179 | - (NSUInteger)supportedInterfaceOrientations{ 180 | return UIInterfaceOrientationMaskPortrait; 181 | } 182 | 183 | - (BOOL)shouldAutorotate{ 184 | return NO; 185 | } 186 | 187 | @end 188 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImagePickerViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFImagePickerViewCell.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JFImagePickerViewCell : UICollectionViewCell 12 | 13 | @property (nonatomic, strong) NSIndexPath *indexPath; 14 | @property (nonatomic, strong) UIImageView *imageView; 15 | @property (nonatomic, strong) UILabel *numOfSelect; 16 | - (void)selectOfNum:(NSInteger)num; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFImagePickerViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImagePickerViewCell.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFImagePickerViewCell.h" 10 | #import "JFAssetHelper.h" 11 | 12 | @implementation JFImagePickerViewCell { 13 | UIView *placeholder; 14 | } 15 | 16 | - (id)initWithFrame:(CGRect)frame 17 | { 18 | self = [super initWithFrame:frame]; 19 | if (self) { 20 | _imageView = [[UIImageView alloc] initWithFrame:self.bounds]; 21 | _imageView.contentMode = UIViewContentModeScaleAspectFill; 22 | _imageView.clipsToBounds = YES; 23 | [self addSubview:_imageView]; 24 | placeholder = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width-30, 4, 26, 26)]; 25 | placeholder.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.1]; 26 | placeholder.layer.cornerRadius = 13; 27 | placeholder.layer.borderColor = [UIColor whiteColor].CGColor; 28 | placeholder.layer.borderWidth = 1; 29 | placeholder.userInteractionEnabled = NO; 30 | [self addSubview:placeholder]; 31 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCell:)]; 32 | [self addGestureRecognizer:tap]; 33 | } 34 | return self; 35 | } 36 | 37 | - (void)selectOfNum:(NSInteger)num{ 38 | if (_numOfSelect==nil&&num!=-1) { 39 | placeholder.hidden = YES; 40 | _numOfSelect = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width-30, 4, 26, 26)]; 41 | _numOfSelect.backgroundColor = [APP_COLOR colorWithAlphaComponent:.9]; 42 | _numOfSelect.textAlignment = NSTextAlignmentCenter; 43 | _numOfSelect.textColor = [UIColor whiteColor]; 44 | _numOfSelect.font = [UIFont systemFontOfSize:15]; 45 | _numOfSelect.layer.cornerRadius = 13; 46 | _numOfSelect.layer.borderColor = [UIColor whiteColor].CGColor; 47 | _numOfSelect.layer.borderWidth = 1; 48 | _numOfSelect.clipsToBounds = YES; 49 | [self addSubview:_numOfSelect]; 50 | _numOfSelect.text = @(num).stringValue; 51 | _numOfSelect.transform = CGAffineTransformMakeScale(.5, .5); 52 | [UIView animateWithDuration:.3 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 53 | _numOfSelect.transform = CGAffineTransformIdentity; 54 | } completion:nil]; 55 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadNum:) name:@"reloadNum" object:nil]; 56 | } else { 57 | placeholder.hidden = NO; 58 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 59 | [_numOfSelect removeFromSuperview]; 60 | _numOfSelect = nil; 61 | } 62 | } 63 | 64 | - (void)removeFromSuperview{ 65 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 66 | [super removeFromSuperview]; 67 | } 68 | 69 | - (void)reloadNum:(NSNotification *)notifi{ 70 | for (NSDictionary *temp in ASSETHELPER.selectdPhotos) { 71 | if ([[[temp allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld", (long)_indexPath.row, (long)ASSETHELPER.currentGroupIndex]]) { 72 | _numOfSelect.text = [[[temp allValues] firstObject] stringValue]; 73 | } 74 | } 75 | } 76 | 77 | - (void)tapCell:(UITapGestureRecognizer *)tap{ 78 | CGPoint location = [tap locationInView:self]; 79 | if (CGRectContainsPoint(CGRectMake(placeholder.frame.origin.x-5, placeholder.frame.origin.y-5, placeholder.frame.size.width+10, placeholder.frame.size.height+10), location)) { 80 | if (self.numOfSelect==nil&&ASSETHELPER.selectdPhotos.count>=9) { 81 | return; 82 | } 83 | if (self.numOfSelect==nil) { 84 | [ASSETHELPER.selectdPhotos addObject:@{[NSString stringWithFormat:@"%ld-%ld",(long)_indexPath.row, (long)ASSETHELPER.currentGroupIndex]: @(ASSETHELPER.selectdPhotos.count+1)}]; 85 | 86 | [ASSETHELPER.selectdAssets addObject:[ASSETHELPER getAssetAtIndex:_indexPath.row]]; 87 | 88 | [self selectOfNum:ASSETHELPER.selectdPhotos.count]; 89 | } else { 90 | NSInteger index = 0; 91 | NSInteger num = 0; 92 | for (NSDictionary *dict in ASSETHELPER.selectdPhotos) { 93 | if ([[[dict allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld",(long)_indexPath.row, (long)ASSETHELPER.currentGroupIndex]]) { 94 | index = [ASSETHELPER.selectdPhotos indexOfObject:dict]; 95 | num = [[[dict allValues] firstObject] intValue]; 96 | } 97 | } 98 | for (NSDictionary *dict in [ASSETHELPER.selectdPhotos copy]) { 99 | if ([[[dict allValues] firstObject] intValue]>num) { 100 | NSInteger index = [ASSETHELPER.selectdPhotos indexOfObject:dict]; 101 | [ASSETHELPER.selectdPhotos removeObject:dict]; 102 | [ASSETHELPER.selectdPhotos insertObject:@{[[dict allKeys] firstObject]: @([[[dict allValues] firstObject] intValue]-1)} atIndex:index]; 103 | } 104 | } 105 | 106 | 107 | [ASSETHELPER.selectdAssets removeObjectAtIndex:index]; 108 | [ASSETHELPER.selectdPhotos removeObjectAtIndex:index]; 109 | [self selectOfNum:-1]; 110 | [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadNum" object:nil]; 111 | } 112 | [[NSNotificationCenter defaultCenter] postNotificationName:@"selectdPhotos" object:nil]; 113 | } else { 114 | [[NSNotificationCenter defaultCenter] postNotificationName:@"showNormalPhotoBrowser" object:_indexPath]; 115 | } 116 | } 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFPhotoBrowserViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFPhotoBrowserViewController.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "JFImagePickerViewCell.h" 12 | @interface JFPhotoBrowserViewController : UIViewController 13 | 14 | - (JFPhotoBrowserViewController *)initWithPreview; 15 | - (JFPhotoBrowserViewController *)initWithNormal; 16 | @property (nonatomic, weak) id delegate; 17 | 18 | @end 19 | 20 | @protocol JDPhotoBrowserDelegate 21 | 22 | - (ALAsset *)assetWithIndex:(NSInteger)index fromPhotoBrowser:(JFPhotoBrowserViewController *)browser; 23 | - (NSInteger)numOfPhotosFromPhotoBrowser:(JFPhotoBrowserViewController *)browser; 24 | - (NSInteger)currentIndexFromPhotoBrowser:(JFPhotoBrowserViewController *)browser; 25 | @optional 26 | - (void)photoBrowser:(JFPhotoBrowserViewController *)browser didShowPage:(NSInteger)page; 27 | - (JFImagePickerViewCell *)cellForRow:(NSInteger)row; 28 | 29 | @end -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFPhotoBrowserViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFPhotoBrowserViewController.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFPhotoBrowserViewController.h" 10 | #import "JFPhotoView.h" 11 | #import "JFImagePickerController.h" 12 | #import "JFAssetHelper.h" 13 | 14 | @interface JFPhotoBrowserViewController () 15 | 16 | @end 17 | 18 | @implementation JFPhotoBrowserViewController{ 19 | UIScrollView *photosView; 20 | NSInteger photoCount; 21 | UIButton *placeholder; 22 | NSMutableArray *disabledIndexs; 23 | NSMutableArray *backupData; 24 | BOOL isPreview; 25 | BOOL isBrowser; 26 | UIImageView *shotBg; 27 | UIView *blackView; 28 | NSInteger currentPage; 29 | BOOL shouldRoate; 30 | } 31 | 32 | - (JFPhotoBrowserViewController *)initWithPreview{ 33 | self = [super initWithNibName:nil bundle:nil]; 34 | if (self) { 35 | isPreview = YES; 36 | self.automaticallyAdjustsScrollViewInsets = NO; 37 | self.extendedLayoutIncludesOpaqueBars = YES; 38 | photosView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width+10, [UIScreen mainScreen].bounds.size.height)]; 39 | photosView.showsVerticalScrollIndicator = NO; 40 | photosView.showsHorizontalScrollIndicator = NO; 41 | photosView.pagingEnabled = YES; 42 | photosView.delegate = self; 43 | [self.view addSubview:photosView]; 44 | self.view.backgroundColor = [UIColor blackColor]; 45 | } 46 | return self; 47 | } 48 | 49 | - (JFPhotoBrowserViewController *)initWithNormal{ 50 | self = [super initWithNibName:nil bundle:nil]; 51 | if (self) { 52 | isPreview = NO; 53 | self.automaticallyAdjustsScrollViewInsets = NO; 54 | self.extendedLayoutIncludesOpaqueBars = YES; 55 | photosView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width+10, [UIScreen mainScreen].bounds.size.height)]; 56 | photosView.showsVerticalScrollIndicator = NO; 57 | photosView.showsHorizontalScrollIndicator = NO; 58 | photosView.pagingEnabled = YES; 59 | photosView.delegate = self; 60 | [self.view addSubview:photosView]; 61 | self.view.backgroundColor = [UIColor blackColor]; 62 | } 63 | return self; 64 | } 65 | 66 | - (void)viewWillAppear:(BOOL)animated{ 67 | [super viewWillAppear:animated]; 68 | [(JFImagePickerController *)self.navigationController setLeftTitle:@"取消"]; 69 | placeholder = [UIButton buttonWithType:UIButtonTypeCustom]; 70 | placeholder.frame = CGRectMake(0, 0, 26, 26); 71 | placeholder.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.1]; 72 | placeholder.layer.cornerRadius = 13; 73 | placeholder.layer.borderColor = [UIColor whiteColor].CGColor; 74 | placeholder.layer.borderWidth = 1; 75 | placeholder.titleLabel.font = [UIFont systemFontOfSize:15]; 76 | [placeholder addTarget:self action:@selector(selectPhoto) forControlEvents:UIControlEventTouchUpInside]; 77 | UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:placeholder]; 78 | self.navigationItem.rightBarButtonItem = item; 79 | CGFloat pageWidth = photosView.frame.size.width; 80 | NSInteger page = floor((photosView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 81 | 82 | BOOL hasItem = NO; 83 | NSInteger num = 0; 84 | for (NSDictionary *temp in ASSETHELPER.selectdPhotos) { 85 | if ([[[temp allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld",(long)page, (long)ASSETHELPER.currentGroupIndex]]) { 86 | num = [[[temp allValues] firstObject] intValue]; 87 | hasItem = YES; 88 | } 89 | } 90 | if (hasItem||isPreview) { 91 | if (isPreview) { 92 | num = page+1; 93 | } 94 | placeholder.backgroundColor = [APP_COLOR colorWithAlphaComponent:.9]; 95 | [placeholder setTitle:@(num).stringValue forState:UIControlStateNormal]; 96 | } 97 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearMemory) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; 98 | } 99 | 100 | - (void)viewDidDisappear:(BOOL)animated{ 101 | [super viewDidDisappear:animated]; 102 | ASSETHELPER.previewIndex = -1; 103 | } 104 | 105 | - (void)viewWillDisappear:(BOOL)animated{ 106 | [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; 107 | if (!isBrowser) { 108 | if (ASSETHELPER.selectdPhotos.count>0) { 109 | [(JFImagePickerController *)self.navigationController setLeftTitle:@"预览"]; 110 | } else { 111 | [(JFImagePickerController *)self.navigationController setLeftTitle:@""]; 112 | } 113 | if (isPreview) { 114 | NSMutableArray *needDelete = [NSMutableArray array]; 115 | for (NSNumber *num in disabledIndexs) { 116 | NSDictionary *temp = [ASSETHELPER.selectdPhotos objectAtIndex:num.intValue]; 117 | NSString *str = [[temp allKeys] firstObject]; 118 | NSArray *arr = [str componentsSeparatedByString:@"-"]; 119 | int row = [arr[0] intValue]; 120 | int group = [arr[1] intValue]; 121 | if (group==ASSETHELPER.currentGroupIndex) { 122 | [[_delegate cellForRow:row] selectOfNum:-1]; 123 | } 124 | for (NSDictionary *dict in [ASSETHELPER.selectdPhotos copy]) { 125 | if ([[[dict allValues] firstObject] intValue]>[[[temp allValues] firstObject] intValue]) { 126 | NSInteger index = [ASSETHELPER.selectdPhotos indexOfObject:dict]; 127 | [ASSETHELPER.selectdPhotos removeObject:dict]; 128 | [ASSETHELPER.selectdPhotos insertObject:@{[[dict allKeys] firstObject]: @([[[dict allValues] firstObject] intValue]-1)} atIndex:index]; 129 | } 130 | } 131 | [needDelete addObject:num]; 132 | } 133 | for (NSNumber *num in needDelete) { 134 | [ASSETHELPER.selectdPhotos removeObjectAtIndex:num.intValue]; 135 | [ASSETHELPER.selectdAssets removeObjectAtIndex:num.intValue]; 136 | } 137 | [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadNum" object:nil]; 138 | [[NSNotificationCenter defaultCenter] postNotificationName:@"selectdPhotos" object:nil]; 139 | } 140 | } 141 | } 142 | 143 | - (void)viewDidLoad 144 | { 145 | [super viewDidLoad]; 146 | disabledIndexs = [[NSMutableArray alloc] init]; 147 | backupData = [[NSMutableArray alloc] init]; 148 | } 149 | 150 | - (void)clearMemory{ 151 | CGFloat pageWidth = photosView.frame.size.width; 152 | int page = floor((photosView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 153 | for (UIView *temp in photosView.subviews) { 154 | if (temp.tag!=page+1) { 155 | [temp removeFromSuperview]; 156 | } 157 | } 158 | } 159 | 160 | - (void)selectPhoto{ 161 | CGFloat pageWidth = photosView.frame.size.width; 162 | NSInteger page = floor((photosView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 163 | if (!isPreview) { 164 | if ([placeholder.backgroundColor isEqual:[[UIColor blackColor] colorWithAlphaComponent:.1]]) { 165 | if (ASSETHELPER.selectdPhotos.count>=9) { 166 | return; 167 | } 168 | [ASSETHELPER.selectdPhotos addObject:@{[NSString stringWithFormat:@"%ld-%ld",(long)page, (long)ASSETHELPER.currentGroupIndex]: @(ASSETHELPER.selectdPhotos.count+1)}]; 169 | 170 | [ASSETHELPER.selectdAssets addObject:[ASSETHELPER getAssetAtIndex:page]]; 171 | 172 | placeholder.transform = CGAffineTransformMakeScale(.5, .5); 173 | [UIView animateWithDuration:.3 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 174 | placeholder.transform = CGAffineTransformIdentity; 175 | } completion:nil]; 176 | placeholder.backgroundColor = [APP_COLOR colorWithAlphaComponent:.9]; 177 | [placeholder setTitle:@(ASSETHELPER.selectdPhotos.count).stringValue forState:UIControlStateNormal]; 178 | [[_delegate cellForRow:page] selectOfNum:ASSETHELPER.selectdPhotos.count]; 179 | } else { 180 | NSInteger index = 0; 181 | NSInteger num = 0; 182 | for (NSDictionary *dict in ASSETHELPER.selectdPhotos) { 183 | if ([[[dict allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld",(long)page, (long)ASSETHELPER.currentGroupIndex]]) { 184 | index = [ASSETHELPER.selectdPhotos indexOfObject:dict]; 185 | num = [[[dict allValues] firstObject] intValue]; 186 | } 187 | } 188 | for (NSDictionary *dict in [ASSETHELPER.selectdPhotos copy]) { 189 | if ([[[dict allValues] firstObject] intValue]>num) { 190 | NSInteger index = [ASSETHELPER.selectdPhotos indexOfObject:dict]; 191 | [ASSETHELPER.selectdPhotos removeObject:dict]; 192 | [ASSETHELPER.selectdPhotos insertObject:@{[[dict allKeys] firstObject]: @([[[dict allValues] firstObject] intValue]-1)} atIndex:index]; 193 | } 194 | } 195 | 196 | placeholder.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.1]; 197 | [placeholder setTitle:@"" forState:UIControlStateNormal]; 198 | [ASSETHELPER.selectdAssets removeObjectAtIndex:index]; 199 | [ASSETHELPER.selectdPhotos removeObjectAtIndex:index]; 200 | [[_delegate cellForRow:page] selectOfNum:-1]; 201 | [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadNum" object:nil]; 202 | } 203 | } else { 204 | if ([placeholder.backgroundColor isEqual:[[UIColor blackColor] colorWithAlphaComponent:.1]]) { 205 | placeholder.transform = CGAffineTransformMakeScale(.5, .5); 206 | [UIView animateWithDuration:.3 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 207 | placeholder.transform = CGAffineTransformIdentity; 208 | } completion:nil]; 209 | [disabledIndexs removeObject:@(page)]; 210 | placeholder.backgroundColor = [APP_COLOR colorWithAlphaComponent:.9]; 211 | [placeholder setTitle:@(page+1).stringValue forState:UIControlStateNormal]; 212 | } else { 213 | [disabledIndexs addObject:@(page)]; 214 | placeholder.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.1]; 215 | [placeholder setTitle:@"" forState:UIControlStateNormal]; 216 | } 217 | } 218 | [[NSNotificationCenter defaultCenter] postNotificationName:@"selectdPhotos" object:nil]; 219 | } 220 | 221 | - (void)setDelegate:(id)delegate{ 222 | _delegate = delegate; 223 | photoCount = [_delegate numOfPhotosFromPhotoBrowser:self]; 224 | photosView.contentSize = CGSizeMake(photosView.frame.size.width*photoCount, 0); 225 | photosView.contentOffset = CGPointMake(photosView.frame.size.width*[_delegate currentIndexFromPhotoBrowser:self], 0); 226 | CGFloat pageWidth = photosView.frame.size.width; 227 | int page = floor((photosView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 228 | currentPage = page; 229 | [self loadScrollViewWithPage:page-1]; 230 | [self loadScrollViewWithPage:page]; 231 | [self loadScrollViewWithPage:page+1]; 232 | } 233 | 234 | - (void)scrollViewDidScroll:(UIScrollView *)scrollview{ 235 | if (!scrollview.tracking&&!scrollview.decelerating) { 236 | return; 237 | } 238 | CGFloat pageWidth = scrollview.frame.size.width; 239 | NSInteger page = floor((scrollview.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 240 | currentPage = page; 241 | [self clearScrollViewWithPage:page-2]; 242 | [self clearScrollViewWithPage:page+2]; 243 | [self loadScrollViewWithPage:page-1]; 244 | [self loadScrollViewWithPage:page]; 245 | [self loadScrollViewWithPage:page+1]; 246 | 247 | if (!isBrowser) { 248 | BOOL hasItem = NO; 249 | NSInteger num = 0; 250 | for (NSDictionary *temp in ASSETHELPER.selectdPhotos) { 251 | if ([[[temp allKeys] firstObject] isEqualToString:[NSString stringWithFormat:@"%ld-%ld",(long)page, (long)ASSETHELPER.currentGroupIndex]]) { 252 | num = [[[temp allValues] firstObject] intValue]; 253 | hasItem = YES; 254 | } 255 | } 256 | if ([disabledIndexs indexOfObject:@(page)]==NSNotFound&&(hasItem||isPreview)) { 257 | if (isPreview) { 258 | num = page+1; 259 | } 260 | placeholder.backgroundColor = [APP_COLOR colorWithAlphaComponent:.9]; 261 | [placeholder setTitle:@(num).stringValue forState:UIControlStateNormal]; 262 | } else { 263 | placeholder.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.1]; 264 | [placeholder setTitle:@"" forState:UIControlStateNormal]; 265 | } 266 | } 267 | } 268 | 269 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 270 | CGFloat pageWidth = scrollView.frame.size.width; 271 | NSInteger page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 272 | if ([_delegate respondsToSelector:@selector(photoBrowser:didShowPage:)]) { 273 | [_delegate photoBrowser:self didShowPage:page]; 274 | } 275 | JFPhotoView *photoView = (JFPhotoView *)[photosView viewWithTag:page+2]; 276 | if (photoView!=nil) { 277 | [photoView reset]; 278 | } 279 | JFPhotoView *photoView1 = (JFPhotoView *)[photosView viewWithTag:page]; 280 | if (photoView1!=nil) { 281 | [photoView reset]; 282 | } 283 | } 284 | 285 | - (void)clearScrollViewWithPage:(NSInteger)page{ 286 | if (page < 0) 287 | return; 288 | if (page >= photoCount) 289 | return; 290 | JFPhotoView *photoView = (JFPhotoView *)[photosView viewWithTag:page+1]; 291 | if (photoView) { 292 | [photoView removeFromSuperview]; 293 | } 294 | } 295 | 296 | - (void)loadScrollViewWithPage:(NSInteger)page 297 | { 298 | if (page < 0) 299 | return; 300 | if (page >= photoCount) 301 | return; 302 | 303 | JFPhotoView *photoView = (JFPhotoView *)[photosView viewWithTag:page+1]; 304 | if (photoView==nil) { 305 | photoView = [[JFPhotoView alloc] initWithFrame:CGRectMake(photosView.frame.size.width*page, 0, photosView.frame.size.width-10, photosView.frame.size.height)]; 306 | photoView.tag = page+1; 307 | photoView.photoDelegate = self; 308 | [photosView addSubview:photoView]; 309 | [photoView loadImage:[_delegate assetWithIndex:page fromPhotoBrowser:self]]; 310 | } else if (photoView.hidden) { 311 | photoView.hidden = NO; 312 | } 313 | } 314 | 315 | - (void)tap{ 316 | if (self.navigationController.navigationBarHidden) { 317 | [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade]; 318 | [self.navigationController setNavigationBarHidden:NO animated:YES]; 319 | [UIView animateWithDuration:.3 animations:^{ 320 | CGRect frame = [(JFImagePickerController *)self.navigationController customToolbar].frame; 321 | frame.origin.y = [UIScreen mainScreen].bounds.size.height-44; 322 | [(JFImagePickerController *)self.navigationController customToolbar].frame = frame; 323 | }]; 324 | } else { 325 | [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; 326 | [self.navigationController setNavigationBarHidden:YES animated:YES]; 327 | [UIView animateWithDuration:.3 animations:^{ 328 | CGRect frame = [(JFImagePickerController *)self.navigationController customToolbar].frame; 329 | frame.origin.y = [UIScreen mainScreen].bounds.size.height; 330 | [(JFImagePickerController *)self.navigationController customToolbar].frame = frame; 331 | }]; 332 | } 333 | } 334 | 335 | @end 336 | -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFPhotoView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JFPhotoView.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JFPhotoView : UIScrollView 13 | 14 | @property (nonatomic, strong) UIImageView *imageView; 15 | @property (nonatomic, weak) id photoDelegate; 16 | 17 | - (void)reloadRotate; 18 | - (void)reset; 19 | - (void)clearMemory; 20 | - (void)loadImage:(ALAsset *)asset; 21 | 22 | @end 23 | 24 | @protocol JFPhotoDelegate 25 | 26 | - (void)tap; 27 | 28 | @end -------------------------------------------------------------------------------- /JFImagePickerController/JFImagePickerController/JFPhotoView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFPhotoView.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15-7-3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "JFPhotoView.h" 10 | #import "JFAssetHelper.h" 11 | #import "JFImageManager.h" 12 | 13 | @implementation JFPhotoView { 14 | BOOL needLayout; 15 | NSMutableArray *splitImage; 16 | CGImageRef originImageRef; 17 | float splitHeight; 18 | BOOL zooming; 19 | CGSize originSize; 20 | } 21 | 22 | - (instancetype)initWithFrame:(CGRect)frame{ 23 | self = [super initWithFrame:frame]; 24 | if (self) { 25 | needLayout = YES; 26 | self.delegate = self; 27 | self.clipsToBounds = YES; 28 | self.backgroundColor = [UIColor clearColor]; 29 | 30 | _imageView = [[UIImageView alloc] initWithImage:nil]; 31 | _imageView.backgroundColor = [UIColor clearColor]; 32 | _imageView.frame = CGRectZero; 33 | _imageView.userInteractionEnabled = YES; 34 | _imageView.contentMode = UIViewContentModeScaleAspectFill; 35 | [self addSubview:_imageView]; 36 | 37 | self.maximumZoomScale = 1; 38 | self.minimumZoomScale = .1; 39 | self.zoomScale = 1; 40 | self.contentSize = CGSizeMake(0, 0); 41 | 42 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; 43 | tap.numberOfTapsRequired = 1; 44 | [_imageView addGestureRecognizer:tap]; 45 | 46 | UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)]; 47 | doubleTap.numberOfTapsRequired = 2; 48 | [_imageView addGestureRecognizer:doubleTap]; 49 | [tap requireGestureRecognizerToFail:doubleTap]; 50 | 51 | UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; 52 | [self addGestureRecognizer:longpress]; 53 | } 54 | return self; 55 | } 56 | 57 | - (void)removeFromSuperview{ 58 | CGImageRelease(originImageRef); 59 | [self clearMemory]; 60 | [super removeFromSuperview]; 61 | } 62 | 63 | - (void)longPress:(UILongPressGestureRecognizer *)gesture{ 64 | if (gesture.state==UIGestureRecognizerStateBegan) { 65 | } 66 | } 67 | 68 | - (void)reset{ 69 | self.zoomScale = self.minimumZoomScale; 70 | self.contentOffset = CGPointZero; 71 | } 72 | 73 | - (void)reloadRotate{ 74 | float progress1 = self.contentOffset.y/self.contentSize.height; 75 | if (splitImage&&splitImage.count>0) { 76 | CGSize size = originSize; 77 | float scale = size.width/self.frame.size.width; 78 | splitHeight = self.frame.size.height*scale; 79 | int part = size.height/splitHeight; 80 | if ((NSInteger)size.height%(NSInteger)splitHeight!=0) { 81 | part+=1; 82 | } 83 | [splitImage removeAllObjects]; 84 | for (int i=0; iself.frame.size.height) { 95 | self.contentOffset = CGPointMake(0, self.contentSize.height*progress1); 96 | } 97 | } 98 | 99 | - (void)setMaxMinZoomScalesForCurrentBounds:(BOOL)rotate{ 100 | self.maximumZoomScale = 1; 101 | self.minimumZoomScale = .1; 102 | self.zoomScale = 1; 103 | CGRect photoImageViewFrame; 104 | photoImageViewFrame.origin = CGPointZero; 105 | if (splitImage&&splitImage.count>0) { 106 | photoImageViewFrame.size = originSize; 107 | } else { 108 | photoImageViewFrame.size = _imageView.image.size; 109 | } 110 | _imageView.frame = photoImageViewFrame; 111 | self.contentSize = photoImageViewFrame.size; 112 | 113 | // Bail if no image 114 | if (_imageView.image == nil&&splitImage==nil&&splitImage.count<=0) return; 115 | 116 | // Reset position 117 | // _imageView.frame = CGRectMake(0, 0, _imageView.frame.size.width, _imageView.frame.size.height); 118 | CGFloat minScale = (self.bounds.size.width-.1)/_imageView.frame.size.width; 119 | 120 | // Calculate Max 121 | CGFloat maxScale = 1+minScale; 122 | if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 123 | // Let them go a bit bigger on a bigger screen! 124 | maxScale = 2.5; 125 | } 126 | 127 | // Set min/max zoom 128 | self.maximumZoomScale = maxScale; 129 | self.minimumZoomScale = minScale; 130 | 131 | // Initial zoom 132 | // float zoomScale = [self initialZoomScaleWithMinScale]; 133 | self.zoomScale = self.minimumZoomScale; 134 | 135 | self.contentOffset = CGPointZero; 136 | 137 | // If we're zooming to fill then centralise 138 | // if (self.zoomScale != minScale) { 139 | // // Centralise 140 | // self.contentOffset = CGPointMake((_imageView.width * self.zoomScale - photoImageViewFrame.size.width) / 2.0, 141 | // (_imageView.height * self.zoomScale - photoImageViewFrame.size.height) / 2.0); 142 | // // Disable scrolling initially until the first pinch to fix issues with swiping on an initally zoomed in photo 143 | // self.scrollEnabled = NO; 144 | // } 145 | // Layout 146 | needLayout = YES; 147 | [self setNeedsLayout]; 148 | } 149 | 150 | - (void)layoutSubviews{ 151 | if (!needLayout) { 152 | return; 153 | } 154 | [super layoutSubviews]; 155 | if (!self.delegate) { 156 | return; 157 | } 158 | // Center the image as it becomes smaller than the size of the screen 159 | CGSize boundsSize = self.bounds.size; 160 | CGRect frameToCenter = _imageView.frame; 161 | 162 | // Horizontally 163 | if (frameToCenter.size.width < boundsSize.width) { 164 | frameToCenter.origin.x = floorf((boundsSize.width - frameToCenter.size.width) / 2.0); 165 | } else { 166 | frameToCenter.origin.x = 0; 167 | } 168 | 169 | // Vertically 170 | if (frameToCenter.size.height < boundsSize.height) { 171 | frameToCenter.origin.y = floorf((boundsSize.height - frameToCenter.size.height) / 2.0); 172 | } else { 173 | frameToCenter.origin.y = 0; 174 | } 175 | 176 | // Center 177 | if (!CGRectEqualToRect(_imageView.frame, frameToCenter)){ 178 | _imageView.frame = frameToCenter; 179 | } 180 | } 181 | 182 | - (void)loadImage:(ALAsset *)asset{ 183 | _imageView.image = [ASSETHELPER getImageFromAsset:asset type:ASSET_PHOTO_ASPECT_THUMBNAIL]; 184 | [self progressImage]; 185 | NSInteger flag = self.tag; 186 | [[JFImageManager sharedManager] imageWithAsset:asset resultHandler:^(CGImageRef imageRef, BOOL longImage) { 187 | if (flag==self.tag) { 188 | if (longImage) { 189 | originSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)); 190 | splitImage = [[NSMutableArray alloc] init]; 191 | originImageRef = imageRef; 192 | float scale = originSize.width/self.frame.size.width; 193 | splitHeight = self.frame.size.height*scale; 194 | splitHeight = ceilf(splitHeight); 195 | int part = originSize.height/splitHeight; 196 | if ((NSInteger)originSize.height%(NSInteger)splitHeight!=0) { 197 | part+=1; 198 | } 199 | for (int i=0; i0) { 219 | for (UIView *temp in _imageView.subviews) { 220 | [temp removeFromSuperview]; 221 | } 222 | [self loadScrollViewWithPage:0]; 223 | [self loadScrollViewWithPage:1]; 224 | } else { 225 | [self setMaxMinZoomScalesForCurrentBounds:NO]; 226 | } 227 | } 228 | 229 | - (void)clearScrollViewWithPage:(NSInteger)page{ 230 | if (page < 0) 231 | return; 232 | if (page >= splitImage.count) 233 | return; 234 | UIImageView *photoView = (UIImageView *)[_imageView viewWithTag:page+1]; 235 | if (photoView) { 236 | photoView.image = nil; 237 | [photoView removeFromSuperview]; 238 | } 239 | } 240 | 241 | - (UIImage *)normalizeImage:(UIImage *)image { 242 | int width = image.size.width; 243 | int height = image.size.height; 244 | CGColorSpaceRef genericColorSpace = CGColorSpaceCreateDeviceRGB(); 245 | CGContextRef thumbBitmapCtxt = CGBitmapContextCreate(NULL, 246 | width, 247 | height, 248 | 8, (4 * width), 249 | genericColorSpace, 250 | (CGBitmapInfo)kCGImageAlphaPremultipliedLast); 251 | CGColorSpaceRelease(genericColorSpace); 252 | CGContextSetInterpolationQuality(thumbBitmapCtxt, kCGInterpolationDefault); 253 | CGRect destRect = CGRectMake(0, 0, width, height); 254 | CGContextDrawImage(thumbBitmapCtxt, destRect, image.CGImage); 255 | CGImageRef tmpThumbImage = CGBitmapContextCreateImage(thumbBitmapCtxt); 256 | CGContextRelease(thumbBitmapCtxt); 257 | UIImage *result = [UIImage imageWithCGImage:tmpThumbImage]; 258 | CGImageRelease(tmpThumbImage); 259 | 260 | return result; 261 | } 262 | 263 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 264 | if (!scrollView.decelerating&&!scrollView.tracking&&!scrollView.dragging) { 265 | return; 266 | } 267 | if (splitImage&&splitImage.count>0) { 268 | float scale = 1+(scrollView.zoomScale-scrollView.minimumZoomScale); 269 | CGFloat pageHeight = scrollView.frame.size.height*scale; 270 | int page = floor((scrollView.contentOffset.y - pageHeight / 2) / pageHeight) + 1; 271 | if (fabs(scrollView.zoomScale-scrollView.minimumZoomScale)<=.01) { 272 | [self clearScrollViewWithPage:page-2]; 273 | [self clearScrollViewWithPage:page+2]; 274 | } 275 | [self loadScrollViewWithPage:page-1]; 276 | [self loadScrollViewWithPage:page]; 277 | [self loadScrollViewWithPage:page+1]; 278 | } 279 | } 280 | 281 | - (void)loadScrollViewWithPage:(NSInteger)page 282 | { 283 | if (page < 0) 284 | return; 285 | if (page >= splitImage.count) 286 | return; 287 | 288 | UIImageView *photoView = (UIImageView *)[_imageView viewWithTag:page+1]; 289 | if (photoView==nil) { 290 | CGRect partRect = CGRectFromString(splitImage[page]); 291 | photoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, page*splitHeight, partRect.size.width, partRect.size.height)]; 292 | photoView.tag = page+1; 293 | [_imageView addSubview:photoView]; 294 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 295 | CGImageRef subimageRef = CGImageCreateWithImageInRect(originImageRef, partRect); 296 | UIImage *image = [self normalizeImage:[UIImage imageWithCGImage:subimageRef]]; 297 | dispatch_async(dispatch_get_main_queue(), ^{ 298 | photoView.image = image; 299 | CGRect frame = photoView.frame; 300 | frame.size.height = image.size.height; 301 | photoView.frame = frame; 302 | if (_imageView.image) { 303 | [self setMaxMinZoomScalesForCurrentBounds:NO]; 304 | _imageView.image = nil; 305 | } 306 | }); 307 | CGImageRelease(subimageRef); 308 | subimageRef = nil; 309 | }); 310 | } 311 | } 312 | 313 | - (void)clearMemory{ 314 | if (splitImage&&splitImage.count>0) { 315 | float scale = 1+(self.zoomScale-self.minimumZoomScale); 316 | CGFloat pageHeight = self.frame.size.height*scale; 317 | int page = floor((self.contentOffset.y - pageHeight / 2) / pageHeight) + 1; 318 | if (fabs(self.zoomScale-self.minimumZoomScale)<=.01) { 319 | for (NSInteger i=0; i0) { 372 | // return; 373 | // } 374 | CGPoint touchPoint = [tap locationInView:_imageView]; 375 | // Zoom 376 | if (self.zoomScale != self.minimumZoomScale && self.zoomScale != [self initialZoomScaleWithMinScale]) { 377 | // Zoom out 378 | [self setZoomScale:self.minimumZoomScale animated:YES]; 379 | } else { 380 | // Zoom in to twice the size 381 | CGFloat newZoomScale = ((self.maximumZoomScale + self.minimumZoomScale) / 2); 382 | CGFloat xsize = self.bounds.size.width / newZoomScale; 383 | CGFloat ysize = self.bounds.size.height / newZoomScale; 384 | [self zoomToRect:CGRectMake(touchPoint.x - xsize/2, touchPoint.y - ysize/2, xsize, ysize) animated:YES]; 385 | 386 | } 387 | } 388 | 389 | - (void)dealloc{ 390 | self.delegate = nil; 391 | _imageView.image = nil; 392 | // NSLog(@"dealloc photo", nil); 393 | } 394 | 395 | @end 396 | -------------------------------------------------------------------------------- /JFImagePickerController/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /JFImagePickerController/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "JFImagePickerController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController { 17 | NSMutableArray *photos; 18 | UICollectionView *photosList; 19 | } 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | self.extendedLayoutIncludesOpaqueBars = YES; 24 | self.automaticallyAdjustsScrollViewInsets = NO; 25 | self.edgesForExtendedLayout = UIRectEdgeAll; 26 | 27 | photos = [[NSMutableArray alloc] init]; 28 | 29 | UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(pickPhotos)]; 30 | self.navigationItem.rightBarButtonItem = addItem; 31 | self.navigationItem.title = @"JFImagePicker"; 32 | 33 | UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 34 | flowLayout.minimumInteritemSpacing = 0; 35 | flowLayout.minimumLineSpacing = 3; 36 | NSInteger size = [UIScreen mainScreen].bounds.size.width/4-1; 37 | if (size%2!=0) { 38 | size-=1; 39 | } 40 | flowLayout.itemSize = CGSizeMake(size, size); 41 | flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); 42 | 43 | photosList = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout]; 44 | photosList.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); 45 | photosList.scrollIndicatorInsets = photosList.contentInset; 46 | photosList.delegate = self; 47 | photosList.dataSource = self; 48 | photosList.backgroundColor = [UIColor whiteColor]; 49 | photosList.alwaysBounceVertical = YES; 50 | [self.view addSubview:photosList]; 51 | [photosList registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"imagePickerCell"]; 52 | } 53 | 54 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 55 | return 1; 56 | } 57 | 58 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 59 | return photos.count; 60 | } 61 | 62 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 63 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imagePickerCell" forIndexPath:indexPath]; 64 | ALAsset *asset = photos[indexPath.row]; 65 | UIImageView *imgView = (UIImageView *)[cell.contentView viewWithTag:1]; 66 | if (!imgView) { 67 | imgView = [[UIImageView alloc] initWithFrame:cell.bounds]; 68 | imgView.contentMode = UIViewContentModeScaleAspectFill; 69 | imgView.clipsToBounds = YES; 70 | imgView.tag = 1; 71 | [cell addSubview:imgView]; 72 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(preview:)]; 73 | [cell addGestureRecognizer:tap]; 74 | } 75 | cell.tag = indexPath.item; 76 | [[JFImageManager sharedManager] thumbWithAsset:asset resultHandler:^(UIImage *result) { 77 | if (cell.tag==indexPath.item) { 78 | imgView.image = result; 79 | } 80 | }]; 81 | return cell; 82 | } 83 | 84 | - (void)preview:(UITapGestureRecognizer *)tap{ 85 | UIView *temp = tap.view; 86 | JFImagePickerController *picker = [[JFImagePickerController alloc] initWithPreviewIndex:temp.tag]; 87 | picker.pickerDelegate = self; 88 | [self presentViewController:picker animated:YES completion:nil]; 89 | } 90 | 91 | - (void)pickPhotos{ 92 | JFImagePickerController *picker = [[JFImagePickerController alloc] initWithRootViewController:nil]; 93 | picker.pickerDelegate = self; 94 | [self presentViewController:picker animated:YES completion:nil]; 95 | } 96 | 97 | #pragma mark - ImagePicker Delegate 98 | 99 | - (void)imagePickerDidFinished:(JFImagePickerController *)picker{ 100 | [photos removeAllObjects]; 101 | [photos addObjectsFromArray:picker.assets]; 102 | [photosList reloadData]; 103 | [self imagePickerDidCancel:picker]; 104 | } 105 | 106 | - (void)imagePickerDidCancel:(JFImagePickerController *)picker{ 107 | [picker dismissViewControllerAnimated:YES completion:nil]; 108 | } 109 | 110 | - (void)didReceiveMemoryWarning { 111 | [super didReceiveMemoryWarning]; 112 | // Dispose of any resources that can be recreated. 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /JFImagePickerController/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JFImagePickerController 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. 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 | -------------------------------------------------------------------------------- /JFImagePickerControllerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.Johnil.$(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 | -------------------------------------------------------------------------------- /JFImagePickerControllerTests/JFImagePickerControllerTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JFImagePickerControllerTests.m 3 | // JFImagePickerControllerTests 4 | // 5 | // Created by Johnil on 15/7/3. 6 | // Copyright (c) 2015年 Johnil. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JFImagePickerControllerTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation JFImagePickerControllerTests 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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JFImagePicker 2 | 高性能多选图片库 3 | 4 | 5 | ###功能 6 | 7 | 多选照片 8 | 9 | 预览已选照片 10 | 11 | 针对超大图片优化 12 | 13 | ###Podfile 14 | 15 | ```ruby 16 | platform :ios, '7.0' 17 | pod 'JFImagePicker' 18 | ``` 19 | 20 | ###How to Use 21 | 22 | ##### Import 23 | ```objective-c 24 | #import "JFImagePickerController.h" 25 | 26 | @interface ViewController () 27 | 28 | @end 29 | 30 | ``` 31 | 32 | ##### Load JFImagePicker 33 | ```objective-c 34 | JFImagePickerController *picker = [[JFImagePickerController alloc] initWithRootViewController:nil]; 35 | picker.pickerDelegate = self; 36 | [self presentViewController:picker animated:YES completion:nil]; 37 | ``` 38 | 39 | ##### Delegate Method 40 | ```objective-c 41 | - (void)imagePickerDidFinished:(JFImagePickerController *)picker{ 42 | //picker.assets is all choices photo 43 | [picker dismissViewControllerAnimated:YES completion:nil]; 44 | } 45 | 46 | - (void)imagePickerDidCancel:(JFImagePickerController *)picker{ 47 | [picker dismissViewControllerAnimated:YES completion:nil]; 48 | } 49 | ``` 50 | 51 | ##### Load Thumb UIImage 52 | ```objective-c 53 | [[JFImageManager sharedManager] thumbWithAsset:asset resultHandler:^(UIImage *result) { 54 | //do something 55 | }]; 56 | ``` 57 | 58 | ##### Load UIImage for best size 59 | ```objective-c 60 | [[JFImageManager sharedManager] imageWithAsset:asset resultHandler:^(UIImage *result) { 61 | //do something 62 | }]; 63 | ``` 64 | 65 | ##### clear 66 | ```objective-c 67 | [JFImagePickerController clear]; //clear datas 68 | ``` 69 | 70 | #License 71 | 72 | JFImagePicker is released under the MIT license. See LICENSE for details. 73 | -------------------------------------------------------------------------------- /assets/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnil/JFImagePickerController/a6df67631927239af3f1a470ae4e43a16986374c/assets/screenshot1.png -------------------------------------------------------------------------------- /assets/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnil/JFImagePickerController/a6df67631927239af3f1a470ae4e43a16986374c/assets/screenshot2.png --------------------------------------------------------------------------------