├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Cartfile ├── FTImageViewer.podspec ├── FTImageViewer.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── FTImageViewer ├── FTImageViewer.h ├── FTImageViewer.swift ├── FTResource.bundle │ ├── close.png │ └── save.png └── Info.plist ├── FTImageViewerDemo ├── FTImageViewerDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── FTImageViewerDemo.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── FTImageViewerDemo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── DemoTableViewCell.swift │ ├── Info.plist │ └── ViewController.swift ├── Podfile └── Podfile.lock ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | 6 | .DS_Store 7 | 8 | 9 | ## Build generated 10 | build/ 11 | DerivedData 12 | 13 | ## Various settings 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata 23 | 24 | ## Other 25 | *.xccheckout 26 | *.moved-aside 27 | *.xcuserstate 28 | *.xcscmblueprint 29 | 30 | ## Obj-C/Swift specific 31 | *.hmap 32 | *.ipa 33 | 34 | ## Playgrounds 35 | timeline.xctimeline 36 | playground.xcworkspace 37 | 38 | # Swift Package Manager 39 | # 40 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 41 | # Packages/ 42 | .build/ 43 | 44 | # CocoaPods 45 | # 46 | # We recommend against adding the Pods directory to your .gitignore. However 47 | # you should judge for yourself, the pros and cons are mentioned at: 48 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 49 | # 50 | Pods/ 51 | 52 | # Carthage 53 | # 54 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 55 | Carthage/Checkouts 56 | 57 | Carthage/Build 58 | 59 | # fastlane 60 | # 61 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 62 | # screenshots whenever they are needed. 63 | # For more information about the recommended setup visit: 64 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 65 | 66 | fastlane/report.xml 67 | fastlane/screenshots 68 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: Swift 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # FTImageViewer 2 | 3 | ## ChangeLog 4 | 5 | | Version | Date | ChangeLog | 6 | | :--------: | :--------: | :-------- | 7 | | 1.5.0 | 2016-10-12 | trying to update to Swift 3.0 | 8 | | 1.9.5 | 2016-10-19 | update to Swift 3.0 | 9 | | 1.9.7 | 2016-11-21 | FIX: activityIndicator not showing | 10 | | 1.9.8 | 2016-11-29 | nothing updated... | 11 | | 1.9.9 | 2017-01-09 | Supports both `portrait` and `landscape` | 12 | | 2.0.0 | 2017-01-09 | Fix some bugs | 13 | | 2.0.1 | 2017-01-19 | add local image support | 14 | | 2.0.5 | 2018-02-07 | Mohsinali Matiya : fix iPhoneX tabbar layout issue | 15 | | 2.0.6 | 2019-04-23 | Swift 5 support. | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- 1 | github "onevcat/Kingfisher" "5.0.1" 2 | -------------------------------------------------------------------------------- /FTImageViewer.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "FTImageViewer" 4 | s.version = "2.0.8" 5 | s.summary = "A simple ImageViewer and ImageGrid. Preview images with just a few lines of code." 6 | s.description = <<-DESC 7 | FTImageViewer. A simple ImageViewer and ImageGrid. Can preview images with just a few lines of code. 8 | I wrote this for my future projects. Feel free to try it in your own projects! 9 | DESC 10 | s.homepage = "https://github.com/liufengting/FTImageViewer" 11 | s.license = { :type => "MIT", :file => "LICENSE" } 12 | s.author = { "liufengting" => "wo157121900@me.com" } 13 | s.platform = :ios, "13.0" 14 | s.source = { :git => "https://github.com/liufengting/FTImageViewer.git", :tag => "#{s.version}" } 15 | s.source_files = "FTImageViewer", "FTImageViewer/*.{h,m,swift,xib}" 16 | s.resources = "FTImageViewer/*.{bundle}" 17 | s.requires_arc = true 18 | s.framework = "UIKit" 19 | s.swift_versions = '5.0' 20 | s.dependency 'Kingfisher' 21 | 22 | end 23 | -------------------------------------------------------------------------------- /FTImageViewer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2A84FF30269576C000D54C99 /* FTImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A84FF2E269576C000D54C99 /* FTImageViewer.swift */; }; 11 | 2A84FF31269576C000D54C99 /* FTResource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 2A84FF2F269576C000D54C99 /* FTResource.bundle */; }; 12 | 2A9873E826957591004F4888 /* FTImageViewer.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A9873E626957591004F4888 /* FTImageViewer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXFileReference section */ 16 | 2A84FF2E269576C000D54C99 /* FTImageViewer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTImageViewer.swift; sourceTree = ""; }; 17 | 2A84FF2F269576C000D54C99 /* FTResource.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = FTResource.bundle; sourceTree = ""; }; 18 | 2A9873E326957591004F4888 /* FTImageViewer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FTImageViewer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 2A9873E626957591004F4888 /* FTImageViewer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FTImageViewer.h; sourceTree = ""; }; 20 | 2A9873E726957591004F4888 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 21 | /* End PBXFileReference section */ 22 | 23 | /* Begin PBXFrameworksBuildPhase section */ 24 | 2A9873E026957591004F4888 /* Frameworks */ = { 25 | isa = PBXFrameworksBuildPhase; 26 | buildActionMask = 2147483647; 27 | files = ( 28 | ); 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXFrameworksBuildPhase section */ 32 | 33 | /* Begin PBXGroup section */ 34 | 2A9873D926957591004F4888 = { 35 | isa = PBXGroup; 36 | children = ( 37 | 2A9873E526957591004F4888 /* FTImageViewer */, 38 | 2A9873E426957591004F4888 /* Products */, 39 | ); 40 | sourceTree = ""; 41 | }; 42 | 2A9873E426957591004F4888 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 2A9873E326957591004F4888 /* FTImageViewer.framework */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 2A9873E526957591004F4888 /* FTImageViewer */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 2A9873E626957591004F4888 /* FTImageViewer.h */, 54 | 2A84FF2E269576C000D54C99 /* FTImageViewer.swift */, 55 | 2A84FF2F269576C000D54C99 /* FTResource.bundle */, 56 | 2A9873E726957591004F4888 /* Info.plist */, 57 | ); 58 | path = FTImageViewer; 59 | sourceTree = ""; 60 | }; 61 | /* End PBXGroup section */ 62 | 63 | /* Begin PBXHeadersBuildPhase section */ 64 | 2A9873DE26957591004F4888 /* Headers */ = { 65 | isa = PBXHeadersBuildPhase; 66 | buildActionMask = 2147483647; 67 | files = ( 68 | 2A9873E826957591004F4888 /* FTImageViewer.h in Headers */, 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXHeadersBuildPhase section */ 73 | 74 | /* Begin PBXNativeTarget section */ 75 | 2A9873E226957591004F4888 /* FTImageViewer */ = { 76 | isa = PBXNativeTarget; 77 | buildConfigurationList = 2A9873EB26957591004F4888 /* Build configuration list for PBXNativeTarget "FTImageViewer" */; 78 | buildPhases = ( 79 | 2A9873DE26957591004F4888 /* Headers */, 80 | 2A9873DF26957591004F4888 /* Sources */, 81 | 2A9873E026957591004F4888 /* Frameworks */, 82 | 2A9873E126957591004F4888 /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = FTImageViewer; 89 | packageProductDependencies = ( 90 | ); 91 | productName = FTImageViewer; 92 | productReference = 2A9873E326957591004F4888 /* FTImageViewer.framework */; 93 | productType = "com.apple.product-type.framework"; 94 | }; 95 | /* End PBXNativeTarget section */ 96 | 97 | /* Begin PBXProject section */ 98 | 2A9873DA26957591004F4888 /* Project object */ = { 99 | isa = PBXProject; 100 | attributes = { 101 | LastUpgradeCheck = 1250; 102 | TargetAttributes = { 103 | 2A9873E226957591004F4888 = { 104 | CreatedOnToolsVersion = 12.5.1; 105 | LastSwiftMigration = 1300; 106 | }; 107 | }; 108 | }; 109 | buildConfigurationList = 2A9873DD26957591004F4888 /* Build configuration list for PBXProject "FTImageViewer" */; 110 | compatibilityVersion = "Xcode 9.3"; 111 | developmentRegion = en; 112 | hasScannedForEncodings = 0; 113 | knownRegions = ( 114 | en, 115 | Base, 116 | ); 117 | mainGroup = 2A9873D926957591004F4888; 118 | packageReferences = ( 119 | ); 120 | productRefGroup = 2A9873E426957591004F4888 /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | 2A9873E226957591004F4888 /* FTImageViewer */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | 2A9873E126957591004F4888 /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | 2A84FF31269576C000D54C99 /* FTResource.bundle in Resources */, 135 | ); 136 | runOnlyForDeploymentPostprocessing = 0; 137 | }; 138 | /* End PBXResourcesBuildPhase section */ 139 | 140 | /* Begin PBXSourcesBuildPhase section */ 141 | 2A9873DF26957591004F4888 /* Sources */ = { 142 | isa = PBXSourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | 2A84FF30269576C000D54C99 /* FTImageViewer.swift in Sources */, 146 | ); 147 | runOnlyForDeploymentPostprocessing = 0; 148 | }; 149 | /* End PBXSourcesBuildPhase section */ 150 | 151 | /* Begin XCBuildConfiguration section */ 152 | 2A9873E926957591004F4888 /* Debug */ = { 153 | isa = XCBuildConfiguration; 154 | buildSettings = { 155 | ALWAYS_SEARCH_USER_PATHS = NO; 156 | CLANG_ANALYZER_NONNULL = YES; 157 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_ENABLE_MODULES = YES; 161 | CLANG_ENABLE_OBJC_ARC = YES; 162 | CLANG_ENABLE_OBJC_WEAK = YES; 163 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 164 | CLANG_WARN_BOOL_CONVERSION = YES; 165 | CLANG_WARN_COMMA = YES; 166 | CLANG_WARN_CONSTANT_CONVERSION = YES; 167 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 168 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 169 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 170 | CLANG_WARN_EMPTY_BODY = YES; 171 | CLANG_WARN_ENUM_CONVERSION = YES; 172 | CLANG_WARN_INFINITE_RECURSION = YES; 173 | CLANG_WARN_INT_CONVERSION = YES; 174 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 175 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 176 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 177 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 178 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 179 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 180 | CLANG_WARN_STRICT_PROTOTYPES = YES; 181 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 182 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 183 | CLANG_WARN_UNREACHABLE_CODE = YES; 184 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 185 | COPY_PHASE_STRIP = NO; 186 | CURRENT_PROJECT_VERSION = 1; 187 | DEBUG_INFORMATION_FORMAT = dwarf; 188 | ENABLE_STRICT_OBJC_MSGSEND = YES; 189 | ENABLE_TESTABILITY = YES; 190 | GCC_C_LANGUAGE_STANDARD = gnu11; 191 | GCC_DYNAMIC_NO_PIC = NO; 192 | GCC_NO_COMMON_BLOCKS = YES; 193 | GCC_OPTIMIZATION_LEVEL = 0; 194 | GCC_PREPROCESSOR_DEFINITIONS = ( 195 | "DEBUG=1", 196 | "$(inherited)", 197 | ); 198 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 199 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 200 | GCC_WARN_UNDECLARED_SELECTOR = YES; 201 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 202 | GCC_WARN_UNUSED_FUNCTION = YES; 203 | GCC_WARN_UNUSED_VARIABLE = YES; 204 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 205 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 206 | MTL_FAST_MATH = YES; 207 | ONLY_ACTIVE_ARCH = YES; 208 | SDKROOT = iphoneos; 209 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 210 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 211 | VERSIONING_SYSTEM = "apple-generic"; 212 | VERSION_INFO_PREFIX = ""; 213 | }; 214 | name = Debug; 215 | }; 216 | 2A9873EA26957591004F4888 /* Release */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_ANALYZER_NONNULL = YES; 221 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 223 | CLANG_CXX_LIBRARY = "libc++"; 224 | CLANG_ENABLE_MODULES = YES; 225 | CLANG_ENABLE_OBJC_ARC = YES; 226 | CLANG_ENABLE_OBJC_WEAK = YES; 227 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_COMMA = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 233 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INFINITE_RECURSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 240 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 243 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 244 | CLANG_WARN_STRICT_PROTOTYPES = YES; 245 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 246 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 247 | CLANG_WARN_UNREACHABLE_CODE = YES; 248 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 249 | COPY_PHASE_STRIP = NO; 250 | CURRENT_PROJECT_VERSION = 1; 251 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 252 | ENABLE_NS_ASSERTIONS = NO; 253 | ENABLE_STRICT_OBJC_MSGSEND = YES; 254 | GCC_C_LANGUAGE_STANDARD = gnu11; 255 | GCC_NO_COMMON_BLOCKS = YES; 256 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 257 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 258 | GCC_WARN_UNDECLARED_SELECTOR = YES; 259 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 260 | GCC_WARN_UNUSED_FUNCTION = YES; 261 | GCC_WARN_UNUSED_VARIABLE = YES; 262 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 263 | MTL_ENABLE_DEBUG_INFO = NO; 264 | MTL_FAST_MATH = YES; 265 | SDKROOT = iphoneos; 266 | SWIFT_COMPILATION_MODE = wholemodule; 267 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 268 | VALIDATE_PRODUCT = YES; 269 | VERSIONING_SYSTEM = "apple-generic"; 270 | VERSION_INFO_PREFIX = ""; 271 | }; 272 | name = Release; 273 | }; 274 | 2A9873EC26957591004F4888 /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | CLANG_ENABLE_MODULES = YES; 278 | CODE_SIGN_STYLE = Automatic; 279 | DEFINES_MODULE = YES; 280 | DEVELOPMENT_TEAM = E83AC9WR2F; 281 | DYLIB_COMPATIBILITY_VERSION = 1; 282 | DYLIB_CURRENT_VERSION = 1; 283 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 284 | INFOPLIST_FILE = FTImageViewer/Info.plist; 285 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 286 | LD_RUNPATH_SEARCH_PATHS = ( 287 | "$(inherited)", 288 | "@executable_path/Frameworks", 289 | "@loader_path/Frameworks", 290 | ); 291 | PRODUCT_BUNDLE_IDENTIFIER = com.liufengting.FTImageViewer; 292 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 293 | SKIP_INSTALL = YES; 294 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 295 | SWIFT_VERSION = 5.0; 296 | TARGETED_DEVICE_FAMILY = "1,2"; 297 | }; 298 | name = Debug; 299 | }; 300 | 2A9873ED26957591004F4888 /* Release */ = { 301 | isa = XCBuildConfiguration; 302 | buildSettings = { 303 | CLANG_ENABLE_MODULES = YES; 304 | CODE_SIGN_STYLE = Automatic; 305 | DEFINES_MODULE = YES; 306 | DEVELOPMENT_TEAM = E83AC9WR2F; 307 | DYLIB_COMPATIBILITY_VERSION = 1; 308 | DYLIB_CURRENT_VERSION = 1; 309 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 310 | INFOPLIST_FILE = FTImageViewer/Info.plist; 311 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | "@loader_path/Frameworks", 316 | ); 317 | PRODUCT_BUNDLE_IDENTIFIER = com.liufengting.FTImageViewer; 318 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 319 | SKIP_INSTALL = YES; 320 | SWIFT_VERSION = 5.0; 321 | TARGETED_DEVICE_FAMILY = "1,2"; 322 | }; 323 | name = Release; 324 | }; 325 | /* End XCBuildConfiguration section */ 326 | 327 | /* Begin XCConfigurationList section */ 328 | 2A9873DD26957591004F4888 /* Build configuration list for PBXProject "FTImageViewer" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 2A9873E926957591004F4888 /* Debug */, 332 | 2A9873EA26957591004F4888 /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | 2A9873EB26957591004F4888 /* Build configuration list for PBXNativeTarget "FTImageViewer" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | 2A9873EC26957591004F4888 /* Debug */, 341 | 2A9873ED26957591004F4888 /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | /* End XCConfigurationList section */ 347 | }; 348 | rootObject = 2A9873DA26957591004F4888 /* Project object */; 349 | } 350 | -------------------------------------------------------------------------------- /FTImageViewer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FTImageViewer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FTImageViewer/FTImageViewer.h: -------------------------------------------------------------------------------- 1 | // 2 | // FTImageViewer.h 3 | // FTImageViewer 4 | // 5 | // Created by LiuFengting on 2021/7/7. 6 | // Copyright © 2022年 . All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for FTImageViewer. 12 | FOUNDATION_EXPORT double FTImageViewerVersionNumber; 13 | 14 | //! Project version string for FTImageViewer. 15 | FOUNDATION_EXPORT const unsigned char FTImageViewerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /FTImageViewer/FTImageViewer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FTImageViewer.swift 3 | // FTImageViewer 4 | // 5 | // Created by liufengting on 15/12/17. 6 | // Copyright © 2022年 . All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | //MARK: - Marcros - 13 | 14 | private let FTImageViewerAnimationDuriation: TimeInterval = 0.3 15 | private let FTImageViewerBackgroundColor = UIColor.black 16 | private let FTImageViewBarBackgroundColor = UIColor.black.withAlphaComponent(0.3) 17 | private let FTImageViewBarHeight: CGFloat = 60.0 // for iPhoneX layout issue 18 | private let FTImageViewBarButtonWidth: CGFloat = 30.0 19 | private let FTImageViewBarDefaultMargin: CGFloat = 5.0 20 | private let FTImageGridViewImageMargin: CGFloat = 2.0 21 | private let KCOLOR_BACKGROUND_WHITE = UIColor(red:241/255.0, green:241/255.0, blue:241/255.0, alpha:1.0) 22 | private var FTImageViewerScreenWidth: CGFloat { return UIScreen.main.bounds.width } 23 | private var FTImageViewerScreenHeight: CGFloat { return UIScreen.main.bounds.height } 24 | 25 | protocol FTImageResourceProtocol { 26 | var image: UIImage? { get } 27 | var imageURLString: String? { get } 28 | } 29 | 30 | public struct FTImageResource: FTImageResourceProtocol { 31 | var image: UIImage? 32 | var imageURLString: String? 33 | 34 | public init(image: UIImage?, imageURLString: String?) { 35 | self.image = image 36 | self.imageURLString = imageURLString 37 | } 38 | } 39 | 40 | //MARK: - FTImageViewer extension - 41 | 42 | public extension FTImageViewer { 43 | 44 | //MARK: - showImages with images (supports both images and url strings) 45 | 46 | static func showImages(_ images: [FTImageResource], atIndex: NSInteger, fromSenderArray: [UIView]){ 47 | self.sharedInstance.showImages(images, atIndex: atIndex, fromSenderArray: fromSenderArray) 48 | } 49 | 50 | //MARK: - showImages with image url strings 51 | 52 | static func showImages(_ images: [String], atIndex: NSInteger, fromSenderArray: [UIView]) { 53 | self.sharedInstance.showImages(images, atIndex: atIndex, fromSenderArray: fromSenderArray); 54 | } 55 | } 56 | 57 | //MARK: - FTImageViewer - 58 | 59 | public class FTImageViewer: NSObject, UIScrollViewDelegate, UIGestureRecognizerDelegate { 60 | 61 | private var fromRect: CGRect! 62 | private var currenIndex: NSInteger = 0 63 | private var imageUrlArray: [FTImageResource]! 64 | private var fromSenderRectArray: [CGRect] = [] 65 | private var isPanRecognize: Bool = false 66 | 67 | 68 | //MARK: - sharedInstance 69 | 70 | public class var sharedInstance: FTImageViewer { 71 | struct Static { 72 | static let instance: FTImageViewer = FTImageViewer() 73 | } 74 | return Static.instance 75 | } 76 | 77 | func getWindow() -> UIWindow? { 78 | return UIApplication 79 | .shared 80 | .connectedScenes 81 | .compactMap { $0 as? UIWindowScene } 82 | .flatMap { $0.windows } 83 | .first { $0.isKeyWindow } 84 | } 85 | 86 | //MARK: - showImages with images (supports both images and url strings) 87 | 88 | public func showImages(_ images: [FTImageResource], atIndex: NSInteger, fromSenderArray: [UIView]){ 89 | fromSenderRectArray = [] 90 | 91 | for i in 0 ... fromSenderArray.count-1 { 92 | let rect: CGRect = fromSenderArray[i].superview!.convert(fromSenderArray[i].frame, to:self.getWindow()) 93 | fromSenderRectArray.append(rect) 94 | } 95 | 96 | currenIndex = atIndex 97 | imageUrlArray = images 98 | fromRect = fromSenderRectArray[atIndex] 99 | 100 | backgroundView.backgroundColor = FTImageViewerBackgroundColor 101 | self.getWindow()?.addSubview(backgroundView); 102 | backgroundView.addSubview(scrollView) 103 | backgroundView.addSubview(tabBar) 104 | 105 | beginAnimationView.isHidden = false 106 | beginAnimationView.frame = fromRect 107 | backgroundView.addSubview(beginAnimationView) 108 | 109 | if let img: UIImage = (images[atIndex]).image { 110 | beginAnimationView.image = img 111 | self.beginAnimationView.frame = self.imageFrame(image: img, fromRect: fromRect) 112 | }else if let imageURL: String = (images[atIndex]).imageURLString { 113 | beginAnimationView.kf.setImage(with: URL(string: imageURL)!, placeholder: nil, options: nil, progressBlock: nil) { result in 114 | if let image = try? result.get().image { 115 | self.beginAnimationView.frame = self.imageFrame(image: image, fromRect: self.fromRect) 116 | } else { 117 | return 118 | } 119 | } 120 | } 121 | 122 | UIView.animate(withDuration: FTImageViewerAnimationDuriation, 123 | animations: { () -> Void in 124 | self.beginAnimationView.layer.frame = UIScreen.main.bounds; 125 | }, completion: { (finished) -> Void in 126 | if (finished == true){ 127 | self.setupView(shouldAnimate: true) 128 | } 129 | }) 130 | } 131 | 132 | func imageFrame(image: UIImage, fromRect: CGRect) -> CGRect { 133 | let size = image.size 134 | var rect = CGRect.zero 135 | let imageRadio = size.width/size.height 136 | let origin = fromRect.width/fromRect.height 137 | if imageRadio > origin { 138 | rect.size.width = imageRadio * fromRect.height 139 | rect.size.height = fromRect.height 140 | rect.origin.x = (fromRect.origin.x + fromRect.size.width/2.0) - rect.size.width/2.0 141 | rect.origin.y = fromRect.origin.y 142 | } else { 143 | rect.size.width = fromRect.width 144 | rect.size.height = fromRect.width/imageRadio 145 | rect.origin.x = fromRect.origin.x 146 | rect.origin.y = (fromRect.origin.y + fromRect.size.height/2.0) - rect.size.height/2.0 147 | } 148 | return rect 149 | } 150 | 151 | //MARK: - showImages with image url strings 152 | 153 | public func showImages(_ images: [String] , atIndex: NSInteger , fromSenderArray: [UIView]) { 154 | var resources: [FTImageResource] = [] 155 | for imageURL in images { 156 | let resource: FTImageResource = FTImageResource(image: nil, imageURLString:imageURL) 157 | resources.append(resource) 158 | } 159 | self.showImages(resources, atIndex: atIndex, fromSenderArray: fromSenderArray) 160 | } 161 | 162 | 163 | fileprivate lazy var backgroundView: UIView = { 164 | let view = UIView(frame: UIScreen.main.bounds) 165 | return view 166 | }() 167 | 168 | fileprivate lazy var beginAnimationView: UIImageView = { 169 | let imageView = UIImageView(frame: CGRect.zero) 170 | imageView.clipsToBounds = true 171 | imageView.isUserInteractionEnabled = false 172 | imageView.contentMode = UIView.ContentMode.scaleAspectFit 173 | imageView.backgroundColor = UIColor.clear; 174 | return imageView 175 | }() 176 | 177 | fileprivate lazy var scrollView: UIScrollView = { 178 | let sView = UIScrollView(frame: UIScreen.main.bounds) 179 | sView.backgroundColor = UIColor.clear 180 | sView.isPagingEnabled = true 181 | sView.alpha = 0.0 182 | sView.bounces = true 183 | sView.showsHorizontalScrollIndicator = false 184 | sView.showsVerticalScrollIndicator = false 185 | sView.alwaysBounceHorizontal = true 186 | sView.delegate = self 187 | return sView 188 | }() 189 | 190 | fileprivate lazy var tabBar: FTImageViewBar = { 191 | let view = FTImageViewBar(frame: CGRect(x: 0 , y: FTImageViewerScreenHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) , 192 | saveTapBlock: { 193 | self.saveCurrentImage(); 194 | }, 195 | closeTapBlock: { 196 | self.animationOut() 197 | }) 198 | view.alpha = 0 199 | return view 200 | }() 201 | 202 | //MARK: - setupView 203 | 204 | fileprivate func setupView(shouldAnimate: Bool){ 205 | 206 | backgroundView.frame = UIScreen.main.bounds 207 | scrollView.frame = UIScreen.main.bounds 208 | tabBar.frame = CGRect(x: 0 , y: FTImageViewerScreenHeight , width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 209 | 210 | for v in scrollView.subviews{ 211 | v.removeFromSuperview() 212 | } 213 | for i in 0 ..< imageUrlArray.count { 214 | let imageView: FTImageView = FTImageView(frame: CGRect(x: FTImageViewerScreenWidth * CGFloat(i), y: 0, width: FTImageViewerScreenWidth, height: FTImageViewerScreenHeight), imageResource: imageUrlArray[i], atIndex: i) 215 | imageView.FTImageViewHandleTap = { 216 | self.animationOut() 217 | } 218 | imageView.panGesture.delegate = self; 219 | imageView.panGesture.addTarget(self, action: #selector(self.panGestureRecognized(_:))) 220 | scrollView.addSubview(imageView) 221 | } 222 | scrollView.contentSize = CGSize(width: UIScreen.main.bounds.width * CGFloat(imageUrlArray.count), height: UIScreen.main.bounds.height) 223 | scrollView.scrollRectToVisible(CGRect(x: FTImageViewerScreenWidth*CGFloat(currenIndex), y: 0, width: FTImageViewerScreenWidth, height: FTImageViewerScreenHeight), animated: false) 224 | tabBar.countLabel.text = "\(currenIndex+1)/\(imageUrlArray.count)" 225 | 226 | if shouldAnimate { 227 | self.show() 228 | }else{ 229 | self.scrollView.alpha = 1.0 230 | self.tabBar.alpha = 1 231 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight-FTImageViewBarHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 232 | self.tabBar.layoutIfNeeded() 233 | } 234 | } 235 | 236 | //MARK: - show 237 | 238 | func show() { 239 | self.addOrientationChangeNotification() 240 | UIView.animate(withDuration: FTImageViewerAnimationDuriation, animations: { () -> Void in 241 | self.scrollView.alpha = 1.0 242 | self.tabBar.alpha = 1 243 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight-FTImageViewBarHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 244 | }, completion: { (finished: Bool) -> Void in 245 | self.beginAnimationView.isHidden = true 246 | }) 247 | } 248 | 249 | 250 | //MARK: - gestureRecognizerShouldBegin 251 | 252 | public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 253 | if (gestureRecognizer.view!.isKind(of: FTImageView.self)){ 254 | let translatedPoint = (gestureRecognizer as! UIPanGestureRecognizer).translation(in: gestureRecognizer.view) 255 | return abs(translatedPoint.y) > abs(translatedPoint.x); 256 | } 257 | return true 258 | } 259 | 260 | //MARK: - panGestureRecognized 261 | 262 | @objc func panGestureRecognized(_ gesture: UIPanGestureRecognizer){ 263 | let currentItem: UIView = gesture.view! 264 | let translatedPoint = gesture.translation(in: currentItem) 265 | let newAlpha = CGFloat(1 - fabsf(Float(translatedPoint.y/FTImageViewerScreenHeight))) 266 | 267 | if (gesture.state == UIGestureRecognizer.State.began || gesture.state == UIGestureRecognizer.State.changed){ 268 | scrollView.isScrollEnabled = false 269 | currentItem.frame = CGRect(x: currentItem.frame.origin.x, y: translatedPoint.y, width: currentItem.frame.size.width, height: currentItem.frame.size.height) 270 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight-FTImageViewBarHeight*newAlpha, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 271 | backgroundView.backgroundColor = FTImageViewerBackgroundColor.withAlphaComponent(newAlpha) 272 | }else if (gesture.state == UIGestureRecognizer.State.ended ){ 273 | scrollView.isScrollEnabled = true 274 | if (abs(translatedPoint.y) >= FTImageViewerScreenHeight*0.2){ 275 | UIView.animate(withDuration: FTImageViewerAnimationDuriation, animations: { () -> Void in 276 | self.backgroundView.backgroundColor = UIColor.clear 277 | if (translatedPoint.y > 0){ 278 | currentItem.frame = CGRect(x: currentItem.frame.origin.x, y: FTImageViewerScreenHeight, width: currentItem.frame.size.width, height: currentItem.frame.size.height) 279 | }else{ 280 | currentItem.frame = CGRect(x: currentItem.frame.origin.x, y: -FTImageViewerScreenHeight, width: currentItem.frame.size.width, height: currentItem.frame.size.height) 281 | } 282 | 283 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 284 | }, completion: { (finished: Bool) -> Void in 285 | if (finished == true){ 286 | self.removeOrientationChangeNotification() 287 | self.scrollView.removeFromSuperview() 288 | self.tabBar.removeFromSuperview() 289 | self.backgroundView.removeFromSuperview() 290 | } 291 | }) 292 | }else{ 293 | UIView.animate(withDuration: FTImageViewerAnimationDuriation, animations: { () -> Void in 294 | self.backgroundView.backgroundColor = FTImageViewerBackgroundColor 295 | currentItem.frame = CGRect(x: currentItem.frame.origin.x, y: 0, width: currentItem.frame.size.width, height: currentItem.frame.size.height) 296 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight-FTImageViewBarHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 297 | }, completion: { (finished: Bool) -> Void in 298 | 299 | }) 300 | } 301 | } 302 | } 303 | 304 | 305 | //MARK: - UIScrollViewDelegate 306 | 307 | public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){ 308 | currenIndex = NSInteger(scrollView.contentOffset.x / FTImageViewerScreenWidth) 309 | tabBar.countLabel.text = "\(currenIndex+1)/\(imageUrlArray.count)" 310 | } 311 | 312 | //MARK: - animationOut 313 | 314 | fileprivate func animationOut(){ 315 | self.removeOrientationChangeNotification() 316 | let page = NSInteger(scrollView.contentOffset.x / FTImageViewerScreenWidth) 317 | for img in scrollView.subviews{ 318 | if (img is FTImageView) && ((img as! FTImageView).tag == page) { 319 | if ((img as! FTImageView).imageView.image != nil) { 320 | self.beginAnimationView.image = (img as! FTImageView).imageView.image 321 | break 322 | } 323 | } 324 | } 325 | self.beginAnimationView.isHidden = false 326 | let rect = self.fromSenderRectArray[page] 327 | var imageRect = rect 328 | if let image = self.beginAnimationView.image { 329 | imageRect = self.imageFrame(image: image, fromRect: rect) 330 | } 331 | UIView.animate(withDuration: FTImageViewerAnimationDuriation, animations: { () -> Void in 332 | self.beginAnimationView.frame = imageRect 333 | self.scrollView.alpha = 0 334 | self.backgroundView.backgroundColor = UIColor.clear; 335 | self.tabBar.frame = CGRect(x: 0, y: FTImageViewerScreenHeight, width: FTImageViewerScreenWidth, height: FTImageViewBarHeight) 336 | }, completion: { (finished: Bool) -> Void in 337 | if (finished == true){ 338 | self.beginAnimationView.isHidden = true 339 | self.scrollView.removeFromSuperview() 340 | self.tabBar.removeFromSuperview() 341 | self.backgroundView.removeFromSuperview() 342 | } 343 | }) 344 | } 345 | 346 | //MARK: - saveCurrentImage 347 | 348 | fileprivate func saveCurrentImage() { 349 | var imageToSave: UIImage? = nil; 350 | for img in scrollView.subviews{ 351 | if (img is FTImageView) && ((img as! FTImageView).tag == currenIndex) { 352 | if ((img as! FTImageView).imageView.image != nil) { 353 | imageToSave = (img as! FTImageView).imageView.image! 354 | } 355 | } 356 | } 357 | if imageToSave != nil { 358 | UIImageWriteToSavedPhotosAlbum(imageToSave!, self, #selector(self.saveImageDone(_:error:context:)), nil) 359 | } 360 | } 361 | 362 | //MARK: - saveImageDone 363 | 364 | @objc func saveImageDone(_ image: UIImage, error: Error, context: UnsafeMutableRawPointer?) { 365 | self.tabBar.countLabel.text = NSLocalizedString("Save image done.", comment: "Save image done.") 366 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(1.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { 367 | self.tabBar.countLabel.text = "\(self.currenIndex+1)/\(self.imageUrlArray.count)" 368 | }) 369 | } 370 | 371 | } 372 | 373 | //MARK: - FTImageViewer extension - 374 | 375 | extension FTImageViewer { 376 | 377 | fileprivate func addOrientationChangeNotification() { 378 | NotificationCenter.default.addObserver(self,selector: #selector(onChangeStatusBarOrientationNotification(notification:)), 379 | name: UIDevice.orientationDidChangeNotification, 380 | object: nil) 381 | } 382 | 383 | fileprivate func removeOrientationChangeNotification() { 384 | NotificationCenter.default.removeObserver(self) 385 | } 386 | 387 | @objc fileprivate func onChangeStatusBarOrientationNotification(notification: Notification) { 388 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 389 | self.setupView(shouldAnimate: false) 390 | } 391 | } 392 | 393 | } 394 | 395 | //MARK: - FTImageView - 396 | 397 | public class FTImageView: UIScrollView, UIScrollViewDelegate{ 398 | 399 | var imageView: UIImageView! 400 | var activityIndicator: UIActivityIndicatorView! 401 | var FTImageViewHandleTap: (() -> ())? 402 | var singleTap: UITapGestureRecognizer! 403 | var doubleTap: UITapGestureRecognizer! 404 | var panGesture: UIPanGestureRecognizer! 405 | 406 | public init(frame: CGRect, imageResource: FTImageResource, atIndex: NSInteger){ 407 | super.init(frame: frame) 408 | 409 | self.backgroundColor = UIColor.clear 410 | self.showsHorizontalScrollIndicator = false 411 | self.showsVerticalScrollIndicator = false 412 | self.decelerationRate = UIScrollView.DecelerationRate.fast 413 | self.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight] 414 | self.minimumZoomScale = 1.0 415 | self.maximumZoomScale = 3.0 416 | self.delegate = self 417 | self.tag = atIndex 418 | 419 | activityIndicator = UIActivityIndicatorView(frame: CGRect(x: (frame.width - FTImageViewBarHeight)/2, y: (frame.height - FTImageViewBarHeight)/2, width: FTImageViewBarHeight, height: FTImageViewBarHeight)) 420 | activityIndicator.style = .medium 421 | activityIndicator.hidesWhenStopped = true 422 | self.addSubview(activityIndicator) 423 | 424 | activityIndicator.startAnimating() 425 | 426 | imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)) 427 | imageView.contentMode = UIView.ContentMode.scaleAspectFit 428 | 429 | if let img: UIImage = imageResource.image { 430 | imageView.image = img 431 | }else if let imageURL: String = imageResource.imageURLString { 432 | imageView.kf.setImage(with: URL(string: imageURL)!, placeholder: nil, options: nil, progressBlock: nil) { result in 433 | if (try? result.get().image) != nil { 434 | self.activityIndicator.stopAnimating() 435 | } else { 436 | return 437 | } 438 | } 439 | } 440 | self.addSubview(imageView) 441 | self.setupGestures() 442 | } 443 | 444 | required public init?(coder aDecoder: NSCoder) { 445 | fatalError("init(coder:) has not been implemented") 446 | } 447 | 448 | fileprivate func setupGestures() { 449 | //gesture 450 | singleTap = UITapGestureRecognizer(target: self, action: #selector(self.handleSingleTap(_:))) 451 | singleTap.numberOfTapsRequired = 1 452 | singleTap.delaysTouchesBegan = true 453 | self.addGestureRecognizer(singleTap) 454 | 455 | doubleTap = UITapGestureRecognizer(target: self, action: #selector(self.handleDoubleTap(_:))) 456 | doubleTap.numberOfTapsRequired = 2 457 | doubleTap.delaysTouchesBegan = true 458 | self.addGestureRecognizer(doubleTap) 459 | 460 | singleTap.require(toFail: doubleTap) 461 | 462 | panGesture = UIPanGestureRecognizer() 463 | panGesture.maximumNumberOfTouches = 1 464 | panGesture.minimumNumberOfTouches = 1 465 | self.addGestureRecognizer(panGesture) 466 | } 467 | 468 | //MARK: - UIScrollViewDelegate 469 | 470 | public func viewForZooming(in scrollView: UIScrollView) -> UIView?{ 471 | return imageView 472 | } 473 | 474 | public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat){ 475 | let ws = scrollView.frame.size.width - scrollView.contentInset.left - scrollView.contentInset.right 476 | let hs = scrollView.frame.size.height - scrollView.contentInset.top - scrollView.contentInset.bottom 477 | let w = imageView.frame.size.width 478 | let h = imageView.frame.size.height 479 | var rct = imageView.frame 480 | rct.origin.x = (ws > w) ? (ws-w)/2: 0 481 | rct.origin.y = (hs > h) ? (hs-h)/2: 0 482 | imageView.frame = rct; 483 | } 484 | 485 | //MARK: - handleSingleTap - 486 | 487 | @objc func handleSingleTap(_ sender: UITapGestureRecognizer){ 488 | self.FTImageViewHandleTap?() 489 | } 490 | 491 | //MARK: - handleDoubleTap - 492 | 493 | @objc func handleDoubleTap(_ sender: UITapGestureRecognizer){ 494 | let touchPoint = sender.location(in: self) 495 | if (self.zoomScale == self.maximumZoomScale){ 496 | self.setZoomScale(self.minimumZoomScale, animated: true) 497 | }else{ 498 | self.zoom(to: CGRect(x: touchPoint.x, y: touchPoint.y, width: 1, height: 1), animated: true) 499 | } 500 | } 501 | 502 | } 503 | 504 | //MARK: - FTImageViewBar - 505 | 506 | public class FTImageViewBar: UIView { 507 | 508 | var saveButtonTapBlock: (() ->())! 509 | var closeButtonTapBlock: (() ->())! 510 | 511 | fileprivate lazy var closeButton: UIButton = { 512 | let button = UIButton(frame: CGRect(x: FTImageViewBarDefaultMargin, y: (self.frame.height-FTImageViewBarButtonWidth)/2, width: FTImageViewBarButtonWidth, height: FTImageViewBarButtonWidth)) 513 | button.backgroundColor = UIColor.clear 514 | button.contentMode = UIView.ContentMode.scaleAspectFill 515 | button.addTarget(self, action: #selector(FTImageViewBar.onCloseButtonTapped), for: UIControl.Event.touchUpInside) 516 | return button 517 | }() 518 | 519 | 520 | fileprivate lazy var saveButton: UIButton = { 521 | let button = UIButton(frame: CGRect(x: self.frame.width-FTImageViewBarButtonWidth-FTImageViewBarDefaultMargin, y: (self.frame.height-FTImageViewBarButtonWidth)/2, width: FTImageViewBarButtonWidth, height: FTImageViewBarButtonWidth)) 522 | button.backgroundColor = UIColor.clear 523 | button.contentMode = UIView.ContentMode.scaleAspectFill 524 | button.addTarget(self, action: #selector(FTImageViewBar.onSaveButtonTapped), for: UIControl.Event.touchUpInside) 525 | return button 526 | }() 527 | 528 | fileprivate lazy var countLabel: UILabel = { 529 | let label = UILabel(frame: CGRect(x: FTImageViewBarButtonWidth+FTImageViewBarDefaultMargin*2, y: 0, width: self.frame.width-(FTImageViewBarButtonWidth+FTImageViewBarDefaultMargin*2)*2, height: self.frame.height)) 530 | label.backgroundColor = UIColor.clear 531 | label.textColor = UIColor.white 532 | label.font = UIFont.systemFont(ofSize: 13) 533 | label.textAlignment = NSTextAlignment.center 534 | label.text = "-/-" 535 | return label 536 | }() 537 | 538 | //MARK: - convenience init 539 | 540 | public convenience init(frame: CGRect, saveTapBlock: @escaping ()->(), closeTapBlock: @escaping ()->()) { 541 | self.init(frame: frame) 542 | self.backgroundColor = FTImageViewBarBackgroundColor 543 | saveButtonTapBlock = saveTapBlock 544 | closeButtonTapBlock = closeTapBlock 545 | var imageBundle: Bundle = Bundle.main 546 | if let bundleURL: String = Bundle(for: FTImageViewer.classForCoder()).path(forResource: "FTResource", ofType: "bundle") { 547 | if let bundle: Bundle = Bundle(path: bundleURL){ 548 | imageBundle = bundle; 549 | } 550 | } 551 | closeButton.setImage(UIImage(named: "close", in: imageBundle, compatibleWith: nil), for: UIControl.State()) 552 | self.addSubview(closeButton) 553 | saveButton.setImage(UIImage(named: "save", in: imageBundle, compatibleWith: nil), for: UIControl.State()) 554 | self.addSubview(saveButton) 555 | self.addSubview(countLabel) 556 | } 557 | 558 | public override func layoutIfNeeded() { 559 | super.layoutIfNeeded() 560 | self.closeButton.frame = CGRect(x: FTImageViewBarDefaultMargin, y: (self.frame.height-FTImageViewBarButtonWidth)/2, width: FTImageViewBarButtonWidth, height: FTImageViewBarButtonWidth) 561 | self.saveButton.frame = CGRect(x: self.frame.width-FTImageViewBarButtonWidth-FTImageViewBarDefaultMargin, y: (self.frame.height-FTImageViewBarButtonWidth)/2, width: FTImageViewBarButtonWidth, height: FTImageViewBarButtonWidth) 562 | self.countLabel.frame = CGRect(x: FTImageViewBarButtonWidth+FTImageViewBarDefaultMargin*2, y: 0, width: self.frame.width-(FTImageViewBarButtonWidth+FTImageViewBarDefaultMargin*2)*2, height: self.frame.height) 563 | } 564 | 565 | //MARK: - onCloseButtonTapped 566 | 567 | @objc func onCloseButtonTapped(){ 568 | self.closeButtonTapBlock(); 569 | } 570 | 571 | //MARK: - onSaveButtonTapped 572 | 573 | @objc func onSaveButtonTapped(){ 574 | self.saveButtonTapBlock(); 575 | } 576 | } 577 | 578 | 579 | //MARK: - FTImageGridView - 580 | 581 | public class FTImageGridView: UIView { 582 | 583 | var FTImageGridViewTapBlock: ((_ buttonArray: [UIButton], _ buttonIndex: NSInteger) ->())? 584 | var buttonArray: [UIButton] = [] 585 | 586 | //MARK: - internal init frame imageArray tapBlock 587 | 588 | public convenience init(frame: CGRect, imageArray: [String], tapBlock: @escaping ((_ buttonsArray: [UIButton], _ buttonIndex: NSInteger) ->())){ 589 | self.init(frame: frame) 590 | self.showWithImageArray(imageArray, tapBlock: tapBlock) 591 | } 592 | 593 | public func showWithImageArray(_ imageArray: [String], tapBlock: @escaping ((_ buttonsArray: [UIButton], _ buttonIndex: NSInteger) ->())) { 594 | buttonArray = [] 595 | for views in self.subviews { 596 | if views.isKind(of: UIButton.classForCoder()){ 597 | views.removeFromSuperview(); 598 | } 599 | } 600 | if imageArray.count > 0 { 601 | FTImageGridViewTapBlock = tapBlock 602 | let imgHeight: CGFloat = (frame.size.width - FTImageGridViewImageMargin * 2) / 3 603 | for i in 0 ... imageArray.count-1 { 604 | let x = CGFloat(i % 3) * (imgHeight + FTImageGridViewImageMargin) 605 | let y = CGFloat(i / 3) * (imgHeight + FTImageGridViewImageMargin) 606 | let imageButton = UIButton() 607 | imageButton.frame = CGRect(x: x, y: y, width: imgHeight, height: imgHeight) 608 | imageButton.backgroundColor = KCOLOR_BACKGROUND_WHITE 609 | imageButton.imageView?.contentMode = UIView.ContentMode.scaleAspectFill 610 | imageButton.kf.setImage(with: URL(string: imageArray[i])!, for: UIControl.State.normal) 611 | 612 | imageButton.tag = i 613 | imageButton.clipsToBounds = true 614 | imageButton.addTarget(self, action: #selector(FTImageGridView.onClickImage(_:)), for: UIControl.Event.touchUpInside) 615 | self.addSubview(imageButton) 616 | self.buttonArray.append(imageButton) 617 | } 618 | } 619 | } 620 | 621 | //MARK: - get Height With Width 622 | 623 | public class func getHeightWithWidth(_ width: CGFloat, imgCount: Int) -> CGFloat{ 624 | let imgHeight: CGFloat = (width - FTImageGridViewImageMargin * 2) / 3 625 | let photoAlbumHeight: CGFloat = imgHeight * CGFloat(ceilf(Float(imgCount) / 3)) + FTImageGridViewImageMargin * CGFloat(ceilf(Float(imgCount) / 3)-1) 626 | return photoAlbumHeight 627 | } 628 | 629 | //MARK: - onClickImage 630 | 631 | @objc func onClickImage(_ sender: UIButton){ 632 | FTImageGridViewTapBlock?(self.buttonArray , sender.tag) 633 | } 634 | 635 | } 636 | -------------------------------------------------------------------------------- /FTImageViewer/FTResource.bundle/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufengting/FTImageViewer/da1fca644b46d5f250d357df1df26694aaf7b639/FTImageViewer/FTResource.bundle/close.png -------------------------------------------------------------------------------- /FTImageViewer/FTResource.bundle/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liufengting/FTImageViewer/da1fca644b46d5f250d357df1df26694aaf7b639/FTImageViewer/FTResource.bundle/save.png -------------------------------------------------------------------------------- /FTImageViewer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 26118B52EE6F66AD803B2CC0 /* Pods_FTImageViewerDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 90ADAC0193F30C6148074D96 /* Pods_FTImageViewerDemo.framework */; }; 11 | 2AD9B62627D5EB900053C920 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD9B62527D5EB900053C920 /* AppDelegate.swift */; }; 12 | 2AD9B62A27D5EB900053C920 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD9B62927D5EB900053C920 /* ViewController.swift */; }; 13 | 2AD9B62D27D5EB900053C920 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2AD9B62B27D5EB900053C920 /* Main.storyboard */; }; 14 | 2AD9B62F27D5EB910053C920 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AD9B62E27D5EB910053C920 /* Assets.xcassets */; }; 15 | 2AD9B63227D5EB910053C920 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2AD9B63027D5EB910053C920 /* LaunchScreen.storyboard */; }; 16 | 2AD9B63A27D5EC100053C920 /* DemoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD9B63927D5EC100053C920 /* DemoTableViewCell.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 2AD9B62227D5EB900053C920 /* FTImageViewerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FTImageViewerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 2AD9B62527D5EB900053C920 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 2AD9B62927D5EB900053C920 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | 2AD9B62C27D5EB900053C920 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | 2AD9B62E27D5EB910053C920 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 2AD9B63127D5EB910053C920 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 2AD9B63327D5EB910053C920 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | 2AD9B63927D5EC100053C920 /* DemoTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoTableViewCell.swift; sourceTree = ""; }; 28 | 2C0046483921B8500D42E103 /* Pods-FTImageViewerDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FTImageViewerDemo.release.xcconfig"; path = "Target Support Files/Pods-FTImageViewerDemo/Pods-FTImageViewerDemo.release.xcconfig"; sourceTree = ""; }; 29 | 90ADAC0193F30C6148074D96 /* Pods_FTImageViewerDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FTImageViewerDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | AB924496713680E91DE06E1F /* Pods-FTImageViewerDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FTImageViewerDemo.debug.xcconfig"; path = "Target Support Files/Pods-FTImageViewerDemo/Pods-FTImageViewerDemo.debug.xcconfig"; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 2AD9B61F27D5EB900053C920 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | 26118B52EE6F66AD803B2CC0 /* Pods_FTImageViewerDemo.framework in Frameworks */, 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 1E96FC51451E94FDDBF443A7 /* Pods */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | AB924496713680E91DE06E1F /* Pods-FTImageViewerDemo.debug.xcconfig */, 49 | 2C0046483921B8500D42E103 /* Pods-FTImageViewerDemo.release.xcconfig */, 50 | ); 51 | path = Pods; 52 | sourceTree = ""; 53 | }; 54 | 2AD9B61927D5EB900053C920 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 2AD9B62427D5EB900053C920 /* FTImageViewerDemo */, 58 | 2AD9B62327D5EB900053C920 /* Products */, 59 | 1E96FC51451E94FDDBF443A7 /* Pods */, 60 | 399D46EE86FB8863B98522AB /* Frameworks */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 2AD9B62327D5EB900053C920 /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 2AD9B62227D5EB900053C920 /* FTImageViewerDemo.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | 2AD9B62427D5EB900053C920 /* FTImageViewerDemo */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 2AD9B62527D5EB900053C920 /* AppDelegate.swift */, 76 | 2AD9B62927D5EB900053C920 /* ViewController.swift */, 77 | 2AD9B63927D5EC100053C920 /* DemoTableViewCell.swift */, 78 | 2AD9B62B27D5EB900053C920 /* Main.storyboard */, 79 | 2AD9B62E27D5EB910053C920 /* Assets.xcassets */, 80 | 2AD9B63027D5EB910053C920 /* LaunchScreen.storyboard */, 81 | 2AD9B63327D5EB910053C920 /* Info.plist */, 82 | ); 83 | path = FTImageViewerDemo; 84 | sourceTree = ""; 85 | }; 86 | 399D46EE86FB8863B98522AB /* Frameworks */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 90ADAC0193F30C6148074D96 /* Pods_FTImageViewerDemo.framework */, 90 | ); 91 | name = Frameworks; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | 2AD9B62127D5EB900053C920 /* FTImageViewerDemo */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = 2AD9B63627D5EB910053C920 /* Build configuration list for PBXNativeTarget "FTImageViewerDemo" */; 100 | buildPhases = ( 101 | A5445B8F6B795CF1BE53211B /* [CP] Check Pods Manifest.lock */, 102 | 2AD9B61E27D5EB900053C920 /* Sources */, 103 | 2AD9B61F27D5EB900053C920 /* Frameworks */, 104 | 2AD9B62027D5EB900053C920 /* Resources */, 105 | D8F2711281C7F6003483A061 /* [CP] Embed Pods Frameworks */, 106 | ); 107 | buildRules = ( 108 | ); 109 | dependencies = ( 110 | ); 111 | name = FTImageViewerDemo; 112 | productName = FTImageViewerDemo; 113 | productReference = 2AD9B62227D5EB900053C920 /* FTImageViewerDemo.app */; 114 | productType = "com.apple.product-type.application"; 115 | }; 116 | /* End PBXNativeTarget section */ 117 | 118 | /* Begin PBXProject section */ 119 | 2AD9B61A27D5EB900053C920 /* Project object */ = { 120 | isa = PBXProject; 121 | attributes = { 122 | BuildIndependentTargetsInParallel = 1; 123 | LastSwiftUpdateCheck = 1330; 124 | LastUpgradeCheck = 1330; 125 | TargetAttributes = { 126 | 2AD9B62127D5EB900053C920 = { 127 | CreatedOnToolsVersion = 13.3; 128 | }; 129 | }; 130 | }; 131 | buildConfigurationList = 2AD9B61D27D5EB900053C920 /* Build configuration list for PBXProject "FTImageViewerDemo" */; 132 | compatibilityVersion = "Xcode 13.0"; 133 | developmentRegion = en; 134 | hasScannedForEncodings = 0; 135 | knownRegions = ( 136 | en, 137 | Base, 138 | ); 139 | mainGroup = 2AD9B61927D5EB900053C920; 140 | productRefGroup = 2AD9B62327D5EB900053C920 /* Products */; 141 | projectDirPath = ""; 142 | projectRoot = ""; 143 | targets = ( 144 | 2AD9B62127D5EB900053C920 /* FTImageViewerDemo */, 145 | ); 146 | }; 147 | /* End PBXProject section */ 148 | 149 | /* Begin PBXResourcesBuildPhase section */ 150 | 2AD9B62027D5EB900053C920 /* Resources */ = { 151 | isa = PBXResourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | 2AD9B63227D5EB910053C920 /* LaunchScreen.storyboard in Resources */, 155 | 2AD9B62F27D5EB910053C920 /* Assets.xcassets in Resources */, 156 | 2AD9B62D27D5EB900053C920 /* Main.storyboard in Resources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXResourcesBuildPhase section */ 161 | 162 | /* Begin PBXShellScriptBuildPhase section */ 163 | A5445B8F6B795CF1BE53211B /* [CP] Check Pods Manifest.lock */ = { 164 | isa = PBXShellScriptBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | ); 168 | inputFileListPaths = ( 169 | ); 170 | inputPaths = ( 171 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 172 | "${PODS_ROOT}/Manifest.lock", 173 | ); 174 | name = "[CP] Check Pods Manifest.lock"; 175 | outputFileListPaths = ( 176 | ); 177 | outputPaths = ( 178 | "$(DERIVED_FILE_DIR)/Pods-FTImageViewerDemo-checkManifestLockResult.txt", 179 | ); 180 | runOnlyForDeploymentPostprocessing = 0; 181 | shellPath = /bin/sh; 182 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 183 | showEnvVarsInLog = 0; 184 | }; 185 | D8F2711281C7F6003483A061 /* [CP] Embed Pods Frameworks */ = { 186 | isa = PBXShellScriptBuildPhase; 187 | buildActionMask = 2147483647; 188 | files = ( 189 | ); 190 | inputFileListPaths = ( 191 | "${PODS_ROOT}/Target Support Files/Pods-FTImageViewerDemo/Pods-FTImageViewerDemo-frameworks-${CONFIGURATION}-input-files.xcfilelist", 192 | ); 193 | name = "[CP] Embed Pods Frameworks"; 194 | outputFileListPaths = ( 195 | "${PODS_ROOT}/Target Support Files/Pods-FTImageViewerDemo/Pods-FTImageViewerDemo-frameworks-${CONFIGURATION}-output-files.xcfilelist", 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | shellPath = /bin/sh; 199 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FTImageViewerDemo/Pods-FTImageViewerDemo-frameworks.sh\"\n"; 200 | showEnvVarsInLog = 0; 201 | }; 202 | /* End PBXShellScriptBuildPhase section */ 203 | 204 | /* Begin PBXSourcesBuildPhase section */ 205 | 2AD9B61E27D5EB900053C920 /* Sources */ = { 206 | isa = PBXSourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | 2AD9B63A27D5EC100053C920 /* DemoTableViewCell.swift in Sources */, 210 | 2AD9B62A27D5EB900053C920 /* ViewController.swift in Sources */, 211 | 2AD9B62627D5EB900053C920 /* AppDelegate.swift in Sources */, 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXSourcesBuildPhase section */ 216 | 217 | /* Begin PBXVariantGroup section */ 218 | 2AD9B62B27D5EB900053C920 /* Main.storyboard */ = { 219 | isa = PBXVariantGroup; 220 | children = ( 221 | 2AD9B62C27D5EB900053C920 /* Base */, 222 | ); 223 | name = Main.storyboard; 224 | sourceTree = ""; 225 | }; 226 | 2AD9B63027D5EB910053C920 /* LaunchScreen.storyboard */ = { 227 | isa = PBXVariantGroup; 228 | children = ( 229 | 2AD9B63127D5EB910053C920 /* Base */, 230 | ); 231 | name = LaunchScreen.storyboard; 232 | sourceTree = ""; 233 | }; 234 | /* End PBXVariantGroup section */ 235 | 236 | /* Begin XCBuildConfiguration section */ 237 | 2AD9B63427D5EB910053C920 /* Debug */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 244 | CLANG_ENABLE_MODULES = YES; 245 | CLANG_ENABLE_OBJC_ARC = YES; 246 | CLANG_ENABLE_OBJC_WEAK = YES; 247 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_COMMA = YES; 250 | CLANG_WARN_CONSTANT_CONVERSION = YES; 251 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 254 | CLANG_WARN_EMPTY_BODY = YES; 255 | CLANG_WARN_ENUM_CONVERSION = YES; 256 | CLANG_WARN_INFINITE_RECURSION = YES; 257 | CLANG_WARN_INT_CONVERSION = YES; 258 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 259 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 260 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 261 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 262 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 264 | CLANG_WARN_STRICT_PROTOTYPES = YES; 265 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = dwarf; 271 | ENABLE_STRICT_OBJC_MSGSEND = YES; 272 | ENABLE_TESTABILITY = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_DYNAMIC_NO_PIC = NO; 275 | GCC_NO_COMMON_BLOCKS = YES; 276 | GCC_OPTIMIZATION_LEVEL = 0; 277 | GCC_PREPROCESSOR_DEFINITIONS = ( 278 | "DEBUG=1", 279 | "$(inherited)", 280 | ); 281 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 282 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 283 | GCC_WARN_UNDECLARED_SELECTOR = YES; 284 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 285 | GCC_WARN_UNUSED_FUNCTION = YES; 286 | GCC_WARN_UNUSED_VARIABLE = YES; 287 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 288 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 289 | MTL_FAST_MATH = YES; 290 | ONLY_ACTIVE_ARCH = YES; 291 | SDKROOT = iphoneos; 292 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 293 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 294 | }; 295 | name = Debug; 296 | }; 297 | 2AD9B63527D5EB910053C920 /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ALWAYS_SEARCH_USER_PATHS = NO; 301 | CLANG_ANALYZER_NONNULL = YES; 302 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 303 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 304 | CLANG_ENABLE_MODULES = YES; 305 | CLANG_ENABLE_OBJC_ARC = YES; 306 | CLANG_ENABLE_OBJC_WEAK = YES; 307 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 308 | CLANG_WARN_BOOL_CONVERSION = YES; 309 | CLANG_WARN_COMMA = YES; 310 | CLANG_WARN_CONSTANT_CONVERSION = YES; 311 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 312 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 313 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 314 | CLANG_WARN_EMPTY_BODY = YES; 315 | CLANG_WARN_ENUM_CONVERSION = YES; 316 | CLANG_WARN_INFINITE_RECURSION = YES; 317 | CLANG_WARN_INT_CONVERSION = YES; 318 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 319 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 320 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 322 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 323 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 324 | CLANG_WARN_STRICT_PROTOTYPES = YES; 325 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 326 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 327 | CLANG_WARN_UNREACHABLE_CODE = YES; 328 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 329 | COPY_PHASE_STRIP = NO; 330 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 331 | ENABLE_NS_ASSERTIONS = NO; 332 | ENABLE_STRICT_OBJC_MSGSEND = YES; 333 | GCC_C_LANGUAGE_STANDARD = gnu11; 334 | GCC_NO_COMMON_BLOCKS = YES; 335 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 336 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 337 | GCC_WARN_UNDECLARED_SELECTOR = YES; 338 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 339 | GCC_WARN_UNUSED_FUNCTION = YES; 340 | GCC_WARN_UNUSED_VARIABLE = YES; 341 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 342 | MTL_ENABLE_DEBUG_INFO = NO; 343 | MTL_FAST_MATH = YES; 344 | SDKROOT = iphoneos; 345 | SWIFT_COMPILATION_MODE = wholemodule; 346 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 347 | VALIDATE_PRODUCT = YES; 348 | }; 349 | name = Release; 350 | }; 351 | 2AD9B63727D5EB910053C920 /* Debug */ = { 352 | isa = XCBuildConfiguration; 353 | baseConfigurationReference = AB924496713680E91DE06E1F /* Pods-FTImageViewerDemo.debug.xcconfig */; 354 | buildSettings = { 355 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 356 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 357 | CODE_SIGN_STYLE = Automatic; 358 | CURRENT_PROJECT_VERSION = 1; 359 | DEVELOPMENT_TEAM = E83AC9WR2F; 360 | GENERATE_INFOPLIST_FILE = YES; 361 | INFOPLIST_FILE = FTImageViewerDemo/Info.plist; 362 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 363 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 364 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 365 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 366 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 367 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 368 | LD_RUNPATH_SEARCH_PATHS = ( 369 | "$(inherited)", 370 | "@executable_path/Frameworks", 371 | ); 372 | MARKETING_VERSION = 1.0; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.liufengting.FTImageViewerDemo; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_EMIT_LOC_STRINGS = YES; 376 | SWIFT_VERSION = 5.0; 377 | TARGETED_DEVICE_FAMILY = "1,2"; 378 | }; 379 | name = Debug; 380 | }; 381 | 2AD9B63827D5EB910053C920 /* Release */ = { 382 | isa = XCBuildConfiguration; 383 | baseConfigurationReference = 2C0046483921B8500D42E103 /* Pods-FTImageViewerDemo.release.xcconfig */; 384 | buildSettings = { 385 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 386 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 387 | CODE_SIGN_STYLE = Automatic; 388 | CURRENT_PROJECT_VERSION = 1; 389 | DEVELOPMENT_TEAM = E83AC9WR2F; 390 | GENERATE_INFOPLIST_FILE = YES; 391 | INFOPLIST_FILE = FTImageViewerDemo/Info.plist; 392 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 393 | INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; 394 | INFOPLIST_KEY_UIMainStoryboardFile = Main; 395 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 396 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 397 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 398 | LD_RUNPATH_SEARCH_PATHS = ( 399 | "$(inherited)", 400 | "@executable_path/Frameworks", 401 | ); 402 | MARKETING_VERSION = 1.0; 403 | PRODUCT_BUNDLE_IDENTIFIER = com.liufengting.FTImageViewerDemo; 404 | PRODUCT_NAME = "$(TARGET_NAME)"; 405 | SWIFT_EMIT_LOC_STRINGS = YES; 406 | SWIFT_VERSION = 5.0; 407 | TARGETED_DEVICE_FAMILY = "1,2"; 408 | }; 409 | name = Release; 410 | }; 411 | /* End XCBuildConfiguration section */ 412 | 413 | /* Begin XCConfigurationList section */ 414 | 2AD9B61D27D5EB900053C920 /* Build configuration list for PBXProject "FTImageViewerDemo" */ = { 415 | isa = XCConfigurationList; 416 | buildConfigurations = ( 417 | 2AD9B63427D5EB910053C920 /* Debug */, 418 | 2AD9B63527D5EB910053C920 /* Release */, 419 | ); 420 | defaultConfigurationIsVisible = 0; 421 | defaultConfigurationName = Release; 422 | }; 423 | 2AD9B63627D5EB910053C920 /* Build configuration list for PBXNativeTarget "FTImageViewerDemo" */ = { 424 | isa = XCConfigurationList; 425 | buildConfigurations = ( 426 | 2AD9B63727D5EB910053C920 /* Debug */, 427 | 2AD9B63827D5EB910053C920 /* Release */, 428 | ); 429 | defaultConfigurationIsVisible = 0; 430 | defaultConfigurationName = Release; 431 | }; 432 | /* End XCConfigurationList section */ 433 | }; 434 | rootObject = 2AD9B61A27D5EB900053C920 /* Project object */; 435 | } 436 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // FTImageViewerDemo 4 | // 5 | // Created by LiuFengting on 2022/3/7. 6 | // Copyright © 2022年 . All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @main 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/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 | 49 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/DemoTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DemoTableViewCell.swift 3 | // FTImageViewerDemo 4 | // 5 | // Created by LiuFengting on 2022/3/7. 6 | // Copyright © 2022年 . All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import FTImageViewer 11 | 12 | class DemoTableViewCell: UITableViewCell { 13 | 14 | @IBOutlet weak var iconImageView: UIImageView! 15 | @IBOutlet weak var nameLabel: UILabel! 16 | @IBOutlet weak var contentLabel: UILabel! 17 | @IBOutlet weak var imageGridView: FTImageGridView! 18 | @IBOutlet weak var imageGridHeight: NSLayoutConstraint! // the height constrain for grid in stroyboard 19 | 20 | 21 | func setupWith(name: String, content: String, imageArray: [String]) { 22 | if imageArray.count > 0 { 23 | if let url = URL(string: imageArray[0]) { 24 | self.iconImageView.kf.setImage(with: url) 25 | } 26 | } 27 | 28 | nameLabel.text = name 29 | contentLabel.text = content 30 | 31 | let gridWidth = UIScreen.main.bounds.size.width - 56 - 8 32 | 33 | // get height for the image grid 34 | imageGridHeight.constant = FTImageGridView.getHeightWithWidth(gridWidth, imgCount: imageArray.count) 35 | 36 | // show images in grid 37 | imageGridView.showWithImageArray(imageArray) { (buttonsArray, buttonIndex) in 38 | // preview images with one line of code 39 | FTImageViewer.showImages(imageArray, atIndex: buttonIndex, fromSenderArray: buttonsArray) 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | NSAllowsArbitraryLoads 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FTImageViewerDemo/FTImageViewerDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // FTImageViewerDemo 4 | // 5 | // Created by LiuFengting on 2022/3/7. 6 | // Copyright © 2022年 . All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 12 | 13 | @IBOutlet weak var tableView: UITableView! 14 | 15 | var data : [[String]] = [["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 16 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 17 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 18 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg", 19 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff6csucjj20gt0aijrh.jpg", 20 | "http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 21 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 22 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 23 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg"], 24 | ["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 25 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 26 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 27 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg"], 28 | ["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 29 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 30 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg"], 31 | ["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 32 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 33 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 34 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg", 35 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff6csucjj20gt0aijrh.jpg", 36 | "http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 37 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg"], 38 | ["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 39 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 40 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 41 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg", 42 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff6csucjj20gt0aijrh.jpg", 43 | "http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 44 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 45 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg"], 46 | ["http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 47 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 48 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 49 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg", 50 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff6csucjj20gt0aijrh.jpg", 51 | "http://ww4.sinaimg.cn/mw600/7352978fgw1f6gkap8p45j20f00f074t.jpg", 52 | "http://ww3.sinaimg.cn/mw600/c0679ecagw1f6ff68fzb1j20gt0gtwhf.jpg", 53 | "http://ww4.sinaimg.cn/mw600/c0679ecagw1f6ff69na87j20gt08a3z2.jpg", 54 | "http://ww1.sinaimg.cn/mw600/c0679ecagw1f6ff6ar7v7j20gt0me3yy.jpg"]] 55 | 56 | override func viewDidLoad() { 57 | super.viewDidLoad() 58 | 59 | tableView.delegate = self 60 | tableView.dataSource = self 61 | tableView.estimatedRowHeight = tableView.rowHeight 62 | tableView.rowHeight = UITableView.automaticDimension 63 | } 64 | 65 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 66 | return data.count 67 | } 68 | 69 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 70 | let cell : DemoTableViewCell = tableView.dequeueReusableCell(withIdentifier: "DemoTableViewCellIdentifier", for: indexPath) as! DemoTableViewCell 71 | cell.setupWith(name: "Person \(indexPath.row)", 72 | content: "Person \(indexPath.row) said this is a great demo, if you like it, please give me a 'star' or fork the project. I will continue making some more Liberary for you.", 73 | imageArray: data[indexPath.row]) 74 | return cell; 75 | } 76 | 77 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 78 | tableView.deselectRow(at: indexPath, animated: true) 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /FTImageViewerDemo/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | platform :ios, '13.0' 3 | 4 | target 'FTImageViewerDemo' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for FTImageViewerDemo 9 | pod 'FTImageViewer', :path => '../' 10 | 11 | end 12 | -------------------------------------------------------------------------------- /FTImageViewerDemo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FTImageViewer (2.0.7): 3 | - Kingfisher 4 | - Kingfisher (7.2.0) 5 | 6 | DEPENDENCIES: 7 | - FTImageViewer (from `../`) 8 | 9 | SPEC REPOS: 10 | trunk: 11 | - Kingfisher 12 | 13 | EXTERNAL SOURCES: 14 | FTImageViewer: 15 | :path: "../" 16 | 17 | SPEC CHECKSUMS: 18 | FTImageViewer: 8e6c8ad3376a4e8a37e059be43b9906e285796fd 19 | Kingfisher: 3ac0b75b155cabc0e544877d1a4deea29feece92 20 | 21 | PODFILE CHECKSUM: fe035bd790420427ae55547fae7af90567bd6cbc 22 | 23 | COCOAPODS: 1.11.2 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 刘锋婷 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![FTImageViewer](https://raw.githubusercontent.com/liufengting/FTResourceRepo/master/Resource/FTImageViewer/FTImageViewer.jpg) 2 | 3 | # FTImageViewer 4 | 5 | [![Twitter](https://img.shields.io/badge/twitter-@liufengting-blue.svg?style=flat)](http://twitter.com/liufengting) 6 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/liufengting/FTImageViewer/master/LICENSE) 7 | [![Pods Versions](https://img.shields.io/cocoapods/v/FTImageViewer.svg?style=flat)](http://cocoapods.org/pods/FTImageViewer) 8 | [![CI Status](http://img.shields.io/travis/liufengting/FTImageViewer.svg?style=flat)](https://travis-ci.org/liufengting/FTImageViewer) 9 | [![Swift Version Compatibility](https://img.shields.io/badge/swift3-compatible-4BC51D.svg?style=flat-square)](https://developer.apple.com/swift) 10 | [![swiftyness](https://img.shields.io/badge/pure-swift-ff3f26.svg?style=flat)](https://swift.org/) 11 | [![Swift Version](https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat)](https://swift.org) 12 | [![GitHub stars](https://img.shields.io/github/stars/liufengting/FTImageViewer.svg)](https://github.com/liufengting/FTImageViewer/stargazers) 13 | 14 | 15 | `FTImageViewer` can preview images with just one lines of code. Also `FTImageViewGrid` has make showing images in a grid much easier. I wrote this for my future projects. Feel free to try it in your own projects! 16 | 17 | 18 | # Feathers 19 | - [x] ❤️ Supports both `portrait` and `landscape` 20 | - [x] Single tap to dismiss and auto return to the current index 21 | - [x] Double tap to zoom in and double tap again to zoom out 22 | - [x] Pinch to zoom in/out 23 | - [x] Button tap to dismiss 24 | - [x] Button tap to save current image to system Photo Album 25 | - [x] Pan up/down to dismiss (like Facebook or QQZone) 26 | - [ ] Pan left/right to dismiss at first/last page 27 | 28 | ## ScreenShots 29 | 30 | 31 | 32 | 33 | 34 | 35 |
36 | 37 | run the demo in `FTImageViewerDemo` to see more 38 | 39 | ## Usage 40 | 41 | * show images in a grid and preview images with one line of code 42 | 43 | ```swift 44 | imageGridView.showWithImageArray(imageArray) { (buttonsArray, buttonIndex) in 45 | // in this tap block, preview images with one line of code 46 | FTImageViewer.sharedInstance.showImages(self.imageArray, atIndex: buttonIndex, fromSenderArray: buttonsArray) 47 | } 48 | ``` 49 | * see more docs in `FTImageViewerDemo/DemoTableViewCell.swift` 50 | 51 | ## Installation 52 | 53 | ### Manually 54 | 55 | * clone this repo. 56 | * Simply drop the `FTImageViewer` folder into your project. 57 | * Enjoy! 58 | 59 | ### Cocoapods 60 | 61 | `FTImageViewer` is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: 62 | 63 | ```ruby 64 | pod 'FTImageViewer' 65 | ``` 66 | 67 | # Bouns 68 | 69 | In `FTImageViewerDemo`, shows you how to use it in tableview, using pure `AutoLayout`. Enjoy. 70 | 71 | ## License 72 | 73 | `FTImageViewer` is available under the MIT license. See the `LICENSE` file for more info. 74 | 75 | --------------------------------------------------------------------------------