├── .gitignore ├── HGADView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── HGADView ├── AppDelegate.swift ├── Assets.xcassets │ ├── 1.imageset │ │ ├── Contents.json │ │ └── 屏幕快照 2015-12-30 下午4.39.40.png │ ├── 2.imageset │ │ ├── Contents.json │ │ └── 屏幕快照 2015-12-30 下午4.39.46.png │ ├── 3.imageset │ │ ├── Contents.json │ │ └── 屏幕快照 2015-12-30 下午4.39.57.png │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── HGADView.swift ├── Info.plist └── ViewController.swift ├── LICENSE ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /HGADView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CE6ECB211C33BFEC00013F44 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6ECB201C33BFEC00013F44 /* AppDelegate.swift */; }; 11 | CE6ECB231C33BFEC00013F44 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6ECB221C33BFEC00013F44 /* ViewController.swift */; }; 12 | CE6ECB261C33BFEC00013F44 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE6ECB241C33BFEC00013F44 /* Main.storyboard */; }; 13 | CE6ECB281C33BFEC00013F44 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE6ECB271C33BFEC00013F44 /* Assets.xcassets */; }; 14 | CE6ECB2B1C33BFEC00013F44 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE6ECB291C33BFEC00013F44 /* LaunchScreen.storyboard */; }; 15 | CE6ECB331C33BFFB00013F44 /* HGADView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6ECB321C33BFFB00013F44 /* HGADView.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | CE6ECB1D1C33BFEC00013F44 /* HGADView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HGADView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | CE6ECB201C33BFEC00013F44 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | CE6ECB221C33BFEC00013F44 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | CE6ECB251C33BFEC00013F44 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | CE6ECB271C33BFEC00013F44 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | CE6ECB2A1C33BFEC00013F44 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | CE6ECB2C1C33BFEC00013F44 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | CE6ECB321C33BFFB00013F44 /* HGADView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HGADView.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | CE6ECB1A1C33BFEC00013F44 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | CE6ECB141C33BFEC00013F44 = { 41 | isa = PBXGroup; 42 | children = ( 43 | CE6ECB1F1C33BFEC00013F44 /* HGADView */, 44 | CE6ECB1E1C33BFEC00013F44 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | CE6ECB1E1C33BFEC00013F44 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | CE6ECB1D1C33BFEC00013F44 /* HGADView.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | CE6ECB1F1C33BFEC00013F44 /* HGADView */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | CE6ECB201C33BFEC00013F44 /* AppDelegate.swift */, 60 | CE6ECB221C33BFEC00013F44 /* ViewController.swift */, 61 | CE6ECB241C33BFEC00013F44 /* Main.storyboard */, 62 | CE6ECB271C33BFEC00013F44 /* Assets.xcassets */, 63 | CE6ECB291C33BFEC00013F44 /* LaunchScreen.storyboard */, 64 | CE6ECB2C1C33BFEC00013F44 /* Info.plist */, 65 | CE6ECB321C33BFFB00013F44 /* HGADView.swift */, 66 | ); 67 | path = HGADView; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | CE6ECB1C1C33BFEC00013F44 /* HGADView */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = CE6ECB2F1C33BFEC00013F44 /* Build configuration list for PBXNativeTarget "HGADView" */; 76 | buildPhases = ( 77 | CE6ECB191C33BFEC00013F44 /* Sources */, 78 | CE6ECB1A1C33BFEC00013F44 /* Frameworks */, 79 | CE6ECB1B1C33BFEC00013F44 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = HGADView; 86 | productName = HGADView; 87 | productReference = CE6ECB1D1C33BFEC00013F44 /* HGADView.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | CE6ECB151C33BFEC00013F44 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0720; 97 | LastUpgradeCheck = 0720; 98 | ORGANIZATIONNAME = nero; 99 | TargetAttributes = { 100 | CE6ECB1C1C33BFEC00013F44 = { 101 | CreatedOnToolsVersion = 7.2; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = CE6ECB181C33BFEC00013F44 /* Build configuration list for PBXProject "HGADView" */; 106 | compatibilityVersion = "Xcode 3.2"; 107 | developmentRegion = English; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | Base, 112 | ); 113 | mainGroup = CE6ECB141C33BFEC00013F44; 114 | productRefGroup = CE6ECB1E1C33BFEC00013F44 /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | CE6ECB1C1C33BFEC00013F44 /* HGADView */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | CE6ECB1B1C33BFEC00013F44 /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | CE6ECB2B1C33BFEC00013F44 /* LaunchScreen.storyboard in Resources */, 129 | CE6ECB281C33BFEC00013F44 /* Assets.xcassets in Resources */, 130 | CE6ECB261C33BFEC00013F44 /* Main.storyboard in Resources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXResourcesBuildPhase section */ 135 | 136 | /* Begin PBXSourcesBuildPhase section */ 137 | CE6ECB191C33BFEC00013F44 /* Sources */ = { 138 | isa = PBXSourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | CE6ECB231C33BFEC00013F44 /* ViewController.swift in Sources */, 142 | CE6ECB211C33BFEC00013F44 /* AppDelegate.swift in Sources */, 143 | CE6ECB331C33BFFB00013F44 /* HGADView.swift in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXVariantGroup section */ 150 | CE6ECB241C33BFEC00013F44 /* Main.storyboard */ = { 151 | isa = PBXVariantGroup; 152 | children = ( 153 | CE6ECB251C33BFEC00013F44 /* Base */, 154 | ); 155 | name = Main.storyboard; 156 | sourceTree = ""; 157 | }; 158 | CE6ECB291C33BFEC00013F44 /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | CE6ECB2A1C33BFEC00013F44 /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | CE6ECB2D1C33BFEC00013F44 /* Debug */ = { 170 | isa = XCBuildConfiguration; 171 | buildSettings = { 172 | ALWAYS_SEARCH_USER_PATHS = NO; 173 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 174 | CLANG_CXX_LIBRARY = "libc++"; 175 | CLANG_ENABLE_MODULES = YES; 176 | CLANG_ENABLE_OBJC_ARC = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_CONSTANT_CONVERSION = YES; 179 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 180 | CLANG_WARN_EMPTY_BODY = YES; 181 | CLANG_WARN_ENUM_CONVERSION = YES; 182 | CLANG_WARN_INT_CONVERSION = YES; 183 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 184 | CLANG_WARN_UNREACHABLE_CODE = YES; 185 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 186 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 187 | COPY_PHASE_STRIP = NO; 188 | DEBUG_INFORMATION_FORMAT = dwarf; 189 | ENABLE_STRICT_OBJC_MSGSEND = YES; 190 | ENABLE_TESTABILITY = YES; 191 | GCC_C_LANGUAGE_STANDARD = gnu99; 192 | GCC_DYNAMIC_NO_PIC = NO; 193 | GCC_NO_COMMON_BLOCKS = YES; 194 | GCC_OPTIMIZATION_LEVEL = 0; 195 | GCC_PREPROCESSOR_DEFINITIONS = ( 196 | "DEBUG=1", 197 | "$(inherited)", 198 | ); 199 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 200 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 201 | GCC_WARN_UNDECLARED_SELECTOR = YES; 202 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 203 | GCC_WARN_UNUSED_FUNCTION = YES; 204 | GCC_WARN_UNUSED_VARIABLE = YES; 205 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 206 | MTL_ENABLE_DEBUG_INFO = YES; 207 | ONLY_ACTIVE_ARCH = YES; 208 | SDKROOT = iphoneos; 209 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 210 | }; 211 | name = Debug; 212 | }; 213 | CE6ECB2E1C33BFEC00013F44 /* Release */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 218 | CLANG_CXX_LIBRARY = "libc++"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_WARN_BOOL_CONVERSION = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_EMPTY_BODY = YES; 225 | CLANG_WARN_ENUM_CONVERSION = YES; 226 | CLANG_WARN_INT_CONVERSION = YES; 227 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 228 | CLANG_WARN_UNREACHABLE_CODE = YES; 229 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 230 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 231 | COPY_PHASE_STRIP = NO; 232 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 233 | ENABLE_NS_ASSERTIONS = NO; 234 | ENABLE_STRICT_OBJC_MSGSEND = YES; 235 | GCC_C_LANGUAGE_STANDARD = gnu99; 236 | GCC_NO_COMMON_BLOCKS = YES; 237 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 239 | GCC_WARN_UNDECLARED_SELECTOR = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 241 | GCC_WARN_UNUSED_FUNCTION = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 244 | MTL_ENABLE_DEBUG_INFO = NO; 245 | SDKROOT = iphoneos; 246 | VALIDATE_PRODUCT = YES; 247 | }; 248 | name = Release; 249 | }; 250 | CE6ECB301C33BFEC00013F44 /* Debug */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 254 | INFOPLIST_FILE = HGADView/Info.plist; 255 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 256 | PRODUCT_BUNDLE_IDENTIFIER = com.nero.HGADView; 257 | PRODUCT_NAME = "$(TARGET_NAME)"; 258 | }; 259 | name = Debug; 260 | }; 261 | CE6ECB311C33BFEC00013F44 /* Release */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = HGADView/Info.plist; 266 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 267 | PRODUCT_BUNDLE_IDENTIFIER = com.nero.HGADView; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | }; 270 | name = Release; 271 | }; 272 | /* End XCBuildConfiguration section */ 273 | 274 | /* Begin XCConfigurationList section */ 275 | CE6ECB181C33BFEC00013F44 /* Build configuration list for PBXProject "HGADView" */ = { 276 | isa = XCConfigurationList; 277 | buildConfigurations = ( 278 | CE6ECB2D1C33BFEC00013F44 /* Debug */, 279 | CE6ECB2E1C33BFEC00013F44 /* Release */, 280 | ); 281 | defaultConfigurationIsVisible = 0; 282 | defaultConfigurationName = Release; 283 | }; 284 | CE6ECB2F1C33BFEC00013F44 /* Build configuration list for PBXNativeTarget "HGADView" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | CE6ECB301C33BFEC00013F44 /* Debug */, 288 | CE6ECB311C33BFEC00013F44 /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | }; 292 | /* End XCConfigurationList section */ 293 | }; 294 | rootObject = CE6ECB151C33BFEC00013F44 /* Project object */; 295 | } 296 | -------------------------------------------------------------------------------- /HGADView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HGADView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // HGADView 4 | // 5 | // Created by nero on 15/12/30. 6 | // Copyright © 2015年 nero. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 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 | func applicationDidEnterBackground(application: UIApplication) { 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 | func applicationWillEnterForeground(application: UIApplication) { 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 | func applicationDidBecomeActive(application: UIApplication) { 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 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "屏幕快照 2015-12-30 下午4.39.40.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/1.imageset/屏幕快照 2015-12-30 下午4.39.40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValiantCat/HGADView-Swift/6f72302a5af9914675420b4881e4df11a5b40e2b/HGADView/Assets.xcassets/1.imageset/屏幕快照 2015-12-30 下午4.39.40.png -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "屏幕快照 2015-12-30 下午4.39.46.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/2.imageset/屏幕快照 2015-12-30 下午4.39.46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValiantCat/HGADView-Swift/6f72302a5af9914675420b4881e4df11a5b40e2b/HGADView/Assets.xcassets/2.imageset/屏幕快照 2015-12-30 下午4.39.46.png -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "屏幕快照 2015-12-30 下午4.39.57.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/3.imageset/屏幕快照 2015-12-30 下午4.39.57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValiantCat/HGADView-Swift/6f72302a5af9914675420b4881e4df11a5b40e2b/HGADView/Assets.xcassets/3.imageset/屏幕快照 2015-12-30 下午4.39.57.png -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /HGADView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /HGADView/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 | 27 | 28 | -------------------------------------------------------------------------------- /HGADView/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 | -------------------------------------------------------------------------------- /HGADView/HGADView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HGADView.swift 3 | // HGADView 4 | // 5 | // Created by nero on 15/12/30. 6 | // Copyright © 2015年 nero. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | private let kADViewHeight = 150 11 | 12 | public class HGADView: UIView,UIScrollViewDelegate { 13 | public typealias ADDidClickClosure = (Int) -> Void 14 | public typealias ADViewLoadImageClosure = (UIImageView,ImageType) -> Void 15 | public var imageDidClick:ADDidClickClosure? 16 | public var loadImage:ADViewLoadImageClosure? 17 | public var images = [ImageType]() { 18 | didSet { 19 | pageControl.numberOfPages = images.count 20 | reloadData() 21 | timer?.invalidate() 22 | timer = nil 23 | if images.count > 1 { addTimer() } 24 | } 25 | 26 | } 27 | // MARK: - 移除定时器 28 | public func removeTimer() { 29 | timer?.invalidate() 30 | timer = nil 31 | 32 | } 33 | // MARK: - 添加定时器 34 | public func addTimer() { 35 | guard images.count > 0 else {return;} 36 | timer = NSTimer(timeInterval: 2.5, target: self, selector: Selector("timerScrollImage"), userInfo: nil, repeats: true) 37 | NSRunLoop.currentRunLoop().addTimer(timer!, forMode: NSDefaultRunLoopMode) 38 | NSRunLoop.currentRunLoop().runMode(UITrackingRunLoopMode, beforeDate: NSDate()) 39 | 40 | } 41 | 42 | 43 | 44 | private var currentImageArray = [ImageType]() 45 | private var currentPage = 0 46 | 47 | private var timer:NSTimer? 48 | private lazy var scrollView:UIScrollView = { 49 | 50 | 51 | let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)) 52 | scrollView.contentSize = CGSize(width: self.frame.width * 3, height: self.frame.height) 53 | scrollView.contentOffset = CGPoint(x: self.frame.width, y: 0) 54 | scrollView.pagingEnabled = true 55 | scrollView.showsHorizontalScrollIndicator = false 56 | scrollView.showsVerticalScrollIndicator = false 57 | scrollView.delegate = self 58 | return scrollView 59 | 60 | }() 61 | private lazy var pageControl:UIPageControl = { 62 | let pageWidth = self.frame.width * 0.25 63 | let pageHeight:CGFloat = 20.0 64 | let pageX = self.frame.width - pageWidth - 10.0 65 | let pageY = self.frame.height - 30.0 66 | let pageControl = UIPageControl(frame: CGRect(x: pageX, y: pageY, width: pageWidth, height: pageHeight)) 67 | pageControl.userInteractionEnabled = false 68 | pageControl.hidesForSinglePage = true 69 | pageControl.currentPageIndicatorTintColor = UIColor.whiteColor() 70 | pageControl.pageIndicatorTintColor = UIColor.grayColor() 71 | return pageControl 72 | }() 73 | 74 | @objc private func timerScrollImage() { 75 | reloadData() 76 | scrollView.setContentOffset(CGPoint(x: frame.width * 2.0 , y: 0) , animated: true) 77 | } 78 | override init (frame: CGRect) { 79 | super.init(frame: frame) 80 | 81 | addSubview(scrollView) 82 | addSubview(pageControl) 83 | 84 | 85 | 86 | } 87 | 88 | required public init?(coder aDecoder: NSCoder) { 89 | fatalError("init(coder:) has not been implemented") 90 | } 91 | 92 | deinit { 93 | scrollView.delegate = nil 94 | timer?.invalidate() 95 | timer = nil 96 | } 97 | 98 | private func reloadData() { 99 | 100 | //设置页数 101 | 102 | pageControl.currentPage = currentPage 103 | // //根据当前页取出图片 104 | getDisplayImagesWithCurpage() 105 | // //从scrollView上移除所有的subview 106 | scrollView.subviews.forEach({$0.removeFromSuperview()}) 107 | 108 | for i in 0..<3 { 109 | let frame = CGRect(x: self.frame.width * CGFloat(i), y: 0, width: self.frame.width, height: self.frame.height) 110 | let imageView = UIImageView(frame: frame) 111 | imageView.userInteractionEnabled = true 112 | imageView.clipsToBounds = true 113 | scrollView.addSubview(imageView) 114 | // 将加载图片的内容放给外部 专业无论你说直接加载 还是各种第三方库都能 115 | loadImage?(imageView,currentImageArray[i]) 116 | let tap = UITapGestureRecognizer(target: self, action: Selector("tapImage")) 117 | imageView.addGestureRecognizer(tap) 118 | } 119 | 120 | 121 | 122 | 123 | } 124 | private func getDisplayImagesWithCurpage() { 125 | //取出开头和末尾图片在图片数组里的下标 126 | var front = currentPage - 1 127 | var last = currentPage + 1 128 | //如果当前图片下标是0,则开头图片设置为图片数组的最后一个元素 129 | if currentPage == 0 { 130 | front = images.count - 1 131 | } 132 | //如果当前图片下标是图片数组最后一个元素,则设置末尾图片为图片数组的第一个元素 133 | if currentPage == images.count - 1 { 134 | last = 0 135 | } 136 | //如果当前图片数组不为空,则移除所有元素 137 | if currentImageArray.count > 0 { 138 | currentImageArray = [ImageType]() 139 | } 140 | //当前图片数组添加图片 141 | currentImageArray.append(images[front]) 142 | currentImageArray.append(images[currentPage]) 143 | currentImageArray.append(images[last]) 144 | 145 | 146 | 147 | } 148 | @objc private func tapImage() { 149 | imageDidClick?(currentPage) 150 | 151 | } 152 | public func scrollViewDidScroll(scrollView: UIScrollView) { 153 | //如果scrollView当前偏移位置x大于等于两倍scrollView宽度 154 | if scrollView.contentOffset.x >= frame.width * 2.0 { 155 | //当前图片位置+1 156 | currentPage += 1 157 | //如果当前图片位置超过数组边界,则设置为0 158 | if currentPage == images.count { 159 | currentPage = 0 160 | } 161 | reloadData() 162 | //设置scrollView偏移位置 163 | scrollView.contentOffset = CGPoint(x: frame.width, y: 0) 164 | }else if scrollView.contentOffset.x <= 0.0{ 165 | currentPage -= 1 166 | if currentPage == -1 { 167 | currentPage = images.count - 1 168 | } 169 | reloadData() 170 | //设置scrollView偏移位置 171 | scrollView.contentOffset = CGPoint(x: frame.width, y: 0) 172 | } 173 | 174 | } 175 | // MARK: 停止滚动的时候回调 176 | public func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 177 | scrollView.setContentOffset(CGPoint(x: frame.width, y: 0), animated: true) 178 | } 179 | // MARK: 开始拖拽的时候调用 180 | public func scrollViewWillBeginDragging(scrollView: UIScrollView) { 181 | // 停止定时器(一旦定时器停止了,就不能再使用) 182 | removeTimer() 183 | } 184 | // MARK: 停止拖拽的时候调用 185 | public func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { 186 | addTimer() 187 | } 188 | 189 | } 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /HGADView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /HGADView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // HGADView 4 | // 5 | // Created by nero on 15/12/30. 6 | // Copyright © 2015年 nero. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | var adView:HGADView? 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | let adView = HGADView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 200)) 17 | view.addSubview(adView) 18 | let images = ["1","2","3"] 19 | adView.images = images 20 | 21 | adView.imageDidClick = { [unowned self] index in 22 | print("第\(index)张图片被点击了") 23 | 24 | } 25 | adView.loadImage = { ( imageView:UIImageView,imageName:String) in 26 | imageView.image = UIImage(named: imageName) 27 | // or use Other Modules 28 | } 29 | self.adView = adView 30 | 31 | 32 | } 33 | override func viewWillAppear(animated: Bool) { 34 | super.viewDidAppear(animated) 35 | adView?.addTimer() 36 | } 37 | override func viewWillDisappear(animated: Bool) { 38 | super.viewWillDisappear(animated) 39 | adView?.removeTimer() 40 | } 41 | override func touchesBegan(touches: Set, withEvent event: UIEvent?) { 42 | 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The Artistic License 2.0 2 | 3 | Copyright (c) 2015 姜沂 4 | 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | This license establishes the terms under which a given free software 11 | Package may be copied, modified, distributed, and/or redistributed. 12 | The intent is that the Copyright Holder maintains some artistic 13 | control over the development of that Package while still keeping the 14 | Package available as open source and free software. 15 | 16 | You are always permitted to make arrangements wholly outside of this 17 | license directly with the Copyright Holder of a given Package. If the 18 | terms of this license do not permit the full use that you propose to 19 | make of the Package, you should contact the Copyright Holder and seek 20 | a different licensing arrangement. 21 | 22 | Definitions 23 | 24 | "Copyright Holder" means the individual(s) or organization(s) 25 | named in the copyright notice for the entire Package. 26 | 27 | "Contributor" means any party that has contributed code or other 28 | material to the Package, in accordance with the Copyright Holder's 29 | procedures. 30 | 31 | "You" and "your" means any person who would like to copy, 32 | distribute, or modify the Package. 33 | 34 | "Package" means the collection of files distributed by the 35 | Copyright Holder, and derivatives of that collection and/or of 36 | those files. A given Package may consist of either the Standard 37 | Version, or a Modified Version. 38 | 39 | "Distribute" means providing a copy of the Package or making it 40 | accessible to anyone else, or in the case of a company or 41 | organization, to others outside of your company or organization. 42 | 43 | "Distributor Fee" means any fee that you charge for Distributing 44 | this Package or providing support for this Package to another 45 | party. It does not mean licensing fees. 46 | 47 | "Standard Version" refers to the Package if it has not been 48 | modified, or has been modified only in ways explicitly requested 49 | by the Copyright Holder. 50 | 51 | "Modified Version" means the Package, if it has been changed, and 52 | such changes were not explicitly requested by the Copyright 53 | Holder. 54 | 55 | "Original License" means this Artistic License as Distributed with 56 | the Standard Version of the Package, in its current version or as 57 | it may be modified by The Perl Foundation in the future. 58 | 59 | "Source" form means the source code, documentation source, and 60 | configuration files for the Package. 61 | 62 | "Compiled" form means the compiled bytecode, object code, binary, 63 | or any other form resulting from mechanical transformation or 64 | translation of the Source form. 65 | 66 | 67 | Permission for Use and Modification Without Distribution 68 | 69 | (1) You are permitted to use the Standard Version and create and use 70 | Modified Versions for any purpose without restriction, provided that 71 | you do not Distribute the Modified Version. 72 | 73 | 74 | Permissions for Redistribution of the Standard Version 75 | 76 | (2) You may Distribute verbatim copies of the Source form of the 77 | Standard Version of this Package in any medium without restriction, 78 | either gratis or for a Distributor Fee, provided that you duplicate 79 | all of the original copyright notices and associated disclaimers. At 80 | your discretion, such verbatim copies may or may not include a 81 | Compiled form of the Package. 82 | 83 | (3) You may apply any bug fixes, portability changes, and other 84 | modifications made available from the Copyright Holder. The resulting 85 | Package will still be considered the Standard Version, and as such 86 | will be subject to the Original License. 87 | 88 | 89 | Distribution of Modified Versions of the Package as Source 90 | 91 | (4) You may Distribute your Modified Version as Source (either gratis 92 | or for a Distributor Fee, and with or without a Compiled form of the 93 | Modified Version) provided that you clearly document how it differs 94 | from the Standard Version, including, but not limited to, documenting 95 | any non-standard features, executables, or modules, and provided that 96 | you do at least ONE of the following: 97 | 98 | (a) make the Modified Version available to the Copyright Holder 99 | of the Standard Version, under the Original License, so that the 100 | Copyright Holder may include your modifications in the Standard 101 | Version. 102 | 103 | (b) ensure that installation of your Modified Version does not 104 | prevent the user installing or running the Standard Version. In 105 | addition, the Modified Version must bear a name that is different 106 | from the name of the Standard Version. 107 | 108 | (c) allow anyone who receives a copy of the Modified Version to 109 | make the Source form of the Modified Version available to others 110 | under 111 | 112 | (i) the Original License or 113 | 114 | (ii) a license that permits the licensee to freely copy, 115 | modify and redistribute the Modified Version using the same 116 | licensing terms that apply to the copy that the licensee 117 | received, and requires that the Source form of the Modified 118 | Version, and of any works derived from it, be made freely 119 | available in that license fees are prohibited but Distributor 120 | Fees are allowed. 121 | 122 | 123 | Distribution of Compiled Forms of the Standard Version 124 | or Modified Versions without the Source 125 | 126 | (5) You may Distribute Compiled forms of the Standard Version without 127 | the Source, provided that you include complete instructions on how to 128 | get the Source of the Standard Version. Such instructions must be 129 | valid at the time of your distribution. If these instructions, at any 130 | time while you are carrying out such distribution, become invalid, you 131 | must provide new instructions on demand or cease further distribution. 132 | If you provide valid instructions or cease distribution within thirty 133 | days after you become aware that the instructions are invalid, then 134 | you do not forfeit any of your rights under this license. 135 | 136 | (6) You may Distribute a Modified Version in Compiled form without 137 | the Source, provided that you comply with Section 4 with respect to 138 | the Source of the Modified Version. 139 | 140 | 141 | Aggregating or Linking the Package 142 | 143 | (7) You may aggregate the Package (either the Standard Version or 144 | Modified Version) with other packages and Distribute the resulting 145 | aggregation provided that you do not charge a licensing fee for the 146 | Package. Distributor Fees are permitted, and licensing fees for other 147 | components in the aggregation are permitted. The terms of this license 148 | apply to the use and Distribution of the Standard or Modified Versions 149 | as included in the aggregation. 150 | 151 | (8) You are permitted to link Modified and Standard Versions with 152 | other works, to embed the Package in a larger work of your own, or to 153 | build stand-alone binary or bytecode versions of applications that 154 | include the Package, and Distribute the result without restriction, 155 | provided the result does not expose a direct interface to the Package. 156 | 157 | 158 | Items That are Not Considered Part of a Modified Version 159 | 160 | (9) Works (including, but not limited to, modules and scripts) that 161 | merely extend or make use of the Package, do not, by themselves, cause 162 | the Package to be a Modified Version. In addition, such works are not 163 | considered parts of the Package itself, and are not subject to the 164 | terms of this license. 165 | 166 | 167 | General Provisions 168 | 169 | (10) Any use, modification, and distribution of the Standard or 170 | Modified Versions is governed by this Artistic License. By using, 171 | modifying or distributing the Package, you accept this license. Do not 172 | use, modify, or distribute the Package, if you do not accept this 173 | license. 174 | 175 | (11) If your Modified Version has been derived from a Modified 176 | Version made by someone other than you, you are nevertheless required 177 | to ensure that your Modified Version complies with the requirements of 178 | this license. 179 | 180 | (12) This license does not grant you the right to use any trademark, 181 | service mark, tradename, or logo of the Copyright Holder. 182 | 183 | (13) This license includes the non-exclusive, worldwide, 184 | free-of-charge patent license to make, have made, use, offer to sell, 185 | sell, import and otherwise transfer the Package with respect to any 186 | patent claims licensable by the Copyright Holder that are necessarily 187 | infringed by the Package. If you institute patent litigation 188 | (including a cross-claim or counterclaim) against any party alleging 189 | that the Package constitutes direct or contributory patent 190 | infringement, then this Artistic License to you shall terminate on the 191 | date that such litigation is filed. 192 | 193 | (14) Disclaimer of Warranty: 194 | THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS 195 | IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED 196 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 197 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL 198 | LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL 199 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 200 | DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF 201 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HGADView-Swift 2 | Swift版轮播器 3 | 4 | 5 | 专门为Swift写的轮播器 非常具有Swift的风格 6 | 7 | 1 到导入项目 将HGADView拖进项目即可 8 | 2 初始化 如下 9 | 10 | let adView = HGADView(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 200)) 11 | view.addSubview(adView) 12 | let images = ["1","2","3"] 13 | adView.images = images 14 | 15 | adView.imageDidClick = { index in 16 | print("第\(index)张图片被点击了") 17 | 18 | } 19 | // 加载图片的代码 20 | adView.loadImage = { ( imageView:UIImageView,imageName:String) in 21 | imageView.image = UIImage(named: imageName) 22 | // or use Other Modules 23 | } 24 | 25 | 26 | 3 Demo见下图 27 | ![demo](https://github.com/aiqiuqiu/HGADView-Swift/blob/master/demo.gif) 28 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValiantCat/HGADView-Swift/6f72302a5af9914675420b4881e4df11a5b40e2b/demo.gif --------------------------------------------------------------------------------