├── .DS_Store ├── WMQRCode ├── .DS_Store ├── WMQRCode │ ├── .DS_Store │ ├── Resource.bundle │ │ ├── ewm@2x.png │ │ ├── ewm@3x.png │ │ ├── line@2x.png │ │ ├── light@2x.png │ │ ├── lighton@2x.png │ │ ├── codeframe@2x.png │ │ ├── codeframe@3x.png │ │ └── fromPhoto@2x.png │ ├── WMQRCodeViewController.h │ └── WMQRCodeViewController.m ├── SVProgressHUD │ ├── SVProgressHUD.bundle │ │ ├── error.png │ │ ├── info.png │ │ ├── info@2x.png │ │ ├── info@3x.png │ │ ├── success.png │ │ ├── angle-mask.png │ │ ├── error@2x.png │ │ ├── error@3x.png │ │ ├── success@2x.png │ │ ├── success@3x.png │ │ ├── angle-mask@2x.png │ │ └── angle-mask@3x.png │ ├── SVProgressHUD-Prefix.pch │ ├── SVRadialGradientLayer.h │ ├── SVIndefiniteAnimatedView.h │ ├── SVRadialGradientLayer.m │ ├── SVIndefiniteAnimatedView.m │ ├── SVProgressHUD.h │ └── SVProgressHUD.m ├── ViewController.h ├── AppDelegate.h ├── main.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── ViewController.m ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard └── AppDelegate.m ├── README.md ├── WMQRCode.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ │ └── wenming.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── xcuserdata │ └── wenming.xcuserdatad │ │ ├── xcschemes │ │ ├── xcschememanagement.plist │ │ └── WMQRCode.xcscheme │ │ └── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist └── project.pbxproj ├── LICENSE └── .gitignore /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/.DS_Store -------------------------------------------------------------------------------- /WMQRCode/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WMQRCode 2 | iOS原生二维码扫描,识别图片中的二维码信息。(赠送扫描动画,手电筒🔦功能让你夜里也可以轻松扫描二维码) 3 | 4 | 2017.12.1更新支持条形码扫描。 5 | -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/.DS_Store -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/ewm@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/ewm@2x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/ewm@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/ewm@3x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/line@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/line@2x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/light@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/light@2x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/lighton@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/lighton@2x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/codeframe@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/codeframe@2x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/codeframe@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/codeframe@3x.png -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/Resource.bundle/fromPhoto@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/WMQRCode/Resource.bundle/fromPhoto@2x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info@2x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/info@3x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error@2x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/error@3x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success@2x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/success@3x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask@2x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode/SVProgressHUD/SVProgressHUD.bundle/angle-mask@3x.png -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SVProgressHUD' target in the 'SVProgressHUD' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/project.xcworkspace/xcuserdata/wenming.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhengwenming/WMQRCode/HEAD/WMQRCode.xcodeproj/project.xcworkspace/xcuserdata/wenming.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /WMQRCode/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/WMQRCodeViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WMQRCodeViewController.h 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WMQRCodeViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /WMQRCode/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVRadialGradientLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVRadialGradientLayer.h 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2014 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface SVRadialGradientLayer : CALayer 11 | 12 | @property (nonatomic) CGPoint gradientCenter; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /WMQRCode/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVIndefiniteAnimatedView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVIndefiniteAnimatedView.h 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2014 Guillaume Campagna. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface SVIndefiniteAnimatedView : UIView 11 | 12 | @property (nonatomic, assign) CGFloat strokeThickness; 13 | @property (nonatomic, assign) CGFloat radius; 14 | @property (nonatomic, strong) UIColor *strokeColor; 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/xcuserdata/wenming.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | WMQRCode.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | BF7FD0451DC849D5000CC513 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WMQRCode/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 | } -------------------------------------------------------------------------------- /WMQRCode/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WMQRCodeViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | UIButton *centerBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 22 | centerBtn.frame = CGRectMake(0, 0, 100, 40); 23 | centerBtn.backgroundColor = [UIColor redColor]; 24 | [centerBtn setTitle:@"扫描" forState:UIControlStateNormal]; 25 | [centerBtn addTarget:self action:@selector(scanQrcode) forControlEvents:UIControlEventTouchUpInside]; 26 | [self.view addSubview:centerBtn]; 27 | centerBtn.center = self.view.center; 28 | 29 | } 30 | 31 | -(void)scanQrcode{ 32 | [self.navigationController pushViewController:[WMQRCodeViewController new] animated:YES]; 33 | } 34 | @end 35 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVRadialGradientLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVRadialGradientLayer.m 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2014 Tobias Tiemerding. All rights reserved. 6 | // 7 | 8 | #import "SVRadialGradientLayer.h" 9 | 10 | @implementation SVRadialGradientLayer 11 | 12 | - (void)drawInContext:(CGContextRef)context { 13 | size_t locationsCount = 2; 14 | CGFloat locations[2] = {0.0f, 1.0f}; 15 | CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; 16 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 17 | CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); 18 | CGColorSpaceRelease(colorSpace); 19 | 20 | float radius = MIN(self.bounds.size.width , self.bounds.size.height) ; 21 | CGContextDrawRadialGradient (context, gradient, self.gradientCenter, 0, self.gradientCenter, radius, kCGGradientDrawsAfterEndLocation); 22 | CGGradientRelease(gradient); 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 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 | -------------------------------------------------------------------------------- /WMQRCode/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPhotoLibraryUsageDescription 6 | 想访问您的相册 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSCameraUsageDescription 26 | 想访问您的📷 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /WMQRCode/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 | -------------------------------------------------------------------------------- /WMQRCode/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WMQRCode 4 | // 5 | // Created by 郑文明 on 16/11/1. 6 | // Copyright © 2016年 郑文明. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /WMQRCode/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/xcuserdata/wenming.xcuserdatad/xcschemes/WMQRCode.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVIndefiniteAnimatedView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVIndefiniteAnimatedView.m 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2014 Guillaume Campagna. All rights reserved. 6 | // 7 | 8 | #import "SVIndefiniteAnimatedView.h" 9 | 10 | #pragma mark SVIndefiniteAnimatedView 11 | 12 | @interface SVIndefiniteAnimatedView () 13 | 14 | @property (nonatomic, strong) CAShapeLayer *indefiniteAnimatedLayer; 15 | 16 | @end 17 | 18 | @implementation SVIndefiniteAnimatedView 19 | 20 | - (void)willMoveToSuperview:(UIView *)newSuperview { 21 | if (newSuperview) { 22 | [self layoutAnimatedLayer]; 23 | } else { 24 | [_indefiniteAnimatedLayer removeFromSuperlayer]; 25 | _indefiniteAnimatedLayer = nil; 26 | } 27 | } 28 | 29 | - (void)layoutAnimatedLayer { 30 | CALayer *layer = self.indefiniteAnimatedLayer; 31 | [self.layer addSublayer:layer]; 32 | layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2); 33 | } 34 | 35 | - (CAShapeLayer*)indefiniteAnimatedLayer { 36 | if(!_indefiniteAnimatedLayer) { 37 | CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5); 38 | CGRect rect = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2); 39 | 40 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter 41 | radius:self.radius 42 | startAngle:(CGFloat) (M_PI*3/2) 43 | endAngle:(CGFloat) (M_PI/2+M_PI*5) 44 | clockwise:YES]; 45 | 46 | _indefiniteAnimatedLayer = [CAShapeLayer layer]; 47 | _indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale]; 48 | _indefiniteAnimatedLayer.frame = rect; 49 | _indefiniteAnimatedLayer.fillColor = [UIColor clearColor].CGColor; 50 | _indefiniteAnimatedLayer.strokeColor = self.strokeColor.CGColor; 51 | _indefiniteAnimatedLayer.lineWidth = self.strokeThickness; 52 | _indefiniteAnimatedLayer.lineCap = kCALineCapRound; 53 | _indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel; 54 | _indefiniteAnimatedLayer.path = smoothedPath.CGPath; 55 | 56 | CALayer *maskLayer = [CALayer layer]; 57 | 58 | NSBundle *bundle = [NSBundle bundleForClass:self.class]; 59 | NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"]; 60 | NSBundle *imageBundle = [NSBundle bundleWithURL:url]; 61 | NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"]; 62 | 63 | maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage]; 64 | maskLayer.frame = _indefiniteAnimatedLayer.bounds; 65 | _indefiniteAnimatedLayer.mask = maskLayer; 66 | 67 | NSTimeInterval animationDuration = 1; 68 | CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 69 | 70 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 71 | animation.fromValue = (id) 0; 72 | animation.toValue = @(M_PI*2); 73 | animation.duration = animationDuration; 74 | animation.timingFunction = linearCurve; 75 | animation.removedOnCompletion = NO; 76 | animation.repeatCount = INFINITY; 77 | animation.fillMode = kCAFillModeForwards; 78 | animation.autoreverses = NO; 79 | [_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"]; 80 | 81 | CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; 82 | animationGroup.duration = animationDuration; 83 | animationGroup.repeatCount = INFINITY; 84 | animationGroup.removedOnCompletion = NO; 85 | animationGroup.timingFunction = linearCurve; 86 | 87 | CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"]; 88 | strokeStartAnimation.fromValue = @0.015; 89 | strokeStartAnimation.toValue = @0.515; 90 | 91 | CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 92 | strokeEndAnimation.fromValue = @0.485; 93 | strokeEndAnimation.toValue = @0.985; 94 | 95 | animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation]; 96 | [_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"]; 97 | 98 | } 99 | return _indefiniteAnimatedLayer; 100 | } 101 | 102 | - (void)setFrame:(CGRect)frame { 103 | if(!CGRectEqualToRect(frame, super.frame)){ 104 | [super setFrame:frame]; 105 | 106 | if (self.superview) { 107 | [self layoutAnimatedLayer]; 108 | } 109 | } 110 | 111 | } 112 | 113 | - (void)setRadius:(CGFloat)radius { 114 | if(radius != _radius){ 115 | _radius = radius; 116 | 117 | [_indefiniteAnimatedLayer removeFromSuperlayer]; 118 | _indefiniteAnimatedLayer = nil; 119 | 120 | if (self.superview) { 121 | [self layoutAnimatedLayer]; 122 | } 123 | } 124 | } 125 | 126 | - (void)setStrokeColor:(UIColor *)strokeColor { 127 | _strokeColor = strokeColor; 128 | _indefiniteAnimatedLayer.strokeColor = strokeColor.CGColor; 129 | } 130 | 131 | - (void)setStrokeThickness:(CGFloat)strokeThickness { 132 | _strokeThickness = strokeThickness; 133 | _indefiniteAnimatedLayer.lineWidth = _strokeThickness; 134 | } 135 | 136 | - (CGSize)sizeThatFits:(CGSize)size { 137 | return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2); 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/xcuserdata/wenming.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 72 | 84 | 85 | 86 | 88 | 98 | 99 | 100 | 102 | 114 | 115 | 116 | 118 | 130 | 131 | 132 | 134 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressHUD.h 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2011-2014 Sam Vermette and contributors. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | #if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000 12 | 13 | #define UI_APPEARANCE_SELECTOR 14 | 15 | #endif 16 | 17 | extern NSString * const SVProgressHUDDidReceiveTouchEventNotification; 18 | extern NSString * const SVProgressHUDDidTouchDownInsideNotification; 19 | extern NSString * const SVProgressHUDWillDisappearNotification; 20 | extern NSString * const SVProgressHUDDidDisappearNotification; 21 | extern NSString * const SVProgressHUDWillAppearNotification; 22 | extern NSString * const SVProgressHUDDidAppearNotification; 23 | 24 | extern NSString * const SVProgressHUDStatusUserInfoKey; 25 | 26 | typedef NS_ENUM(NSInteger, SVProgressHUDStyle) { 27 | SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred on iOS 8 and above 28 | SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred on iOS 8 and above 29 | SVProgressHUDStyleCustom // uses the fore- and background color properties 30 | }; 31 | 32 | typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) { 33 | SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed 34 | SVProgressHUDMaskTypeClear, // don't allow user interactions 35 | SVProgressHUDMaskTypeBlack, // don't allow user interactions and dim the UI in the back of the HUD, as on iOS 7 and above 36 | SVProgressHUDMaskTypeGradient // don't allow user interactions and dim the UI with a a-la UIAlertView background gradient, as on iOS 6 37 | }; 38 | 39 | typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) { 40 | SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring) 41 | SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView 42 | }; 43 | 44 | @interface SVProgressHUD : UIView 45 | 46 | #pragma mark - Customization 47 | 48 | @property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight 49 | @property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone 50 | @property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat 51 | @property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message 52 | @property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt 53 | @property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt 54 | @property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt 55 | @property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt 56 | @property (strong, nonatomic) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] 57 | @property (strong, nonatomic) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor whiteColor] 58 | @property (strong, nonatomic) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor] 59 | @property (strong, nonatomic) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik 60 | @property (strong, nonatomic) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik 61 | @property (strong, nonatomic) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik 62 | @property (strong, nonatomic) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set 63 | @property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds 64 | 65 | @property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0 66 | 67 | + (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight 68 | + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone 69 | + (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat 70 | + (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message 71 | + (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt 72 | + (void)setRingRadius:(CGFloat)radius; // default is 18 pt 73 | + (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt 74 | + (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt 75 | + (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] 76 | + (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom 77 | + (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom 78 | + (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik 79 | + (void)setSuccessImage:(UIImage*)image; // default is the bundled success image provided by Freepik 80 | + (void)setErrorImage:(UIImage*)image; // default is the bundled error image provided by Freepik 81 | + (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set 82 | + (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds 83 | 84 | #pragma mark - Show Methods 85 | 86 | + (void)show; 87 | + (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead."))); 88 | + (void)showWithStatus:(NSString*)status; 89 | + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead."))); 90 | 91 | + (void)showProgress:(float)progress; 92 | + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead."))); 93 | + (void)showProgress:(float)progress status:(NSString*)status; 94 | + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead."))); 95 | 96 | + (void)setStatus:(NSString*)status; // change the HUD loading status while it's showing 97 | 98 | // stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later 99 | + (void)showInfoWithStatus:(NSString*)status; 100 | + (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead."))); 101 | + (void)showSuccessWithStatus:(NSString*)status; 102 | + (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead."))); 103 | + (void)showErrorWithStatus:(NSString*)status; 104 | + (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead."))); 105 | 106 | // shows a image + status, use 28x28 white PNGs 107 | + (void)showImage:(UIImage*)image status:(NSString*)status; 108 | + (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage: and setDefaultMaskType: instead."))); 109 | 110 | + (void)setOffsetFromCenter:(UIOffset)offset; 111 | + (void)resetOffsetFromCenter; 112 | 113 | + (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed 114 | + (void)dismiss; 115 | + (void)dismissWithDelay:(NSTimeInterval)delay; // delayes the dismissal 116 | 117 | + (BOOL)isVisible; 118 | 119 | + (NSTimeInterval)displayDurationForString:(NSString*)string; 120 | 121 | @end 122 | 123 | -------------------------------------------------------------------------------- /WMQRCode/WMQRCode/WMQRCodeViewController.m: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // WMQRCodeViewController.m 4 | // WMQRCode 5 | // 6 | // Created by 郑文明 on 16/11/1. 7 | // Copyright © 2016年 郑文明. All rights reserved. 8 | // 9 | 10 | #import "WMQRCodeViewController.h" 11 | #import "SVProgressHUD.h" 12 | 13 | 14 | #define kDeviceVersion [[UIDevice currentDevice].systemVersion floatValue] 15 | 16 | #define kScreenWidth [UIScreen mainScreen].bounds.size.width 17 | #define kScreenHeight [UIScreen mainScreen].bounds.size.height 18 | #define kNavbarHeight ((kDeviceVersion>=7.0)? 64 :44 ) 19 | 20 | #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 21 | #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 22 | 23 | #define kSCREEN_MAX_LENGTH (MAX(kScreenWidth, kScreenHeight)) 24 | #define kSCREEN_MIN_LENGTH (MIN(kScreenWidth, kScreenHeight)) 25 | 26 | #define IS_IPHONE4 (IS_IPHONE && kSCREEN_MAX_LENGTH < 568.0) 27 | #define IS_IPHONE5 (IS_IPHONE && kSCREEN_MAX_LENGTH == 568.0) 28 | #define IS_IPHONE6 (IS_IPHONE && kSCREEN_MAX_LENGTH == 667.0) 29 | #define IS_IPHONE6P (IS_IPHONE && kSCREEN_MAX_LENGTH == 736.0) 30 | 31 | @import AVFoundation; 32 | 33 | 34 | @interface WMQRCodeViewController (){ 35 | UILabel * introLab; 36 | BOOL isLightOn; 37 | UIButton *mineQRCode; 38 | UIButton *theLightBtn; 39 | BOOL hasTheVC; 40 | BOOL isFirst; 41 | BOOL isUp; 42 | int num; 43 | AVCaptureVideoPreviewLayer *preView; 44 | AVCaptureDevice *captureDevice; 45 | NSTimer * timer; 46 | 47 | 48 | } 49 | @property (nonatomic,strong) AVCaptureSession *session; 50 | @property (nonatomic,weak) AVCaptureMetadataOutput *output; 51 | @property (nonatomic,retain) UIImageView *lineIV; 52 | /** 扫描支持的编码格式的数组 */ 53 | @property (nonatomic, strong) NSMutableArray * metadataObjectTypes; 54 | 55 | @end 56 | 57 | @implementation WMQRCodeViewController 58 | - (NSMutableArray *)metadataObjectTypes{ 59 | if (!_metadataObjectTypes) { 60 | _metadataObjectTypes = [NSMutableArray arrayWithObjects:AVMetadataObjectTypeAztecCode, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeUPCECode, nil]; 61 | 62 | // >= iOS 8 63 | if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) { 64 | [_metadataObjectTypes addObjectsFromArray:@[AVMetadataObjectTypeInterleaved2of5Code, AVMetadataObjectTypeITF14Code, AVMetadataObjectTypeDataMatrixCode]]; 65 | } 66 | } 67 | 68 | return _metadataObjectTypes; 69 | } 70 | - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ 71 | [self dismissViewControllerAnimated:YES completion:^{ 72 | // [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault]; 73 | }]; 74 | } 75 | 76 | - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 77 | 78 | //[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault]; 79 | viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor]; 80 | viewController.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor]; 81 | NSDictionary *attributeDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:17.0], NSFontAttributeName, nil]; 82 | navigationController.navigationBar.titleTextAttributes = attributeDic; 83 | } 84 | - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { 85 | 86 | UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; 87 | if (!image) { 88 | image = [info objectForKey:UIImagePickerControllerOriginalImage]; 89 | } 90 | 91 | ; 92 | [self dismissViewControllerAnimated:NO completion:^{ 93 | //[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault]; 94 | }]; 95 | NSString *stringValue = [self stringFromFileImage:image]; 96 | [self checkQRcode:stringValue]; 97 | 98 | } 99 | 100 | - (void)rightBarButtonItemPressed:(UIButton *)sender { 101 | 102 | // if (kDeviceVersion<=7.0) { 103 | // } 104 | // else { 105 | // self.detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }]; 106 | // } 107 | 108 | UIImagePickerController *pickCtr = [[UIImagePickerController alloc] init]; 109 | pickCtr.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 110 | pickCtr.delegate= self; 111 | pickCtr.allowsEditing = NO; 112 | pickCtr.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]; 113 | [self presentViewController:pickCtr animated:YES completion:^{ 114 | 115 | }]; 116 | NSArray *vcs = self.navigationController.viewControllers; 117 | NSLog(@"vcs = %@",vcs); 118 | } 119 | -(void)initUI{ 120 | isFirst=YES; 121 | isUp = NO; 122 | num =0; 123 | // 自定义导航右按钮 124 | NSString *name = [@"Resource.bundle" stringByAppendingPathComponent:@"fromPhoto"]; 125 | UIImage *fromPhoto = [UIImage imageNamed:name]; 126 | UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; 127 | rightButton.frame = CGRectMake(0, 0, fromPhoto.size.width, fromPhoto.size.height); 128 | [rightButton setImage:fromPhoto forState:UIControlStateNormal]; 129 | [rightButton setImage:fromPhoto forState:UIControlStateSelected]; 130 | [rightButton addTarget:self action:@selector(rightBarButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside]; 131 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton]; 132 | 133 | } 134 | - (void)startSessionRightNow:(NSNotification*)notification { 135 | //[timer resumeTimer]; 136 | [self creatTimer]; 137 | [_session startRunning]; 138 | } 139 | - (void)viewDidAppear:(BOOL)animated { 140 | [super viewDidAppear:animated]; 141 | if(isFirst) 142 | { 143 | [self creatTimer]; 144 | [_session startRunning]; 145 | } 146 | isFirst=NO; 147 | } 148 | 149 | - (void)viewWillDisappear:(BOOL)animated { 150 | [super viewWillDisappear:animated]; 151 | [self deleteTimer]; 152 | [[NSNotificationCenter defaultCenter]removeObserver:self name:@"startSession" object:nil]; 153 | } 154 | 155 | - (void)viewDidDisappear:(BOOL)animated { 156 | [super viewDidDisappear:animated]; 157 | } 158 | #pragma mark - 删除timer 159 | - (void)deleteTimer 160 | { 161 | if (timer) { 162 | [timer invalidate]; 163 | timer=nil; 164 | } 165 | } 166 | #pragma mark - 创建timer 167 | - (void)creatTimer 168 | { 169 | if (!timer) { 170 | timer=[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(animation) userInfo:nil repeats:YES]; 171 | } 172 | } 173 | - (void)viewWillAppear:(BOOL)animated { 174 | [super viewWillAppear:animated]; 175 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startSessionRightNow:) name:@"startSession" object:nil]; 176 | if (!isFirst) { 177 | [self creatTimer]; 178 | [_session startRunning]; 179 | } 180 | } 181 | - (void)viewDidLoad { 182 | self.navigationItem.title = @"扫一扫"; 183 | 184 | self.view.backgroundColor = [UIColor colorWithWhite:0.2 alpha:1]; 185 | [super viewDidLoad]; 186 | 187 | [self initUI]; 188 | [self setupDevice]; 189 | } 190 | -(void)setupDevice{ 191 | //1.初始化捕捉设备(AVCaptureDevice),类型为AVMediaTypeVideo 192 | captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 193 | 194 | NSError *error; 195 | //2.用captureDevice创建输入流input 196 | AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error]; 197 | if (!input) { 198 | NSLog(@"%@", [error localizedDescription]); 199 | return ; 200 | } 201 | 202 | //创建会话 203 | _session = [[AVCaptureSession alloc] init]; 204 | [_session setSessionPreset:AVCaptureSessionPresetHigh]; 205 | 206 | if ([_session canAddInput:input]) { 207 | [_session addInput:input]; 208 | } 209 | 210 | //预览视图 211 | preView = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_session]; 212 | //设置预览图层填充方式 213 | [preView setVideoGravity:AVLayerVideoGravityResizeAspectFill]; 214 | preView.frame = CGRectMake(kNavbarHeight / 2, kNavbarHeight + 30, self.view.frame.size.width - kNavbarHeight, self.view.frame.size.width - kNavbarHeight); 215 | [self.view.layer insertSublayer:preView atIndex:0]; 216 | 217 | 218 | 219 | 220 | //输出 221 | AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init]; 222 | [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; 223 | if ([_session canAddOutput:output]) { 224 | [_session addOutput:output]; 225 | } 226 | self.output = output; 227 | 228 | NSArray *arrTypes = output.availableMetadataObjectTypes; 229 | NSLog(@"%@",arrTypes); 230 | 231 | if ([_output.availableMetadataObjectTypes containsObject:AVMetadataObjectTypeQRCode] || [_output.availableMetadataObjectTypes containsObject:AVMetadataObjectTypeCode128Code]) { 232 | output.metadataObjectTypes = self.metadataObjectTypes; 233 | // [_session startRunning]; 234 | } else { 235 | [_session stopRunning]; 236 | // rightButton.enabled = NO; 237 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"抱歉!" message:@"相机权限被拒绝,请前往设置-隐私-相机启用此应用的相机权限。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; 238 | [alert show]; 239 | return; 240 | } 241 | 242 | 243 | UIImageView *codeFrame = [[UIImageView alloc] initWithFrame:preView.frame]; 244 | codeFrame.contentMode = UIViewContentModeScaleAspectFit; 245 | NSString *name = [@"Resource.bundle" stringByAppendingPathComponent:@"codeframe"]; 246 | 247 | [codeFrame setImage:[UIImage imageNamed:name]]; 248 | [self.view addSubview:codeFrame]; 249 | 250 | introLab = [[UILabel alloc] initWithFrame:CGRectMake(preView.frame.origin.x, preView.frame.origin.y + preView.frame.size.height, preView.frame.size.width, 40)]; 251 | introLab.numberOfLines = 1; 252 | introLab.textAlignment = NSTextAlignmentCenter; 253 | introLab.textColor = [UIColor whiteColor]; 254 | introLab.adjustsFontSizeToFitWidth = YES; 255 | introLab.text = @"将二维码/条码放入框内,即可自动扫描"; 256 | [self.view addSubview:introLab]; 257 | 258 | //我的二维码按钮 259 | mineQRCode = [UIButton buttonWithType:UIButtonTypeCustom]; 260 | mineQRCode.frame = CGRectMake(self.view.frame.size.width / 2 - 100 / 2, introLab.frame.origin.y+introLab.frame.size.height - 5, 100, introLab.frame.size.height); 261 | [mineQRCode setTitle:@"我的二维码" forState:UIControlStateNormal]; 262 | [mineQRCode setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 263 | [mineQRCode addTarget:self action:@selector(showTheQRCodeOfMine:) forControlEvents:UIControlEventTouchUpInside]; 264 | [self.view addSubview:mineQRCode]; 265 | mineQRCode.hidden = YES; 266 | 267 | //theLightBtn 268 | theLightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 269 | 270 | theLightBtn.frame = CGRectMake(self.view.frame.size.width / 2 - 100 / 2, mineQRCode.frame.origin.y + mineQRCode.frame.size.height + 20, 100, introLab.frame.size.height); 271 | NSString *lightName = [@"Resource.bundle" stringByAppendingPathComponent:@"light"]; 272 | NSString *lightonName = [@"Resource.bundle" stringByAppendingPathComponent:@"lighton"]; 273 | 274 | [theLightBtn setImage:[UIImage imageNamed:lightName] forState:UIControlStateNormal]; 275 | [theLightBtn setImage:[UIImage imageNamed:lightonName] forState:UIControlStateSelected]; 276 | [theLightBtn addTarget:self action:@selector(lightOnOrOff:) forControlEvents:UIControlEventTouchUpInside]; 277 | [self.view addSubview:theLightBtn]; 278 | 279 | if (![captureDevice isTorchAvailable]) { 280 | theLightBtn.hidden = YES; 281 | } 282 | // Start 283 | _lineIV = [[UIImageView alloc] initWithFrame:CGRectMake(preView.frame.origin.x, preView.frame.origin.y, preView.frame.size.width, 5)]; 284 | NSString *lineName = [@"Resource.bundle" stringByAppendingPathComponent:@"line"]; 285 | 286 | _lineIV.image = [UIImage imageNamed:lineName]; 287 | [self.view addSubview:_lineIV]; 288 | 289 | 290 | //开始扫描 291 | [_session startRunning]; 292 | } 293 | //手电筒🔦的开和关 294 | - (void)lightOnOrOff:(UIButton *)sender { 295 | sender.selected = !sender.selected; 296 | isLightOn = 1 - isLightOn; 297 | if (isLightOn) { 298 | [self turnOnLed:YES]; 299 | }else { 300 | [self turnOffLed:YES]; 301 | } 302 | } 303 | 304 | //打开手电筒 305 | - (void) turnOnLed:(bool)update { 306 | [captureDevice lockForConfiguration:nil]; 307 | [captureDevice setTorchMode:AVCaptureTorchModeOn]; 308 | [captureDevice unlockForConfiguration]; 309 | } 310 | //关闭手电筒 311 | - (void) turnOffLed:(bool)update { 312 | [captureDevice lockForConfiguration:nil]; 313 | [captureDevice setTorchMode: AVCaptureTorchModeOff]; 314 | [captureDevice unlockForConfiguration]; 315 | } 316 | - (void)showTheQRCodeOfMine:(UIButton *)sender { 317 | NSLog(@"showTheQRCodeOfMine"); 318 | } 319 | - (void)animation { 320 | if (isUp == NO) { 321 | num ++; 322 | _lineIV.frame = CGRectMake(preView.frame.origin.x, preView.frame.origin.y + 2 * num, preView.frame.size.width, 5); 323 | if (2 * num >= preView.frame.size.height) { 324 | isUp = YES; 325 | } 326 | }else { 327 | num --; 328 | _lineIV.frame = CGRectMake(preView.frame.origin.x, preView.frame.origin.y + 2 * num, preView.frame.size.width, 5); 329 | if (num == 0) { 330 | isUp = NO; 331 | } 332 | } 333 | } 334 | 335 | #pragma mark - AVCaptureMetadataOutputObjectsDelegate 336 | - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection 337 | { 338 | //判断是否有数据 339 | if (metadataObjects != nil && [metadataObjects count] > 0) { 340 | 341 | AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0]; 342 | //判断回传的数据类型 343 | if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) { 344 | 345 | NSLog(@"stringValue = %@",metadataObj.stringValue); 346 | [self checkQRcode:metadataObj.stringValue]; 347 | }else{ 348 | NSLog(@"stringValue = %@",metadataObj.stringValue); 349 | [self checkQRcode:metadataObj.stringValue]; 350 | 351 | } 352 | } 353 | [_session stopRunning]; 354 | [self performSelector:@selector(startReading) withObject:nil afterDelay:0.5]; 355 | } 356 | 357 | -(void)startReading{ 358 | [_session startRunning]; 359 | } 360 | -(void)stopReading{ 361 | [_session stopRunning]; 362 | } 363 | /** 364 | * 判断二维码 365 | */ 366 | - (void)checkQRcode:(NSString *)str{ 367 | 368 | if (str.length == 0) { 369 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"找不到二维码" message:@"导入的图片里并没有找到二维码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; 370 | [alert show]; 371 | return; 372 | } 373 | 374 | if ([str hasPrefix:@"http"]) { 375 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; 376 | }else{ 377 | //弹出一个view显示二维码内容 378 | [SVProgressHUD showInfoWithStatus:str]; 379 | } 380 | [SVProgressHUD dismissWithDelay:1.0]; 381 | 382 | } 383 | /** 384 | * 将二维码图片转化为字符 385 | */ 386 | - (NSString *)stringFromFileImage:(UIImage *)img{ 387 | int exifOrientation; 388 | switch (img.imageOrientation) { 389 | case UIImageOrientationUp: 390 | exifOrientation = 1; 391 | break; 392 | case UIImageOrientationDown: 393 | exifOrientation = 3; 394 | break; 395 | case UIImageOrientationLeft: 396 | exifOrientation = 8; 397 | break; 398 | case UIImageOrientationRight: 399 | exifOrientation = 6; 400 | break; 401 | case UIImageOrientationUpMirrored: 402 | exifOrientation = 2; 403 | break; 404 | case UIImageOrientationDownMirrored: 405 | exifOrientation = 4; 406 | break; 407 | case UIImageOrientationLeftMirrored: 408 | exifOrientation = 5; 409 | break; 410 | case UIImageOrientationRightMirrored: 411 | exifOrientation = 7; 412 | break; 413 | default: 414 | break; 415 | } 416 | 417 | NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh }; // TODO: read doc for more tuneups 418 | CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:detectorOptions]; 419 | 420 | NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:img.CGImage]]; 421 | 422 | CIQRCodeFeature * qrStr = (CIQRCodeFeature *)features.firstObject; 423 | //只返回第一个扫描到的二维码 424 | return qrStr.messageString; 425 | } 426 | -(void)dealloc{ 427 | NSLog(@"%@ dealloc",NSStringFromClass(self.class)); 428 | } 429 | - (void)didReceiveMemoryWarning { 430 | [super didReceiveMemoryWarning]; 431 | } 432 | @end 433 | -------------------------------------------------------------------------------- /WMQRCode.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BF7FD04B1DC849D5000CC513 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BF7FD04A1DC849D5000CC513 /* main.m */; }; 11 | BF7FD04E1DC849D5000CC513 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = BF7FD04D1DC849D5000CC513 /* AppDelegate.m */; }; 12 | BF7FD0511DC849D5000CC513 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BF7FD0501DC849D5000CC513 /* ViewController.m */; }; 13 | BF7FD0541DC849D5000CC513 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF7FD0521DC849D5000CC513 /* Main.storyboard */; }; 14 | BF7FD0561DC849D5000CC513 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF7FD0551DC849D5000CC513 /* Assets.xcassets */; }; 15 | BF7FD0591DC849D5000CC513 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF7FD0571DC849D5000CC513 /* LaunchScreen.storyboard */; }; 16 | BF7FD0631DC84A2B000CC513 /* WMQRCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BF7FD0621DC84A2B000CC513 /* WMQRCodeViewController.m */; }; 17 | BFF8DCE21DC8702D0047494E /* SVIndefiniteAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = BFF8DCDB1DC8702D0047494E /* SVIndefiniteAnimatedView.m */; }; 18 | BFF8DCE31DC8702D0047494E /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BFF8DCDD1DC8702D0047494E /* SVProgressHUD.bundle */; }; 19 | BFF8DCE41DC8702D0047494E /* SVProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = BFF8DCDF1DC8702D0047494E /* SVProgressHUD.m */; }; 20 | BFF8DCE51DC8702D0047494E /* SVRadialGradientLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = BFF8DCE11DC8702D0047494E /* SVRadialGradientLayer.m */; }; 21 | BFF8DCE81DC87A580047494E /* Resource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = BFF8DCE71DC87A580047494E /* Resource.bundle */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | BF7FD0461DC849D5000CC513 /* WMQRCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WMQRCode.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | BF7FD04A1DC849D5000CC513 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 27 | BF7FD04C1DC849D5000CC513 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 28 | BF7FD04D1DC849D5000CC513 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 29 | BF7FD04F1DC849D5000CC513 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 30 | BF7FD0501DC849D5000CC513 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 31 | BF7FD0531DC849D5000CC513 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 32 | BF7FD0551DC849D5000CC513 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 33 | BF7FD0581DC849D5000CC513 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 34 | BF7FD05A1DC849D5000CC513 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | BF7FD0611DC84A2B000CC513 /* WMQRCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMQRCodeViewController.h; sourceTree = ""; }; 36 | BF7FD0621DC84A2B000CC513 /* WMQRCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMQRCodeViewController.m; sourceTree = ""; }; 37 | BFF8DCDA1DC8702D0047494E /* SVIndefiniteAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVIndefiniteAnimatedView.h; sourceTree = ""; }; 38 | BFF8DCDB1DC8702D0047494E /* SVIndefiniteAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVIndefiniteAnimatedView.m; sourceTree = ""; }; 39 | BFF8DCDC1DC8702D0047494E /* SVProgressHUD-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SVProgressHUD-Prefix.pch"; sourceTree = ""; }; 40 | BFF8DCDD1DC8702D0047494E /* SVProgressHUD.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SVProgressHUD.bundle; sourceTree = ""; }; 41 | BFF8DCDE1DC8702D0047494E /* SVProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressHUD.h; sourceTree = ""; }; 42 | BFF8DCDF1DC8702D0047494E /* SVProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVProgressHUD.m; sourceTree = ""; }; 43 | BFF8DCE01DC8702D0047494E /* SVRadialGradientLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVRadialGradientLayer.h; sourceTree = ""; }; 44 | BFF8DCE11DC8702D0047494E /* SVRadialGradientLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVRadialGradientLayer.m; sourceTree = ""; }; 45 | BFF8DCE71DC87A580047494E /* Resource.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Resource.bundle; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | BF7FD0431DC849D5000CC513 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | BF7FD03D1DC849D5000CC513 = { 60 | isa = PBXGroup; 61 | children = ( 62 | BF7FD0481DC849D5000CC513 /* WMQRCode */, 63 | BF7FD0471DC849D5000CC513 /* Products */, 64 | ); 65 | sourceTree = ""; 66 | }; 67 | BF7FD0471DC849D5000CC513 /* Products */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | BF7FD0461DC849D5000CC513 /* WMQRCode.app */, 71 | ); 72 | name = Products; 73 | sourceTree = ""; 74 | }; 75 | BF7FD0481DC849D5000CC513 /* WMQRCode */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | BF7FD04C1DC849D5000CC513 /* AppDelegate.h */, 79 | BF7FD04D1DC849D5000CC513 /* AppDelegate.m */, 80 | BF7FD04F1DC849D5000CC513 /* ViewController.h */, 81 | BF7FD0501DC849D5000CC513 /* ViewController.m */, 82 | BFF8DCD91DC8702D0047494E /* SVProgressHUD */, 83 | BF7FD0521DC849D5000CC513 /* Main.storyboard */, 84 | BF7FD0601DC84A0C000CC513 /* WMQRCode */, 85 | BF7FD0551DC849D5000CC513 /* Assets.xcassets */, 86 | BF7FD0571DC849D5000CC513 /* LaunchScreen.storyboard */, 87 | BF7FD05A1DC849D5000CC513 /* Info.plist */, 88 | BF7FD0491DC849D5000CC513 /* Supporting Files */, 89 | ); 90 | path = WMQRCode; 91 | sourceTree = ""; 92 | }; 93 | BF7FD0491DC849D5000CC513 /* Supporting Files */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | BF7FD04A1DC849D5000CC513 /* main.m */, 97 | ); 98 | name = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | BF7FD0601DC84A0C000CC513 /* WMQRCode */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | BF7FD0611DC84A2B000CC513 /* WMQRCodeViewController.h */, 105 | BF7FD0621DC84A2B000CC513 /* WMQRCodeViewController.m */, 106 | BFF8DCE71DC87A580047494E /* Resource.bundle */, 107 | ); 108 | path = WMQRCode; 109 | sourceTree = ""; 110 | }; 111 | BFF8DCD91DC8702D0047494E /* SVProgressHUD */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | BFF8DCDA1DC8702D0047494E /* SVIndefiniteAnimatedView.h */, 115 | BFF8DCDB1DC8702D0047494E /* SVIndefiniteAnimatedView.m */, 116 | BFF8DCDC1DC8702D0047494E /* SVProgressHUD-Prefix.pch */, 117 | BFF8DCDD1DC8702D0047494E /* SVProgressHUD.bundle */, 118 | BFF8DCDE1DC8702D0047494E /* SVProgressHUD.h */, 119 | BFF8DCDF1DC8702D0047494E /* SVProgressHUD.m */, 120 | BFF8DCE01DC8702D0047494E /* SVRadialGradientLayer.h */, 121 | BFF8DCE11DC8702D0047494E /* SVRadialGradientLayer.m */, 122 | ); 123 | path = SVProgressHUD; 124 | sourceTree = ""; 125 | }; 126 | /* End PBXGroup section */ 127 | 128 | /* Begin PBXNativeTarget section */ 129 | BF7FD0451DC849D5000CC513 /* WMQRCode */ = { 130 | isa = PBXNativeTarget; 131 | buildConfigurationList = BF7FD05D1DC849D5000CC513 /* Build configuration list for PBXNativeTarget "WMQRCode" */; 132 | buildPhases = ( 133 | BF7FD0421DC849D5000CC513 /* Sources */, 134 | BF7FD0431DC849D5000CC513 /* Frameworks */, 135 | BF7FD0441DC849D5000CC513 /* Resources */, 136 | ); 137 | buildRules = ( 138 | ); 139 | dependencies = ( 140 | ); 141 | name = WMQRCode; 142 | productName = WMQRCode; 143 | productReference = BF7FD0461DC849D5000CC513 /* WMQRCode.app */; 144 | productType = "com.apple.product-type.application"; 145 | }; 146 | /* End PBXNativeTarget section */ 147 | 148 | /* Begin PBXProject section */ 149 | BF7FD03E1DC849D5000CC513 /* Project object */ = { 150 | isa = PBXProject; 151 | attributes = { 152 | LastUpgradeCheck = 0800; 153 | ORGANIZATIONNAME = "郑文明"; 154 | TargetAttributes = { 155 | BF7FD0451DC849D5000CC513 = { 156 | CreatedOnToolsVersion = 8.0; 157 | DevelopmentTeam = 58RLM4UFK5; 158 | ProvisioningStyle = Automatic; 159 | }; 160 | }; 161 | }; 162 | buildConfigurationList = BF7FD0411DC849D5000CC513 /* Build configuration list for PBXProject "WMQRCode" */; 163 | compatibilityVersion = "Xcode 3.2"; 164 | developmentRegion = English; 165 | hasScannedForEncodings = 0; 166 | knownRegions = ( 167 | English, 168 | en, 169 | Base, 170 | ); 171 | mainGroup = BF7FD03D1DC849D5000CC513; 172 | productRefGroup = BF7FD0471DC849D5000CC513 /* Products */; 173 | projectDirPath = ""; 174 | projectRoot = ""; 175 | targets = ( 176 | BF7FD0451DC849D5000CC513 /* WMQRCode */, 177 | ); 178 | }; 179 | /* End PBXProject section */ 180 | 181 | /* Begin PBXResourcesBuildPhase section */ 182 | BF7FD0441DC849D5000CC513 /* Resources */ = { 183 | isa = PBXResourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | BF7FD0591DC849D5000CC513 /* LaunchScreen.storyboard in Resources */, 187 | BF7FD0561DC849D5000CC513 /* Assets.xcassets in Resources */, 188 | BF7FD0541DC849D5000CC513 /* Main.storyboard in Resources */, 189 | BFF8DCE31DC8702D0047494E /* SVProgressHUD.bundle in Resources */, 190 | BFF8DCE81DC87A580047494E /* Resource.bundle in Resources */, 191 | ); 192 | runOnlyForDeploymentPostprocessing = 0; 193 | }; 194 | /* End PBXResourcesBuildPhase section */ 195 | 196 | /* Begin PBXSourcesBuildPhase section */ 197 | BF7FD0421DC849D5000CC513 /* Sources */ = { 198 | isa = PBXSourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | BFF8DCE51DC8702D0047494E /* SVRadialGradientLayer.m in Sources */, 202 | BFF8DCE21DC8702D0047494E /* SVIndefiniteAnimatedView.m in Sources */, 203 | BF7FD0631DC84A2B000CC513 /* WMQRCodeViewController.m in Sources */, 204 | BF7FD0511DC849D5000CC513 /* ViewController.m in Sources */, 205 | BF7FD04E1DC849D5000CC513 /* AppDelegate.m in Sources */, 206 | BF7FD04B1DC849D5000CC513 /* main.m in Sources */, 207 | BFF8DCE41DC8702D0047494E /* SVProgressHUD.m in Sources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | /* End PBXSourcesBuildPhase section */ 212 | 213 | /* Begin PBXVariantGroup section */ 214 | BF7FD0521DC849D5000CC513 /* Main.storyboard */ = { 215 | isa = PBXVariantGroup; 216 | children = ( 217 | BF7FD0531DC849D5000CC513 /* Base */, 218 | ); 219 | name = Main.storyboard; 220 | sourceTree = ""; 221 | }; 222 | BF7FD0571DC849D5000CC513 /* LaunchScreen.storyboard */ = { 223 | isa = PBXVariantGroup; 224 | children = ( 225 | BF7FD0581DC849D5000CC513 /* Base */, 226 | ); 227 | name = LaunchScreen.storyboard; 228 | sourceTree = ""; 229 | }; 230 | /* End PBXVariantGroup section */ 231 | 232 | /* Begin XCBuildConfiguration section */ 233 | BF7FD05B1DC849D5000CC513 /* Debug */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 239 | CLANG_CXX_LIBRARY = "libc++"; 240 | CLANG_ENABLE_MODULES = YES; 241 | CLANG_ENABLE_OBJC_ARC = YES; 242 | CLANG_WARN_BOOL_CONVERSION = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 245 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 246 | CLANG_WARN_EMPTY_BODY = YES; 247 | CLANG_WARN_ENUM_CONVERSION = YES; 248 | CLANG_WARN_INFINITE_RECURSION = YES; 249 | CLANG_WARN_INT_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 252 | CLANG_WARN_UNREACHABLE_CODE = YES; 253 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 254 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 255 | COPY_PHASE_STRIP = NO; 256 | DEBUG_INFORMATION_FORMAT = dwarf; 257 | ENABLE_STRICT_OBJC_MSGSEND = YES; 258 | ENABLE_TESTABILITY = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu99; 260 | GCC_DYNAMIC_NO_PIC = NO; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_OPTIMIZATION_LEVEL = 0; 263 | GCC_PREPROCESSOR_DEFINITIONS = ( 264 | "DEBUG=1", 265 | "$(inherited)", 266 | ); 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 274 | MTL_ENABLE_DEBUG_INFO = YES; 275 | ONLY_ACTIVE_ARCH = YES; 276 | SDKROOT = iphoneos; 277 | }; 278 | name = Debug; 279 | }; 280 | BF7FD05C1DC849D5000CC513 /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_SEARCH_USER_PATHS = NO; 284 | CLANG_ANALYZER_NONNULL = YES; 285 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 286 | CLANG_CXX_LIBRARY = "libc++"; 287 | CLANG_ENABLE_MODULES = YES; 288 | CLANG_ENABLE_OBJC_ARC = YES; 289 | CLANG_WARN_BOOL_CONVERSION = YES; 290 | CLANG_WARN_CONSTANT_CONVERSION = YES; 291 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 292 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 293 | CLANG_WARN_EMPTY_BODY = YES; 294 | CLANG_WARN_ENUM_CONVERSION = YES; 295 | CLANG_WARN_INFINITE_RECURSION = YES; 296 | CLANG_WARN_INT_CONVERSION = YES; 297 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 298 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 299 | CLANG_WARN_UNREACHABLE_CODE = YES; 300 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 301 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 302 | COPY_PHASE_STRIP = NO; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu99; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | SDKROOT = iphoneos; 317 | VALIDATE_PRODUCT = YES; 318 | }; 319 | name = Release; 320 | }; 321 | BF7FD05E1DC849D5000CC513 /* Debug */ = { 322 | isa = XCBuildConfiguration; 323 | buildSettings = { 324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 325 | DEVELOPMENT_TEAM = 58RLM4UFK5; 326 | INFOPLIST_FILE = WMQRCode/Info.plist; 327 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 328 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 329 | PRODUCT_BUNDLE_IDENTIFIER = aixin.WMQRCode; 330 | PRODUCT_NAME = "$(TARGET_NAME)"; 331 | }; 332 | name = Debug; 333 | }; 334 | BF7FD05F1DC849D5000CC513 /* Release */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 338 | DEVELOPMENT_TEAM = 58RLM4UFK5; 339 | INFOPLIST_FILE = WMQRCode/Info.plist; 340 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 341 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 342 | PRODUCT_BUNDLE_IDENTIFIER = aixin.WMQRCode; 343 | PRODUCT_NAME = "$(TARGET_NAME)"; 344 | }; 345 | name = Release; 346 | }; 347 | /* End XCBuildConfiguration section */ 348 | 349 | /* Begin XCConfigurationList section */ 350 | BF7FD0411DC849D5000CC513 /* Build configuration list for PBXProject "WMQRCode" */ = { 351 | isa = XCConfigurationList; 352 | buildConfigurations = ( 353 | BF7FD05B1DC849D5000CC513 /* Debug */, 354 | BF7FD05C1DC849D5000CC513 /* Release */, 355 | ); 356 | defaultConfigurationIsVisible = 0; 357 | defaultConfigurationName = Release; 358 | }; 359 | BF7FD05D1DC849D5000CC513 /* Build configuration list for PBXNativeTarget "WMQRCode" */ = { 360 | isa = XCConfigurationList; 361 | buildConfigurations = ( 362 | BF7FD05E1DC849D5000CC513 /* Debug */, 363 | BF7FD05F1DC849D5000CC513 /* Release */, 364 | ); 365 | defaultConfigurationIsVisible = 0; 366 | defaultConfigurationName = Release; 367 | }; 368 | /* End XCConfigurationList section */ 369 | }; 370 | rootObject = BF7FD03E1DC849D5000CC513 /* Project object */; 371 | } 372 | -------------------------------------------------------------------------------- /WMQRCode/SVProgressHUD/SVProgressHUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressHUD.h 3 | // SVProgressHUD, https://github.com/TransitApp/SVProgressHUD 4 | // 5 | // Copyright (c) 2011-2014 Sam Vermette and contributors. All rights reserved. 6 | // 7 | 8 | #if !__has_feature(objc_arc) 9 | #error SVProgressHUD is ARC only. Either turn on ARC for the project or use -fobjc-arc flag 10 | #endif 11 | 12 | #import "SVProgressHUD.h" 13 | #import "SVIndefiniteAnimatedView.h" 14 | #import "SVRadialGradientLayer.h" 15 | 16 | NSString * const SVProgressHUDDidReceiveTouchEventNotification = @"SVProgressHUDDidReceiveTouchEventNotification"; 17 | NSString * const SVProgressHUDDidTouchDownInsideNotification = @"SVProgressHUDDidTouchDownInsideNotification"; 18 | NSString * const SVProgressHUDWillDisappearNotification = @"SVProgressHUDWillDisappearNotification"; 19 | NSString * const SVProgressHUDDidDisappearNotification = @"SVProgressHUDDidDisappearNotification"; 20 | NSString * const SVProgressHUDWillAppearNotification = @"SVProgressHUDWillAppearNotification"; 21 | NSString * const SVProgressHUDDidAppearNotification = @"SVProgressHUDDidAppearNotification"; 22 | 23 | NSString * const SVProgressHUDStatusUserInfoKey = @"SVProgressHUDStatusUserInfoKey"; 24 | 25 | static const CGFloat SVProgressHUDParallaxDepthPoints = 10; 26 | static const CGFloat SVProgressHUDUndefinedProgress = -1; 27 | 28 | @interface SVProgressHUD () 29 | 30 | @property (nonatomic, strong, readonly) NSTimer *fadeOutTimer; 31 | @property (nonatomic, readonly, getter = isClear) BOOL clear; 32 | 33 | @property (nonatomic, strong) UIControl *overlayView; 34 | @property (nonatomic, strong) UIView *hudView; 35 | 36 | @property (nonatomic, strong) UILabel *stringLabel; 37 | @property (nonatomic, strong) UIImageView *imageView; 38 | @property (nonatomic, strong) UIView *indefiniteAnimatedView; 39 | @property (nonatomic, strong) CALayer *backgroundLayer; 40 | 41 | @property (nonatomic, readwrite) CGFloat progress; 42 | @property (nonatomic, readwrite) NSUInteger activityCount; 43 | @property (nonatomic, strong) CAShapeLayer *backgroundRingLayer; 44 | @property (nonatomic, strong) CAShapeLayer *ringLayer; 45 | 46 | @property (nonatomic, readonly) CGFloat visibleKeyboardHeight; 47 | 48 | - (void)updateHUDFrame; 49 | - (void)updateMask; 50 | - (void)updateBlurBounds; 51 | #if TARGET_OS_IOS 52 | - (void)updateMotionEffectForOrientation:(UIInterfaceOrientation)orientation; 53 | #endif 54 | - (void)updateMotionEffectForXMotionEffectType:(UIInterpolatingMotionEffectType)xMotionEffectType yMotionEffectType:(UIInterpolatingMotionEffectType)yMotionEffectType; 55 | 56 | - (void)setStatus:(NSString*)string; 57 | - (void)setFadeOutTimer:(NSTimer*)newTimer; 58 | 59 | - (void)registerNotifications; 60 | - (NSDictionary*)notificationUserInfo; 61 | 62 | - (void)positionHUD:(NSNotification*)notification; 63 | - (void)moveToPoint:(CGPoint)newCenter rotateAngle:(CGFloat)angle; 64 | 65 | - (void)overlayViewDidReceiveTouchEvent:(id)sender forEvent:(UIEvent*)event; 66 | 67 | - (void)showProgress:(float)progress status:(NSString*)string; 68 | - (void)showImage:(UIImage*)image status:(NSString*)status duration:(NSTimeInterval)duration; 69 | 70 | - (void)dismissWithDelay:(NSTimeInterval)delay; 71 | - (void)dismiss; 72 | 73 | - (UIActivityIndicatorView *)createActivityIndicatorView; 74 | - (SVIndefiniteAnimatedView *)createIndefiniteAnimatedView; 75 | - (UIView *)indefiniteAnimatedView; 76 | - (CAShapeLayer*)ringLayer; 77 | - (CAShapeLayer*)backgroundRingLayer; 78 | - (void)cancelRingLayerAnimation; 79 | - (CAShapeLayer*)createRingLayerWithCenter:(CGPoint)center radius:(CGFloat)radius; 80 | 81 | - (UIColor*)foregroundColorForStyle; 82 | - (UIColor*)backgroundColorForStyle; 83 | - (UIImage*)image:(UIImage*)image withTintColor:(UIColor*)color; 84 | 85 | @end 86 | 87 | 88 | @implementation SVProgressHUD { 89 | BOOL _isInitializing; 90 | } 91 | 92 | + (SVProgressHUD*)sharedView{ 93 | static dispatch_once_t once; 94 | 95 | static SVProgressHUD *sharedView; 96 | #if !defined(SV_APP_EXTENSIONS) 97 | dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[[[UIApplication sharedApplication] delegate] window].bounds]; }); 98 | #else 99 | dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; }); 100 | #endif 101 | return sharedView; 102 | } 103 | 104 | 105 | #pragma mark - Setters 106 | 107 | + (void)setStatus:(NSString*)status{ 108 | [[self sharedView] setStatus:status]; 109 | } 110 | 111 | + (void)setDefaultStyle:(SVProgressHUDStyle)style{ 112 | [self sharedView].defaultStyle = style; 113 | } 114 | 115 | + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType{ 116 | [self sharedView].defaultMaskType = maskType; 117 | } 118 | 119 | + (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type { 120 | [self sharedView].defaultAnimationType = type; 121 | // Reset indefiniteAnimatedView so it gets recreated with the new style 122 | [self sharedView].indefiniteAnimatedView = nil; 123 | } 124 | 125 | + (void)setMinimumSize:(CGSize)minimumSize{ 126 | [self sharedView].minimumSize = minimumSize; 127 | } 128 | 129 | + (void)setRingThickness:(CGFloat)ringThickness{ 130 | [self sharedView].ringThickness = ringThickness; 131 | } 132 | 133 | + (void)setRingRadius:(CGFloat)radius{ 134 | [self sharedView].ringRadius = radius; 135 | } 136 | 137 | + (void)setRingNoTextRadius:(CGFloat)radius{ 138 | [self sharedView].ringNoTextRadius = radius; 139 | } 140 | 141 | + (void)setCornerRadius:(CGFloat)cornerRadius{ 142 | [self sharedView].cornerRadius = cornerRadius; 143 | } 144 | 145 | + (void)setFont:(UIFont*)font{ 146 | [self sharedView].font = font; 147 | } 148 | 149 | + (void)setForegroundColor:(UIColor*)color{ 150 | [self sharedView].foregroundColor = color; 151 | } 152 | 153 | + (void)setBackgroundColor:(UIColor*)color{ 154 | [self sharedView].backgroundColor = color; 155 | } 156 | 157 | + (void)setInfoImage:(UIImage*)image{ 158 | [self sharedView].infoImage = image; 159 | } 160 | 161 | + (void)setSuccessImage:(UIImage *)image { 162 | [self sharedView].successImage = image; 163 | } 164 | 165 | + (void)setErrorImage:(UIImage *)image { 166 | [self sharedView].errorImage = image; 167 | } 168 | 169 | + (void)setViewForExtension:(UIView *)view{ 170 | [self sharedView].viewForExtension = view; 171 | } 172 | 173 | + (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval { 174 | [self sharedView].minimumDismissTimeInterval = interval; 175 | } 176 | 177 | 178 | #pragma mark - Show Methods 179 | 180 | + (void)show{ 181 | [self showWithStatus:nil]; 182 | } 183 | 184 | + (void)showWithMaskType:(SVProgressHUDMaskType)maskType{ 185 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 186 | [self setDefaultMaskType:maskType]; 187 | [self show]; 188 | [self setDefaultMaskType:existingMaskType]; 189 | } 190 | 191 | + (void)showWithStatus:(NSString*)status{ 192 | [self sharedView]; 193 | [self showProgress:SVProgressHUDUndefinedProgress status:status]; 194 | } 195 | 196 | + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 197 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 198 | [self setDefaultMaskType:maskType]; 199 | [self showWithStatus:status]; 200 | [self setDefaultMaskType:existingMaskType]; 201 | } 202 | 203 | + (void)showProgress:(float)progress{ 204 | [self showProgress:progress status:nil]; 205 | } 206 | 207 | + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType{ 208 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 209 | [self setDefaultMaskType:maskType]; 210 | [self showProgress:progress]; 211 | [self setDefaultMaskType:existingMaskType]; 212 | } 213 | 214 | + (void)showProgress:(float)progress status:(NSString*)status{ 215 | [[self sharedView] showProgress:progress status:status]; 216 | } 217 | 218 | + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 219 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 220 | [self setDefaultMaskType:maskType]; 221 | [self showProgress:progress status:status]; 222 | [self setDefaultMaskType:existingMaskType]; 223 | } 224 | 225 | #pragma mark - Show, then automatically dismiss methods 226 | 227 | + (void)showInfoWithStatus:(NSString*)status{ 228 | [self showImage:[self sharedView].infoImage status:status]; 229 | } 230 | 231 | + (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 232 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 233 | [self setDefaultMaskType:maskType]; 234 | [self showInfoWithStatus:status]; 235 | [self setDefaultMaskType:existingMaskType]; 236 | } 237 | 238 | + (void)showSuccessWithStatus:(NSString*)status{ 239 | [self showImage:[self sharedView].successImage status:status]; 240 | } 241 | 242 | + (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 243 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 244 | [self setDefaultMaskType:maskType]; 245 | [self showSuccessWithStatus:status]; 246 | [self setDefaultMaskType:existingMaskType]; 247 | } 248 | 249 | + (void)showErrorWithStatus:(NSString*)status{ 250 | [self showImage:[self sharedView].errorImage status:status]; 251 | } 252 | 253 | + (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 254 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 255 | [self setDefaultMaskType:maskType]; 256 | [self showErrorWithStatus:status]; 257 | [self setDefaultMaskType:existingMaskType]; 258 | } 259 | 260 | + (void)showImage:(UIImage*)image status:(NSString*)status{ 261 | NSTimeInterval displayInterval = [self displayDurationForString:status]; 262 | [[self sharedView] showImage:image status:status duration:displayInterval]; 263 | } 264 | 265 | + (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType{ 266 | SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType; 267 | [self setDefaultMaskType:maskType]; 268 | [self showImage:image status:status]; 269 | [self setDefaultMaskType:existingMaskType]; 270 | } 271 | 272 | 273 | #pragma mark - Dismiss Methods 274 | 275 | + (void)popActivity{ 276 | if([self sharedView].activityCount > 0){ 277 | [self sharedView].activityCount--; 278 | } 279 | if([self sharedView].activityCount == 0){ 280 | [[self sharedView] dismiss]; 281 | } 282 | } 283 | 284 | + (void)dismissWithDelay:(NSTimeInterval)delay{ 285 | if([self isVisible]){ 286 | [[self sharedView] dismissWithDelay:delay]; 287 | } 288 | } 289 | 290 | + (void)dismiss{ 291 | [self dismissWithDelay:0]; 292 | } 293 | 294 | 295 | #pragma mark - Offset 296 | 297 | + (void)setOffsetFromCenter:(UIOffset)offset{ 298 | [self sharedView].offsetFromCenter = offset; 299 | } 300 | 301 | + (void)resetOffsetFromCenter{ 302 | [self setOffsetFromCenter:UIOffsetZero]; 303 | } 304 | 305 | 306 | #pragma mark - Instance Methods 307 | 308 | - (instancetype)initWithFrame:(CGRect)frame{ 309 | if((self = [super initWithFrame:frame])){ 310 | _isInitializing = YES; 311 | 312 | self.userInteractionEnabled = NO; 313 | _backgroundColor = [UIColor clearColor]; 314 | _foregroundColor = [UIColor blackColor]; 315 | self.alpha = 0.0f; 316 | self.activityCount = 0; 317 | 318 | _defaultMaskType = SVProgressHUDMaskTypeNone; 319 | _defaultStyle = SVProgressHUDStyleLight; 320 | _defaultAnimationType = SVProgressHUDAnimationTypeFlat; 321 | 322 | // add accessibility support 323 | self.accessibilityIdentifier = @"SVProgressHUD"; 324 | self.accessibilityLabel = @"SVProgressHUD"; 325 | self.isAccessibilityElement = YES; 326 | 327 | if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) { 328 | _font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]; 329 | } else { 330 | _font = [UIFont systemFontOfSize:14.0f]; 331 | } 332 | 333 | NSBundle *bundle = [NSBundle bundleForClass:[self class]]; 334 | NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"]; 335 | NSBundle *imageBundle = [NSBundle bundleWithURL:url]; 336 | 337 | UIImage* infoImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"info" ofType:@"png"]]; 338 | UIImage* successImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"success" ofType:@"png"]]; 339 | UIImage* errorImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"error" ofType:@"png"]]; 340 | 341 | if ([[UIImage class] instancesRespondToSelector:@selector(imageWithRenderingMode:)]) { 342 | _infoImage = [infoImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 343 | _successImage = [successImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 344 | _errorImage = [errorImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 345 | } else { 346 | _infoImage = infoImage; 347 | _successImage = successImage; 348 | _errorImage = errorImage; 349 | } 350 | 351 | _ringThickness = 2; 352 | _ringRadius = 18; 353 | _ringNoTextRadius = 24; 354 | 355 | _cornerRadius = 14; 356 | 357 | _minimumDismissTimeInterval = 5.0f; 358 | 359 | _isInitializing = NO; 360 | } 361 | return self; 362 | } 363 | 364 | - (void)updateHUDFrame{ 365 | CGFloat hudWidth = 100.0f; 366 | CGFloat hudHeight = 100.0f; 367 | CGFloat stringHeightBuffer = 20.0f; 368 | CGFloat stringAndContentHeightBuffer = 80.0f; 369 | CGRect labelRect = CGRectZero; 370 | 371 | // Check if an image or progress ring is displayed 372 | BOOL imageUsed = (self.imageView.image) || (self.imageView.hidden); 373 | BOOL progressUsed = (self.progress != SVProgressHUDUndefinedProgress) && (self.progress >= 0.0f); 374 | 375 | // Calculate and apply sizes 376 | NSString *string = self.stringLabel.text; 377 | if(string){ 378 | CGSize constraintSize = CGSizeMake(200.0f, 300.0f); 379 | CGRect stringRect; 380 | if([string respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]){ 381 | stringRect = [string boundingRectWithSize:constraintSize 382 | options:(NSStringDrawingOptions)(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin) 383 | attributes:@{NSFontAttributeName: self.stringLabel.font} 384 | context:NULL]; 385 | } else{ 386 | CGSize stringSize; 387 | if([string respondsToSelector:@selector(sizeWithAttributes:)]){ 388 | stringSize = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:self.stringLabel.font.fontName size:self.stringLabel.font.pointSize]}]; 389 | } else{ 390 | #if TARGET_OS_IOS 391 | #pragma clang diagnostic push 392 | #pragma clang diagnostic ignored "-Wdeprecated" 393 | stringSize = [string sizeWithFont:self.stringLabel.font constrainedToSize:CGSizeMake(200.0f, 300.0f)]; 394 | #pragma clang diagnostic pop 395 | #endif 396 | } 397 | stringRect = CGRectMake(0.0f, 0.0f, stringSize.width, stringSize.height); 398 | } 399 | 400 | CGFloat stringWidth = stringRect.size.width; 401 | CGFloat stringHeight = ceilf(CGRectGetHeight(stringRect)); 402 | 403 | if(imageUsed || progressUsed){ 404 | hudHeight = stringAndContentHeightBuffer + stringHeight; 405 | } else{ 406 | hudHeight = stringHeightBuffer + stringHeight; 407 | } 408 | if(stringWidth > hudWidth){ 409 | hudWidth = ceilf(stringWidth/2)*2; 410 | } 411 | CGFloat labelRectY = (imageUsed || progressUsed) ? 68.0f : 9.0f; 412 | if(hudHeight > 100.0f){ 413 | labelRect = CGRectMake(12.0f, labelRectY, hudWidth, stringHeight); 414 | hudWidth += 24.0f; 415 | } else{ 416 | hudWidth += 24.0f; 417 | labelRect = CGRectMake(0.0f, labelRectY, hudWidth, stringHeight); 418 | } 419 | } 420 | 421 | // Update values on subviews 422 | self.hudView.bounds = CGRectMake(0.0f, 0.0f, MAX(self.minimumSize.width, hudWidth), MAX(self.minimumSize.height, hudHeight)); 423 | labelRect.size.width += MAX(0, self.minimumSize.width - hudWidth); 424 | [self updateBlurBounds]; 425 | 426 | if(string){ 427 | self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, 36.0f); 428 | } else{ 429 | self.imageView.center = CGPointMake(CGRectGetWidth(self.hudView.bounds)/2, CGRectGetHeight(self.hudView.bounds)/2); 430 | } 431 | 432 | self.stringLabel.hidden = NO; 433 | self.stringLabel.frame = labelRect; 434 | 435 | // Animate value update 436 | [CATransaction begin]; 437 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 438 | 439 | if(string) { 440 | if(self.defaultAnimationType == SVProgressHUDAnimationTypeFlat) { 441 | SVIndefiniteAnimatedView *indefiniteAnimationView = (SVIndefiniteAnimatedView *)self.indefiniteAnimatedView; 442 | indefiniteAnimationView.radius = self.ringRadius; 443 | [indefiniteAnimationView sizeToFit]; 444 | } 445 | 446 | CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36.0f); 447 | self.indefiniteAnimatedView.center = center; 448 | 449 | if(self.progress != SVProgressHUDUndefinedProgress){ 450 | self.backgroundRingLayer.position = self.ringLayer.position = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), 36.0f); 451 | } 452 | } else { 453 | if(self.defaultAnimationType == SVProgressHUDAnimationTypeFlat) { 454 | SVIndefiniteAnimatedView *indefiniteAnimationView = (SVIndefiniteAnimatedView *)self.indefiniteAnimatedView; 455 | indefiniteAnimationView.radius = self.ringNoTextRadius; 456 | [indefiniteAnimationView sizeToFit]; 457 | } 458 | 459 | CGPoint center = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2); 460 | self.indefiniteAnimatedView.center = center; 461 | 462 | if(self.progress != SVProgressHUDUndefinedProgress){ 463 | self.backgroundRingLayer.position = self.ringLayer.position = CGPointMake((CGRectGetWidth(self.hudView.bounds)/2), CGRectGetHeight(self.hudView.bounds)/2); 464 | } 465 | } 466 | 467 | [CATransaction commit]; 468 | } 469 | 470 | - (void)updateMask{ 471 | if(self.backgroundLayer){ 472 | [self.backgroundLayer removeFromSuperlayer]; 473 | self.backgroundLayer = nil; 474 | } 475 | switch (self.defaultMaskType){ 476 | case SVProgressHUDMaskTypeBlack:{ 477 | 478 | self.backgroundLayer = [CALayer layer]; 479 | self.backgroundLayer.frame = self.bounds; 480 | self.backgroundLayer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5].CGColor; 481 | [self.backgroundLayer setNeedsDisplay]; 482 | 483 | [self.layer insertSublayer:self.backgroundLayer atIndex:0]; 484 | break; 485 | } 486 | 487 | case SVProgressHUDMaskTypeGradient:{ 488 | SVRadialGradientLayer *layer = [SVRadialGradientLayer layer]; 489 | self.backgroundLayer = layer; 490 | self.backgroundLayer.frame = self.bounds; 491 | CGPoint gradientCenter = self.center; 492 | gradientCenter.y = (self.bounds.size.height - self.visibleKeyboardHeight) / 2; 493 | layer.gradientCenter = gradientCenter; 494 | [self.backgroundLayer setNeedsDisplay]; 495 | 496 | [self.layer insertSublayer:self.backgroundLayer atIndex:0]; 497 | break; 498 | } 499 | default: 500 | break; 501 | } 502 | } 503 | 504 | - (void)updateBlurBounds{ 505 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 506 | if(NSClassFromString(@"UIBlurEffect") && self.defaultStyle != SVProgressHUDStyleCustom){ 507 | // Remove background color, else the effect would not work 508 | self.hudView.backgroundColor = [UIColor clearColor]; 509 | 510 | // Remove any old instances of UIVisualEffectViews 511 | for (UIView *subview in self.hudView.subviews){ 512 | if([subview isKindOfClass:[UIVisualEffectView class]]){ 513 | [subview removeFromSuperview]; 514 | } 515 | } 516 | 517 | if(self.backgroundColor != [UIColor clearColor]){ 518 | // Create blur effect 519 | UIBlurEffectStyle blurEffectStyle = self.defaultStyle == SVProgressHUDStyleDark ? UIBlurEffectStyleDark : UIBlurEffectStyleLight; 520 | UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:blurEffectStyle]; 521 | UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 522 | blurEffectView.autoresizingMask = self.hudView.autoresizingMask; 523 | blurEffectView.frame = self.hudView.bounds; 524 | 525 | // Add vibrancy to the blur effect to make it more vivid 526 | UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect]; 527 | UIVisualEffectView *vibrancyEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect]; 528 | vibrancyEffectView.autoresizingMask = blurEffectView.autoresizingMask; 529 | vibrancyEffectView.bounds = blurEffectView.bounds; 530 | [blurEffectView.contentView addSubview:vibrancyEffectView]; 531 | 532 | [self.hudView insertSubview:blurEffectView atIndex:0]; 533 | } 534 | } 535 | #endif 536 | } 537 | 538 | #if TARGET_OS_IOS 539 | - (void)updateMotionEffectForOrientation:(UIInterfaceOrientation)orientation{ 540 | UIInterpolatingMotionEffectType xMotionEffectType = UIInterfaceOrientationIsPortrait(orientation) ? UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis : UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis; 541 | UIInterpolatingMotionEffectType yMotionEffectType = UIInterfaceOrientationIsPortrait(orientation) ? UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis : UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis; 542 | [self updateMotionEffectForXMotionEffectType:xMotionEffectType yMotionEffectType:yMotionEffectType]; 543 | } 544 | #endif 545 | 546 | - (void)updateMotionEffectForXMotionEffectType:(UIInterpolatingMotionEffectType)xMotionEffectType yMotionEffectType:(UIInterpolatingMotionEffectType)yMotionEffectType{ 547 | if([_hudView respondsToSelector:@selector(addMotionEffect:)]){ 548 | UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:xMotionEffectType]; 549 | effectX.minimumRelativeValue = @(-SVProgressHUDParallaxDepthPoints); 550 | effectX.maximumRelativeValue = @(SVProgressHUDParallaxDepthPoints); 551 | 552 | UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:yMotionEffectType]; 553 | effectY.minimumRelativeValue = @(-SVProgressHUDParallaxDepthPoints); 554 | effectY.maximumRelativeValue = @(SVProgressHUDParallaxDepthPoints); 555 | 556 | UIMotionEffectGroup *effectGroup = [[UIMotionEffectGroup alloc] init]; 557 | effectGroup.motionEffects = @[effectX, effectY]; 558 | 559 | // Update motion effects 560 | self.hudView.motionEffects = @[]; 561 | [self.hudView addMotionEffect:effectGroup]; 562 | } 563 | } 564 | 565 | - (void)setStatus:(NSString*)string{ 566 | self.stringLabel.text = string; 567 | [self updateHUDFrame]; 568 | } 569 | 570 | - (void)setFadeOutTimer:(NSTimer*)newTimer{ 571 | if(_fadeOutTimer){ 572 | [_fadeOutTimer invalidate], _fadeOutTimer = nil; 573 | } 574 | if(newTimer){ 575 | _fadeOutTimer = newTimer; 576 | } 577 | } 578 | 579 | 580 | #pragma mark - Notifications and their handling 581 | 582 | - (void)registerNotifications{ 583 | #if TARGET_OS_IOS 584 | [[NSNotificationCenter defaultCenter] addObserver:self 585 | selector:@selector(positionHUD:) 586 | name:UIApplicationDidChangeStatusBarOrientationNotification 587 | object:nil]; 588 | #endif 589 | [[NSNotificationCenter defaultCenter] addObserver:self 590 | selector:@selector(positionHUD:) 591 | name:UIApplicationDidBecomeActiveNotification 592 | object:nil]; 593 | 594 | [[NSNotificationCenter defaultCenter] addObserver:self 595 | selector:@selector(positionHUD:) 596 | name:UIKeyboardWillHideNotification 597 | object:nil]; 598 | 599 | [[NSNotificationCenter defaultCenter] addObserver:self 600 | selector:@selector(positionHUD:) 601 | name:UIKeyboardDidHideNotification 602 | object:nil]; 603 | 604 | [[NSNotificationCenter defaultCenter] addObserver:self 605 | selector:@selector(positionHUD:) 606 | name:UIKeyboardWillShowNotification 607 | object:nil]; 608 | 609 | [[NSNotificationCenter defaultCenter] addObserver:self 610 | selector:@selector(positionHUD:) 611 | name:UIKeyboardDidShowNotification 612 | object:nil]; 613 | } 614 | 615 | - (NSDictionary*)notificationUserInfo{ 616 | return (self.stringLabel.text ? @{SVProgressHUDStatusUserInfoKey : self.stringLabel.text} : nil); 617 | } 618 | 619 | - (void)positionHUD:(NSNotification*)notification{ 620 | CGFloat keyboardHeight = 0.0f; 621 | double animationDuration = 0.0; 622 | 623 | #if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS 624 | self.frame = [[[UIApplication sharedApplication] delegate] window].bounds; 625 | UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation; 626 | #elif !defined(SV_APP_EXTENSIONS) 627 | self.frame = [UIApplication sharedApplication].keyWindow.bounds; 628 | #else 629 | if (self.viewForExtension){ 630 | self.frame = self.viewForExtension.frame; 631 | } else { 632 | self.frame = UIScreen.mainScreen.bounds; 633 | } 634 | UIInterfaceOrientation orientation = CGRectGetWidth(self.frame) > CGRectGetHeight(self.frame) ? UIInterfaceOrientationLandscapeLeft : UIInterfaceOrientationPortrait; 635 | #endif 636 | 637 | // no transforms applied to window in iOS 8, but only if compiled with iOS 8 sdk as base sdk, otherwise system supports old rotation logic. 638 | BOOL ignoreOrientation = NO; 639 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 640 | if([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]){ 641 | ignoreOrientation = YES; 642 | } 643 | #endif 644 | 645 | // Get keyboardHeight in regards to current state 646 | if(notification){ 647 | NSDictionary* keyboardInfo = [notification userInfo]; 648 | CGRect keyboardFrame = [keyboardInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue]; 649 | animationDuration = [keyboardInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 650 | 651 | if(notification.name == UIKeyboardWillShowNotification || notification.name == UIKeyboardDidShowNotification){ 652 | keyboardHeight = CGRectGetWidth(keyboardFrame); 653 | #if TARGET_OS_IOS 654 | if(ignoreOrientation || UIInterfaceOrientationIsPortrait(orientation)){ 655 | keyboardHeight = CGRectGetHeight(keyboardFrame); 656 | } 657 | #endif 658 | } 659 | } else{ 660 | keyboardHeight = self.visibleKeyboardHeight; 661 | } 662 | 663 | // Get the currently active frame of the display (depends on orientation) 664 | CGRect orientationFrame = self.bounds; 665 | 666 | #if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS 667 | CGRect statusBarFrame = UIApplication.sharedApplication.statusBarFrame; 668 | #else 669 | CGRect statusBarFrame = CGRectZero; 670 | #endif 671 | 672 | #if TARGET_OS_IOS 673 | if(!ignoreOrientation && UIInterfaceOrientationIsLandscape(orientation)){ 674 | float temp = CGRectGetWidth(orientationFrame); 675 | orientationFrame.size.width = CGRectGetHeight(orientationFrame); 676 | orientationFrame.size.height = temp; 677 | 678 | temp = CGRectGetWidth(statusBarFrame); 679 | statusBarFrame.size.width = CGRectGetHeight(statusBarFrame); 680 | statusBarFrame.size.height = temp; 681 | } 682 | 683 | // Update the motion effects in regards to orientation 684 | [self updateMotionEffectForOrientation:orientation]; 685 | #else 686 | [self updateMotionEffectForXMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis yMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; 687 | #endif 688 | 689 | // Calculate available height for display 690 | CGFloat activeHeight = CGRectGetHeight(orientationFrame); 691 | if(keyboardHeight > 0){ 692 | activeHeight += CGRectGetHeight(statusBarFrame)*2; 693 | } 694 | activeHeight -= keyboardHeight; 695 | 696 | CGFloat posX = CGRectGetWidth(orientationFrame)/2.0f; 697 | CGFloat posY = floorf(activeHeight*0.45f); 698 | 699 | CGFloat rotateAngle = 0.0; 700 | CGPoint newCenter = CGPointMake(posX, posY); 701 | 702 | // Update posX and posY in regards to orientation 703 | #if TARGET_OS_IOS 704 | if(!ignoreOrientation){ 705 | switch (orientation){ 706 | case UIInterfaceOrientationPortraitUpsideDown: 707 | rotateAngle = (CGFloat) M_PI; 708 | newCenter = CGPointMake(posX, CGRectGetHeight(orientationFrame)-posY); 709 | break; 710 | case UIInterfaceOrientationLandscapeLeft: 711 | rotateAngle = (CGFloat) (-M_PI/2.0f); 712 | newCenter = CGPointMake(posY, posX); 713 | break; 714 | case UIInterfaceOrientationLandscapeRight: 715 | rotateAngle = (CGFloat) (M_PI/2.0f); 716 | newCenter = CGPointMake(CGRectGetHeight(orientationFrame)-posY, posX); 717 | break; 718 | default: // Same as UIInterfaceOrientationPortrait 719 | rotateAngle = 0.0f; 720 | newCenter = CGPointMake(posX, posY); 721 | break; 722 | } 723 | } 724 | #endif 725 | 726 | if(notification){ 727 | // Animate update if notification was present 728 | [UIView animateWithDuration:animationDuration 729 | delay:0 730 | options:UIViewAnimationOptionAllowUserInteraction 731 | animations:^{ 732 | [self moveToPoint:newCenter rotateAngle:rotateAngle]; 733 | [self.hudView setNeedsDisplay]; 734 | } completion:NULL]; 735 | } else{ 736 | [self moveToPoint:newCenter rotateAngle:rotateAngle]; 737 | [self.hudView setNeedsDisplay]; 738 | } 739 | 740 | [self updateMask]; 741 | } 742 | 743 | - (void)moveToPoint:(CGPoint)newCenter rotateAngle:(CGFloat)angle{ 744 | self.hudView.transform = CGAffineTransformMakeRotation(angle); 745 | self.hudView.center = CGPointMake(newCenter.x + self.offsetFromCenter.horizontal, newCenter.y + self.offsetFromCenter.vertical); 746 | } 747 | 748 | 749 | #pragma mark - Event handling 750 | 751 | - (void)overlayViewDidReceiveTouchEvent:(id)sender forEvent:(UIEvent*)event{ 752 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidReceiveTouchEventNotification object:event]; 753 | 754 | UITouch *touch = event.allTouches.anyObject; 755 | CGPoint touchLocation = [touch locationInView:self]; 756 | 757 | if(CGRectContainsPoint(self.hudView.frame, touchLocation)){ 758 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidTouchDownInsideNotification object:event]; 759 | } 760 | } 761 | 762 | 763 | #pragma mark - Master show/dismiss methods 764 | 765 | - (void)showProgress:(float)progress status:(NSString*)string{ 766 | if(!self.overlayView.superview){ 767 | #if !defined(SV_APP_EXTENSIONS) 768 | NSEnumerator *frontToBackWindows = [UIApplication.sharedApplication.windows reverseObjectEnumerator]; 769 | for (UIWindow *window in frontToBackWindows){ 770 | BOOL windowOnMainScreen = window.screen == UIScreen.mainScreen; 771 | BOOL windowIsVisible = !window.hidden && window.alpha > 0; 772 | BOOL windowLevelNormal = window.windowLevel == UIWindowLevelNormal; 773 | 774 | if(windowOnMainScreen && windowIsVisible && windowLevelNormal){ 775 | [window addSubview:self.overlayView]; 776 | break; 777 | } 778 | } 779 | #else 780 | if(self.viewForExtension){ 781 | [self.viewForExtension addSubview:self.overlayView]; 782 | } 783 | #endif 784 | } else{ 785 | // Ensure that overlay will be exactly on top of rootViewController (which may be changed during runtime). 786 | [self.overlayView.superview bringSubviewToFront:self.overlayView]; 787 | } 788 | 789 | if(!self.superview){ 790 | [self.overlayView addSubview:self]; 791 | } 792 | 793 | if(self.fadeOutTimer){ 794 | self.activityCount = 0; 795 | } 796 | self.fadeOutTimer = nil; 797 | self.imageView.hidden = YES; 798 | self.progress = progress; 799 | 800 | self.stringLabel.text = string; 801 | [self updateHUDFrame]; 802 | 803 | if(progress >= 0){ 804 | self.imageView.image = nil; 805 | self.imageView.hidden = NO; 806 | 807 | [self.indefiniteAnimatedView removeFromSuperview]; 808 | if([self.indefiniteAnimatedView respondsToSelector:@selector(stopAnimating)]) { 809 | [(id)self.indefiniteAnimatedView stopAnimating]; 810 | } 811 | 812 | self.ringLayer.strokeEnd = progress; 813 | 814 | if(progress == 0){ 815 | self.activityCount++; 816 | } 817 | } else{ 818 | self.activityCount++; 819 | [self cancelRingLayerAnimation]; 820 | 821 | [self.hudView addSubview:self.indefiniteAnimatedView]; 822 | if([self.indefiniteAnimatedView respondsToSelector:@selector(startAnimating)]) { 823 | [(id)self.indefiniteAnimatedView startAnimating]; 824 | } 825 | } 826 | 827 | if(self.defaultMaskType != SVProgressHUDMaskTypeNone){ 828 | self.overlayView.userInteractionEnabled = YES; 829 | self.accessibilityLabel = string; 830 | self.isAccessibilityElement = YES; 831 | } else{ 832 | self.overlayView.userInteractionEnabled = NO; 833 | self.hudView.accessibilityLabel = string; 834 | self.hudView.isAccessibilityElement = YES; 835 | } 836 | 837 | self.overlayView.hidden = NO; 838 | self.overlayView.backgroundColor = [UIColor clearColor]; 839 | [self positionHUD:nil]; 840 | 841 | // Appear 842 | if(self.alpha != 1 || self.hudView.alpha != 1){ 843 | NSDictionary *userInfo = [self notificationUserInfo]; 844 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillAppearNotification 845 | object:nil 846 | userInfo:userInfo]; 847 | 848 | [self registerNotifications]; 849 | self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.3, 1.3); 850 | 851 | if(self.isClear){ 852 | self.alpha = 1; 853 | self.hudView.alpha = 0; 854 | } 855 | 856 | __weak SVProgressHUD *weakSelf = self; 857 | [UIView animateWithDuration:0.15 858 | delay:0 859 | options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState 860 | animations:^{ 861 | __strong SVProgressHUD *strongSelf = weakSelf; 862 | if(strongSelf){ 863 | strongSelf.hudView.transform = CGAffineTransformScale(strongSelf.hudView.transform, 1/1.3f, 1/1.3f); 864 | 865 | if(strongSelf.isClear){ // handle iOS 7 and 8 UIToolbar which not answers well to hierarchy opacity change 866 | strongSelf.hudView.alpha = 1; 867 | } else{ 868 | strongSelf.alpha = 1; 869 | } 870 | } 871 | } 872 | completion:^(BOOL finished){ 873 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidAppearNotification 874 | object:nil 875 | userInfo:userInfo]; 876 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); 877 | UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, string); 878 | }]; 879 | 880 | [self setNeedsDisplay]; 881 | } 882 | } 883 | 884 | - (void)showImage:(UIImage*)image status:(NSString*)string duration:(NSTimeInterval)duration{ 885 | self.progress = SVProgressHUDUndefinedProgress; 886 | [self cancelRingLayerAnimation]; 887 | 888 | if(![self.class isVisible]){ 889 | [self.class show]; 890 | } 891 | 892 | UIColor *tintColor = self.foregroundColorForStyle; 893 | if([self.imageView respondsToSelector:@selector(setTintColor:)]){ 894 | if (image.renderingMode != UIImageRenderingModeAlwaysTemplate) { 895 | image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 896 | } 897 | self.imageView.tintColor = tintColor; 898 | } else{ 899 | image = [self image:image withTintColor:tintColor]; 900 | } 901 | self.imageView.image = image; 902 | self.imageView.hidden = NO; 903 | 904 | self.stringLabel.text = string; 905 | [self updateHUDFrame]; 906 | [self.indefiniteAnimatedView removeFromSuperview]; 907 | if([self.indefiniteAnimatedView respondsToSelector:@selector(stopAnimating)]) { 908 | [(id)self.indefiniteAnimatedView stopAnimating]; 909 | } 910 | 911 | if(self.defaultMaskType != SVProgressHUDMaskTypeNone){ 912 | self.overlayView.userInteractionEnabled = YES; 913 | self.accessibilityLabel = string; 914 | self.isAccessibilityElement = YES; 915 | } else{ 916 | self.overlayView.userInteractionEnabled = NO; 917 | self.hudView.accessibilityLabel = string; 918 | self.hudView.isAccessibilityElement = YES; 919 | } 920 | 921 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); 922 | UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, string); 923 | 924 | self.fadeOutTimer = [NSTimer timerWithTimeInterval:duration target:self selector:@selector(dismiss) userInfo:nil repeats:NO]; 925 | [[NSRunLoop mainRunLoop] addTimer:self.fadeOutTimer forMode:NSRunLoopCommonModes]; 926 | } 927 | 928 | - (void)dismissWithDelay:(NSTimeInterval)delay{ 929 | NSDictionary *userInfo = [self notificationUserInfo]; 930 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillDisappearNotification 931 | object:nil 932 | userInfo:userInfo]; 933 | 934 | self.activityCount = 0; 935 | __weak SVProgressHUD *weakSelf = self; 936 | [UIView animateWithDuration:0.15 937 | delay:delay 938 | options:(UIViewAnimationOptions) (UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction) 939 | animations:^{ 940 | __strong SVProgressHUD *strongSelf = weakSelf; 941 | if(strongSelf){ 942 | strongSelf.hudView.transform = CGAffineTransformScale(self.hudView.transform, 0.8f, 0.8f); 943 | if(strongSelf.isClear){ // handle iOS 7 UIToolbar not answer well to hierarchy opacity change 944 | strongSelf.hudView.alpha = 0.0f; 945 | } else{ 946 | strongSelf.alpha = 0.0f; 947 | } 948 | } 949 | } 950 | completion:^(BOOL finished){ 951 | __strong SVProgressHUD *strongSelf = weakSelf; 952 | if(strongSelf){ 953 | if(strongSelf.alpha == 0.0f || strongSelf.hudView.alpha == 0.0f){ 954 | strongSelf.alpha = 0.0f; 955 | strongSelf.hudView.alpha = 0.0f; 956 | 957 | [[NSNotificationCenter defaultCenter] removeObserver:strongSelf]; 958 | [strongSelf cancelRingLayerAnimation]; 959 | [_hudView removeFromSuperview]; 960 | _hudView = nil; 961 | 962 | [_overlayView removeFromSuperview]; 963 | _overlayView = nil; 964 | 965 | [_indefiniteAnimatedView removeFromSuperview]; 966 | _indefiniteAnimatedView = nil; 967 | 968 | UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); 969 | 970 | [[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDDidDisappearNotification 971 | object:nil 972 | userInfo:userInfo]; 973 | 974 | // Tell the rootViewController to update the StatusBar appearance 975 | #if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS 976 | UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController; 977 | if([rootController respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){ 978 | [rootController setNeedsStatusBarAppearanceUpdate]; 979 | } 980 | #endif 981 | // uncomment to make sure UIWindow is gone from app.windows 982 | //NSLog(@"%@", [UIApplication sharedApplication].windows); 983 | //NSLog(@"keyWindow = %@", [[[UIApplication sharedApplication] delegate] window]); 984 | } 985 | } 986 | }]; 987 | } 988 | 989 | - (void)dismiss 990 | { 991 | [self dismissWithDelay:0]; 992 | } 993 | 994 | 995 | #pragma mark - Ring progress animation 996 | 997 | - (UIActivityIndicatorView *)createActivityIndicatorView{ 998 | UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 999 | activityIndicatorView.color = self.foregroundColorForStyle; 1000 | [activityIndicatorView sizeToFit]; 1001 | return activityIndicatorView; 1002 | } 1003 | 1004 | - (SVIndefiniteAnimatedView *)createIndefiniteAnimatedView{ 1005 | SVIndefiniteAnimatedView *indefiniteAnimatedView = [[SVIndefiniteAnimatedView alloc] initWithFrame:CGRectZero]; 1006 | indefiniteAnimatedView.strokeColor = self.foregroundColorForStyle; 1007 | indefiniteAnimatedView.radius = self.stringLabel.text ? self.ringRadius : self.ringNoTextRadius; 1008 | indefiniteAnimatedView.strokeThickness = self.ringThickness; 1009 | [indefiniteAnimatedView sizeToFit]; 1010 | return indefiniteAnimatedView; 1011 | } 1012 | 1013 | - (UIView *)indefiniteAnimatedView{ 1014 | if(_indefiniteAnimatedView == nil){ 1015 | _indefiniteAnimatedView = (self.defaultAnimationType == SVProgressHUDAnimationTypeFlat) ? [self createIndefiniteAnimatedView] : [self createActivityIndicatorView]; 1016 | } 1017 | 1018 | return _indefiniteAnimatedView; 1019 | } 1020 | 1021 | - (CAShapeLayer*)ringLayer{ 1022 | if(!_ringLayer){ 1023 | CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); 1024 | _ringLayer = [self createRingLayerWithCenter:center radius:self.ringRadius]; 1025 | [self.hudView.layer addSublayer:_ringLayer]; 1026 | } 1027 | _ringLayer.strokeColor = self.foregroundColorForStyle.CGColor; 1028 | _ringLayer.lineWidth = self.ringThickness; 1029 | 1030 | return _ringLayer; 1031 | } 1032 | 1033 | - (CAShapeLayer*)backgroundRingLayer{ 1034 | if(!_backgroundRingLayer){ 1035 | CGPoint center = CGPointMake(CGRectGetWidth(_hudView.frame)/2, CGRectGetHeight(_hudView.frame)/2); 1036 | _backgroundRingLayer = [self createRingLayerWithCenter:center radius:self.ringRadius]; 1037 | _backgroundRingLayer.strokeEnd = 1; 1038 | [self.hudView.layer addSublayer:_backgroundRingLayer]; 1039 | } 1040 | _backgroundRingLayer.strokeColor = [self.foregroundColorForStyle colorWithAlphaComponent:0.1f].CGColor; 1041 | _backgroundRingLayer.lineWidth = self.ringThickness; 1042 | 1043 | return _backgroundRingLayer; 1044 | } 1045 | 1046 | - (void)cancelRingLayerAnimation{ 1047 | [CATransaction begin]; 1048 | [CATransaction setDisableActions:YES]; 1049 | [_hudView.layer removeAllAnimations]; 1050 | 1051 | _ringLayer.strokeEnd = 0.0f; 1052 | if(_ringLayer.superlayer){ 1053 | [_ringLayer removeFromSuperlayer]; 1054 | } 1055 | _ringLayer = nil; 1056 | 1057 | if(_backgroundRingLayer.superlayer){ 1058 | [_backgroundRingLayer removeFromSuperlayer]; 1059 | } 1060 | _backgroundRingLayer = nil; 1061 | 1062 | [CATransaction commit]; 1063 | } 1064 | 1065 | - (CAShapeLayer*)createRingLayerWithCenter:(CGPoint)center radius:(CGFloat)radius{ 1066 | UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius startAngle:(CGFloat) -M_PI_2 endAngle:(CGFloat) (M_PI + M_PI_2) clockwise:YES]; 1067 | 1068 | CAShapeLayer *slice = [CAShapeLayer layer]; 1069 | slice.contentsScale = [[UIScreen mainScreen] scale]; 1070 | slice.frame = CGRectMake(center.x-radius, center.y-radius, radius*2, radius*2); 1071 | slice.fillColor = [UIColor clearColor].CGColor; 1072 | slice.lineCap = kCALineCapRound; 1073 | slice.lineJoin = kCALineJoinBevel; 1074 | slice.path = smoothedPath.CGPath; 1075 | 1076 | return slice; 1077 | } 1078 | 1079 | 1080 | #pragma mark - Utilities 1081 | 1082 | + (BOOL)isVisible{ 1083 | return ([self sharedView].alpha == 1); 1084 | } 1085 | 1086 | 1087 | #pragma mark - Getters 1088 | + (NSTimeInterval)displayDurationForString:(NSString*)string{ 1089 | return MIN((float)string.length * 0.06 + 0.5, [self sharedView].minimumDismissTimeInterval); 1090 | } 1091 | 1092 | - (UIColor *)foregroundColorForStyle{ 1093 | if(self.defaultStyle == SVProgressHUDStyleLight){ 1094 | return [UIColor blackColor]; 1095 | } else if(self.defaultStyle == SVProgressHUDStyleDark){ 1096 | return [UIColor whiteColor]; 1097 | } else{ 1098 | return self.foregroundColor; 1099 | } 1100 | } 1101 | 1102 | - (UIColor *)backgroundColorForStyle{ 1103 | if(self.defaultStyle == SVProgressHUDStyleLight){ 1104 | return [UIColor whiteColor]; 1105 | } else if(self.defaultStyle == SVProgressHUDStyleDark){ 1106 | return [UIColor blackColor]; 1107 | } else{ 1108 | return self.backgroundColor; 1109 | } 1110 | } 1111 | 1112 | - (UIImage*)image:(UIImage*)image withTintColor:(UIColor*)color{ 1113 | CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height); 1114 | UIGraphicsBeginImageContextWithOptions(rect.size, NO, image.scale); 1115 | CGContextRef c = UIGraphicsGetCurrentContext(); 1116 | [image drawInRect:rect]; 1117 | CGContextSetFillColorWithColor(c, [color CGColor]); 1118 | CGContextSetBlendMode(c, kCGBlendModeSourceAtop); 1119 | CGContextFillRect(c, rect); 1120 | UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext(); 1121 | UIGraphicsEndImageContext(); 1122 | 1123 | return tintedImage; 1124 | } 1125 | 1126 | - (BOOL)isClear{ // used for iOS 7 and above 1127 | return (self.defaultMaskType == SVProgressHUDMaskTypeClear || self.defaultMaskType == SVProgressHUDMaskTypeNone); 1128 | } 1129 | 1130 | - (UIControl*)overlayView{ 1131 | if(!_overlayView){ 1132 | #if !defined(SV_APP_EXTENSIONS) 1133 | CGRect windowBounds = [[[UIApplication sharedApplication] delegate] window].bounds; 1134 | _overlayView = [[UIControl alloc] initWithFrame:windowBounds]; 1135 | #else 1136 | _overlayView = [[UIControl alloc] initWithFrame:[UIScreen mainScreen].bounds]; 1137 | #endif 1138 | _overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 1139 | _overlayView.backgroundColor = [UIColor clearColor]; 1140 | [_overlayView addTarget:self action:@selector(overlayViewDidReceiveTouchEvent:forEvent:) forControlEvents:UIControlEventTouchDown]; 1141 | } 1142 | return _overlayView; 1143 | } 1144 | 1145 | - (UIView*)hudView{ 1146 | if(!_hudView){ 1147 | _hudView = [[UIView alloc] initWithFrame:CGRectZero]; 1148 | _hudView.layer.cornerRadius = self.cornerRadius; 1149 | _hudView.layer.masksToBounds = YES; 1150 | _hudView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; 1151 | } 1152 | _hudView.backgroundColor = self.backgroundColorForStyle; 1153 | 1154 | if(!_hudView.superview){ 1155 | [self addSubview:_hudView]; 1156 | } 1157 | return _hudView; 1158 | } 1159 | 1160 | - (UILabel*)stringLabel{ 1161 | if(!_stringLabel){ 1162 | _stringLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 1163 | _stringLabel.backgroundColor = [UIColor clearColor]; 1164 | _stringLabel.adjustsFontSizeToFitWidth = YES; 1165 | _stringLabel.textAlignment = NSTextAlignmentCenter; 1166 | _stringLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters; 1167 | _stringLabel.numberOfLines = 0; 1168 | } 1169 | _stringLabel.textColor = self.foregroundColorForStyle; 1170 | _stringLabel.font = self.font; 1171 | 1172 | if(!_stringLabel.superview){ 1173 | [self.hudView addSubview:_stringLabel]; 1174 | } 1175 | return _stringLabel; 1176 | } 1177 | 1178 | - (UIImageView*)imageView{ 1179 | if(!_imageView){ 1180 | _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 28.0f, 28.0f)]; 1181 | } 1182 | if(!_imageView.superview){ 1183 | [self.hudView addSubview:_imageView]; 1184 | } 1185 | return _imageView; 1186 | } 1187 | 1188 | - (CGFloat)visibleKeyboardHeight{ 1189 | #if !defined(SV_APP_EXTENSIONS) 1190 | UIWindow *keyboardWindow = nil; 1191 | for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]){ 1192 | if(![[testWindow class] isEqual:[UIWindow class]]){ 1193 | keyboardWindow = testWindow; 1194 | break; 1195 | } 1196 | } 1197 | 1198 | for (__strong UIView *possibleKeyboard in [keyboardWindow subviews]){ 1199 | if([possibleKeyboard isKindOfClass:NSClassFromString(@"UIPeripheralHostView")] || [possibleKeyboard isKindOfClass:NSClassFromString(@"UIKeyboard")]){ 1200 | return CGRectGetHeight(possibleKeyboard.bounds); 1201 | } else if([possibleKeyboard isKindOfClass:NSClassFromString(@"UIInputSetContainerView")]){ 1202 | for (__strong UIView *possibleKeyboardSubview in [possibleKeyboard subviews]){ 1203 | if([possibleKeyboardSubview isKindOfClass:NSClassFromString(@"UIInputSetHostView")]){ 1204 | return CGRectGetHeight(possibleKeyboardSubview.bounds); 1205 | } 1206 | } 1207 | } 1208 | } 1209 | #endif 1210 | return 0; 1211 | } 1212 | 1213 | #pragma mark - UIAppearance Setters 1214 | 1215 | - (void)setDefaultStyle:(SVProgressHUDStyle)style{ 1216 | if (!_isInitializing) _defaultStyle = style; 1217 | } 1218 | 1219 | - (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType{ 1220 | if (!_isInitializing) _defaultMaskType = maskType; 1221 | } 1222 | 1223 | - (void)setDefaultAnimationType:(SVProgressHUDAnimationType)animationType{ 1224 | if (!_isInitializing) _defaultAnimationType = animationType; 1225 | } 1226 | 1227 | - (void)setMinimumSize:(CGSize)minimumSize{ 1228 | if (!_isInitializing) _minimumSize = minimumSize; 1229 | } 1230 | 1231 | - (void)setRingThickness:(CGFloat)ringThickness{ 1232 | if (!_isInitializing) _ringThickness = ringThickness; 1233 | } 1234 | 1235 | - (void)setRingRadius:(CGFloat)ringRadius{ 1236 | if (!_isInitializing) _ringRadius = ringRadius; 1237 | } 1238 | 1239 | - (void)setRingNoTextRadius:(CGFloat)ringNoTextRadius{ 1240 | if (!_isInitializing) _ringNoTextRadius = ringNoTextRadius; 1241 | } 1242 | 1243 | - (void)setCornerRadius:(CGFloat)cornerRadius{ 1244 | if (!_isInitializing) _cornerRadius = cornerRadius; 1245 | } 1246 | 1247 | - (void)setFont:(UIFont *)font{ 1248 | if (!_isInitializing) _font = font; 1249 | } 1250 | 1251 | - (void)setBackgroundColor:(UIColor *)color{ 1252 | if (!_isInitializing) _backgroundColor = color; 1253 | } 1254 | 1255 | - (void)setForegroundColor:(UIColor *)color{ 1256 | if (!_isInitializing) _foregroundColor = color; 1257 | } 1258 | 1259 | - (void)setInfoImage:(UIImage*)image{ 1260 | if (!_isInitializing) _infoImage = image; 1261 | } 1262 | 1263 | - (void)setSuccessImage:(UIImage *)image{ 1264 | if (!_isInitializing) _successImage = image; 1265 | } 1266 | 1267 | - (void)setErrorImage:(UIImage *)image{ 1268 | if (!_isInitializing) _errorImage = image; 1269 | } 1270 | 1271 | - (void)setViewForExtension:(UIView *)view{ 1272 | if (!_isInitializing) _viewForExtension = view; 1273 | } 1274 | 1275 | - (void)setOffsetFromCenter:(UIOffset)offset{ 1276 | if (!_isInitializing) _offsetFromCenter = offset; 1277 | } 1278 | 1279 | - (void)setMinimumDismissTimeInterval:(NSTimeInterval)minimumDismissTimeInterval{ 1280 | if (!_isInitializing) _minimumDismissTimeInterval = minimumDismissTimeInterval; 1281 | } 1282 | 1283 | @end 1284 | 1285 | --------------------------------------------------------------------------------