├── README.md ├── Podfile ├── LFCamera.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── project.pbxproj ├── LFCamera ├── ViewController.h ├── PrefixHeader.pch ├── AppDelegate.h ├── main.m ├── LFCamera │ ├── LFCameraResultView.h │ ├── LFCamera.h │ ├── LFCameraResultView.m │ └── LFCamera.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── AppDelegate.m └── ViewController.m ├── LFCamera.xcworkspace └── contents.xcworkspacedata ├── LFCamera.podspec ├── LFCameraTests ├── Info.plist └── LFCameraTests.m ├── LFCameraUITests ├── Info.plist └── LFCameraUITests.m ├── LICENSE └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # LFCamera 2 | 自定义相机,可选带拍摄区域边框及半透明遮罩层 3 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '7.0' 2 | target 'LFCamera' do 3 | pod 'Masonry' 4 | end 5 | -------------------------------------------------------------------------------- /LFCamera.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LFCamera/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LFCamera.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LFCamera/PrefixHeader.pch: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixHeader.pch 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/25. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #ifndef PrefixHeader_pch 10 | #define PrefixHeader_pch 11 | 12 | #import "Masonry.h" 13 | 14 | #endif /* PrefixHeader_pch */ 15 | -------------------------------------------------------------------------------- /LFCamera/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. 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 | -------------------------------------------------------------------------------- /LFCamera/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. 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 | -------------------------------------------------------------------------------- /LFCamera.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'LFCamera' 3 | s.version = '1.0' 4 | s.license = { :type => "MIT", :file => "LICENSE" } 5 | s.summary = '可自定义相机UI,可选带拍摄区域边框及半透明遮罩层 ' 6 | s.homepage = 'https://github.com/zhanglinfeng/LFCamera' 7 | s.authors = { '张林峰' => '1051034428@qq.com' } 8 | s.source = { :git => 'https://github.com/zhanglinfeng/LFCamera.git', :tag => s.version.to_s } 9 | s.requires_arc = true 10 | s.ios.deployment_target = '8.0' 11 | s.source_files = 'LFCamera/LFCamera/*.{h,m}' 12 | end 13 | -------------------------------------------------------------------------------- /LFCamera/LFCamera/LFCameraResultView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LFCameraResultView.h 3 | // CarMedia 4 | // 5 | // Created by 张林峰 on 16/11/4. 6 | // Copyright © 2016年 张林峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LFCameraResultView : UIView 12 | 13 | @property (strong, nonatomic) UIImageView *imageView; 14 | @property (strong, nonatomic) UIButton *btRephotograph; 15 | @property (strong, nonatomic) UIButton *btUsePhoto; 16 | @property (copy, nonatomic) void (^rephotographBlock)();//重拍 17 | @property (copy, nonatomic) void (^usePhotoBlock)(UIImage *img);//使用 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /LFCameraTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LFCameraUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LFCameraTests/LFCameraTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LFCameraTests.m 3 | // LFCameraTests 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LFCameraTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LFCameraTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 张林峰 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 | -------------------------------------------------------------------------------- /LFCamera/LFCamera/LFCamera.h: -------------------------------------------------------------------------------- 1 | // 2 | // LFCamera.h 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/25. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, LFCaptureFlashMode) { 12 | LFCaptureFlashModeOff = 0, 13 | LFCaptureFlashModeOn = 1, 14 | LFCaptureFlashModeAuto = 2 15 | }; 16 | 17 | @interface LFCamera : UIView 18 | 19 | @property (assign, nonatomic) CGRect effectiveRect;//拍摄有效区域((可不设置,不设置则不显示遮罩层和边框) 20 | 21 | //有效区边框色,默认橘色 22 | @property (nonatomic, strong) UIColor *effectiveRectBorderColor; 23 | 24 | //遮罩层颜色,默认黑色半透明 25 | @property (nonatomic, strong) UIColor *maskColor; 26 | 27 | @property (nonatomic) UIView *focusView;//聚焦的view 28 | 29 | /**如果用代码初始化,一定要调这个方法初始化*/ 30 | - (instancetype)initWithFrame:(CGRect)frame; 31 | 32 | /**获取摄像头方向*/ 33 | - (BOOL)isCameraFront; 34 | 35 | /**获取闪光灯模式*/ 36 | - (LFCaptureFlashMode)getCaptureFlashMode; 37 | 38 | /**切换闪光灯*/ 39 | - (void)switchLight:(LFCaptureFlashMode)flashMode; 40 | 41 | /**切换摄像头*/ 42 | - (void)switchCamera:(BOOL)isFront; 43 | 44 | /**拍照*/ 45 | - (void)takePhoto:(void (^)(UIImage *img))resultBlock; 46 | 47 | /**重拍*/ 48 | - (void)restart; 49 | 50 | /**调整图片朝向*/ 51 | + (UIImage *)fixOrientation:(UIImage *)aImage; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /LFCameraUITests/LFCameraUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // LFCameraUITests.m 3 | // LFCameraUITests 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LFCameraUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation LFCameraUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LFCamera/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LFCamera/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 | -------------------------------------------------------------------------------- /LFCamera/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | 需要访问您的摄像头 25 | NSMicrophoneUsageDescription 26 | 需要访问您的麦克风 27 | NSPhotoLibraryUsageDescription 28 | 需要访问您的相册 29 | UILaunchStoryboardName 30 | LaunchScreen 31 | UIMainStoryboardFile 32 | Main 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UISupportedInterfaceOrientations~ipad 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /.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 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-acknowledgements.markdown 62 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-acknowledgements.plist 63 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-dummy.m 64 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-frameworks.sh 65 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-resources.sh 66 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera.debug.xcconfig 67 | Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera.release.xcconfig 68 | -------------------------------------------------------------------------------- /LFCamera/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. 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 | // Override point for customization after application launch. 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 | -------------------------------------------------------------------------------- /LFCamera/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/24. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LFCameraResultView.h" 11 | #import "LFCamera.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (strong, nonatomic) LFCamera *lfCamera; 16 | @property (strong, nonatomic) LFCameraResultView *resultView;//结果view 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | //本界面可以随便怎么设计,我这里只做个粗糙版。核心是LFCamera 26 | 27 | self.lfCamera = [[LFCamera alloc] initWithFrame:self.view.bounds]; 28 | 29 | //拍摄有效区域(可不设置,不设置则不显示遮罩层和边框) 30 | self.lfCamera.effectiveRect = CGRectMake(20, 200, self.view.frame.size.width - 40, 280); 31 | [self.view insertSubview:self.lfCamera atIndex:0]; 32 | 33 | } 34 | 35 | 36 | - (IBAction)takePhoto:(id)sender { 37 | [self.lfCamera takePhoto:^(UIImage *img) { 38 | self.resultView = [[LFCameraResultView alloc] initWithFrame:self.view.bounds]; 39 | self.resultView.imageView.image = img; 40 | 41 | __weak ViewController *weakSelf = self; 42 | self.resultView.rephotographBlock = ^ { 43 | [weakSelf.lfCamera restart]; 44 | 45 | }; 46 | self.resultView.usePhotoBlock = ^(UIImage *img){ 47 | 48 | }; 49 | [self.view addSubview:self.resultView]; 50 | }]; 51 | } 52 | 53 | - (IBAction)lightOn:(id)sender { 54 | [self.lfCamera switchLight:LFCaptureFlashModeOn]; 55 | NSLog(@"灯:%@",@([self.lfCamera getCaptureFlashMode])); 56 | } 57 | 58 | - (IBAction)lightOff:(id)sender { 59 | [self.lfCamera switchLight:LFCaptureFlashModeOff]; 60 | NSLog(@"灯:%@",@([self.lfCamera getCaptureFlashMode])); 61 | } 62 | 63 | - (IBAction)lightAuto:(id)sender { 64 | [self.lfCamera switchLight:LFCaptureFlashModeAuto]; 65 | NSLog(@"灯:%@",@([self.lfCamera getCaptureFlashMode])); 66 | } 67 | 68 | - (IBAction)switchFront:(id)sender { 69 | [self.lfCamera switchCamera:YES]; 70 | NSLog(@"摄像头:%@",@([self.lfCamera isCameraFront])); 71 | } 72 | 73 | - (IBAction)switchBack:(id)sender { 74 | [self.lfCamera switchCamera:NO]; 75 | NSLog(@"摄像头:%@",@([self.lfCamera isCameraFront])); 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /LFCamera/LFCamera/LFCameraResultView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LFCameraResultView.m 3 | // CarMedia 4 | // 5 | // Created by 张林峰 on 16/11/4. 6 | // Copyright © 2016年 张林峰. All rights reserved. 7 | // 8 | 9 | #import "LFCameraResultView.h" 10 | 11 | @implementation LFCameraResultView 12 | 13 | - (instancetype)initWithFrame:(CGRect)frame { 14 | self = [super initWithFrame:frame]; 15 | if (self) { 16 | [self initUI]; 17 | } 18 | return self; 19 | } 20 | 21 | -(void)layoutSubviews { 22 | [super layoutSubviews]; 23 | self.imageView.frame = self.bounds; 24 | self.btRephotograph.frame = CGRectMake(20, self.frame.size.height - 60, 60, 40); 25 | self.btUsePhoto.frame = CGRectMake(self.frame.size.width - 80, self.frame.size.height - 60, 60, 40); 26 | } 27 | 28 | - (void)initUI { 29 | 30 | self.imageView = [[UIImageView alloc] initWithFrame:self.bounds]; 31 | self.imageView.backgroundColor =[UIColor blackColor]; 32 | self.imageView.contentMode = UIViewContentModeScaleAspectFit; 33 | [self addSubview:self.imageView]; 34 | 35 | self.btRephotograph = [[UIButton alloc] initWithFrame:CGRectMake(20, self.frame.size.height - 60, 60, 40)]; 36 | [self.btRephotograph setTitle:@"重拍" forState:UIControlStateNormal]; 37 | [self.btRephotograph addTarget:self action:@selector(rephotograph:) forControlEvents:UIControlEventTouchUpInside]; 38 | [self addSubview:self.btRephotograph]; 39 | 40 | self.btUsePhoto = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width - 80, self.frame.size.height - 60, 60, 40)]; 41 | [self.btUsePhoto setTitle:@"使用" forState:UIControlStateNormal]; 42 | [self.btUsePhoto addTarget:self action:@selector(usePhoto:) forControlEvents:UIControlEventTouchUpInside]; 43 | [self addSubview:self.btUsePhoto]; 44 | } 45 | 46 | - (void)rephotograph:(id)sender { 47 | [self removeFromSuperview]; 48 | if (self.rephotographBlock) { 49 | self.rephotographBlock(); 50 | } 51 | } 52 | 53 | - (void)usePhoto:(id)sender { 54 | if (self.usePhotoBlock) { 55 | self.usePhotoBlock(self.imageView.image); 56 | } 57 | } 58 | 59 | /* 60 | // Only override drawRect: if you perform custom drawing. 61 | // An empty implementation adversely affects performance during animation. 62 | - (void)drawRect:(CGRect)rect { 63 | // Drawing code 64 | } 65 | */ 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /LFCamera/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 | 35 | 42 | 49 | 56 | 63 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /LFCamera/LFCamera/LFCamera.m: -------------------------------------------------------------------------------- 1 | // 2 | // LFCamera.m 3 | // LFCamera 4 | // 5 | // Created by 张林峰 on 2017/4/25. 6 | // Copyright © 2017年 张林峰. All rights reserved. 7 | // 8 | 9 | #import "LFCamera.h" 10 | #import 11 | #import 12 | 13 | @interface LFCamera () 14 | 15 | //捕获设备,通常是前置摄像头,后置摄像头,麦克风(音频输入) 16 | @property(nonatomic)AVCaptureDevice *device; 17 | 18 | //AVCaptureDeviceInput 代表输入设备,他使用AVCaptureDevice 来初始化 19 | @property(nonatomic)AVCaptureDeviceInput *input; 20 | 21 | //当启动摄像头开始捕获输入 22 | @property(nonatomic)AVCaptureMetadataOutput *output; 23 | 24 | @property (nonatomic)AVCaptureStillImageOutput *ImageOutPut; 25 | 26 | //session:由他把输入输出结合在一起,并开始启动捕获设备(摄像头) 27 | @property(nonatomic)AVCaptureSession *session; 28 | 29 | //图像预览层,实时显示捕获的图像 30 | @property(nonatomic)AVCaptureVideoPreviewLayer *previewLayer; 31 | 32 | /**记录开始的缩放比例*/ 33 | @property(nonatomic,assign) CGFloat beginGestureScale; 34 | 35 | /** 最后的缩放比例*/ 36 | @property(nonatomic,assign) CGFloat effectiveScale; 37 | 38 | @property(nonatomic, strong) CMMotionManager * motionManager; 39 | @property(nonatomic, assign) UIDeviceOrientation deviceOrientation; 40 | 41 | @property (nonatomic, strong) CAShapeLayer * maskLayer;//半透明黑色遮罩 42 | @property (nonatomic, strong) CAShapeLayer * effectiveRectLayer;//有效区域框 43 | @property (nonatomic) BOOL isAuthorized; 44 | @property (nonatomic) BOOL isFront;//是否前摄像头 45 | 46 | @end 47 | 48 | @implementation LFCamera 49 | 50 | - (instancetype)initWithFrame:(CGRect)frame { 51 | self = [super initWithFrame:frame]; 52 | if (self) { 53 | self.isAuthorized = [self canUseCamear]; 54 | [self configCotionManager]; 55 | if (self.isAuthorized) { 56 | [self configCamera]; 57 | } 58 | self.effectiveRectBorderColor = [UIColor orangeColor]; 59 | self.maskColor = [UIColor colorWithWhite: 0 alpha: 0.75]; 60 | //聚焦视图 61 | [self addSubview:self.focusView]; 62 | 63 | //缩放手势 64 | self.effectiveScale = self.beginGestureScale = 1.0f; 65 | UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; 66 | pinch.delegate = self; 67 | [self addGestureRecognizer:pinch]; 68 | } 69 | return self; 70 | } 71 | 72 | -(void)awakeFromNib { 73 | [super awakeFromNib]; 74 | self.isAuthorized = [self canUseCamear]; 75 | [self configCotionManager]; 76 | if (self.isAuthorized) { 77 | [self configCamera]; 78 | } 79 | self.effectiveRectBorderColor = [UIColor orangeColor]; 80 | self.maskColor = [UIColor colorWithWhite: 0 alpha: 0.75]; 81 | //聚焦视图 82 | [self addSubview:self.focusView]; 83 | 84 | //缩放手势 85 | self.effectiveScale = self.beginGestureScale = 1.0f; 86 | UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; 87 | pinch.delegate = self; 88 | [self addGestureRecognizer:pinch]; 89 | } 90 | 91 | - (void)dealloc { 92 | [self.session stopRunning]; 93 | } 94 | 95 | - (void)layoutSubviews { 96 | self.maskLayer.path = [self getMaskPathWithRect:self.bounds exceptRect:self.effectiveRect].CGPath; 97 | self.previewLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); 98 | } 99 | 100 | - (void)setEffectiveRect:(CGRect)effectiveRect { 101 | _effectiveRect = effectiveRect; 102 | if (_effectiveRect.size.width > 0) { 103 | [self setupEffectiveRect]; 104 | } 105 | } 106 | 107 | - (void)configCotionManager { 108 | _motionManager = [[CMMotionManager alloc] init]; 109 | _motionManager.deviceMotionUpdateInterval = 1/15.0; 110 | if (!_motionManager.deviceMotionAvailable) { 111 | _motionManager = nil; 112 | } 113 | [_motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler: ^(CMDeviceMotion *motion, NSError *error){ 114 | [self performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES]; 115 | }]; 116 | } 117 | 118 | - (void)handleDeviceMotion:(CMDeviceMotion *)deviceMotion{ 119 | double x = deviceMotion.gravity.x; 120 | double y = deviceMotion.gravity.y; 121 | if (fabs(y) >= fabs(x)) 122 | { 123 | if (y >= 0){ 124 | _deviceOrientation = UIDeviceOrientationPortraitUpsideDown; 125 | } 126 | else{ 127 | _deviceOrientation = UIDeviceOrientationPortrait; 128 | } 129 | } 130 | else{ 131 | if (x >= 0){ 132 | _deviceOrientation = UIDeviceOrientationLandscapeRight; 133 | } 134 | else{ 135 | _deviceOrientation = UIDeviceOrientationLandscapeLeft; 136 | } 137 | } 138 | } 139 | 140 | - (void)configCamera{ 141 | 142 | //使用AVMediaTypeVideo 指明self.device代表视频,默认使用后置摄像头进行初始化 143 | self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 144 | //使用设备初始化输入 145 | self.input = [[AVCaptureDeviceInput alloc]initWithDevice:self.device error:nil]; 146 | 147 | //生成输出对象 148 | self.output = [[AVCaptureMetadataOutput alloc]init]; 149 | self.ImageOutPut = [[AVCaptureStillImageOutput alloc] init]; 150 | 151 | //生成会话,用来结合输入输出 152 | self.session = [[AVCaptureSession alloc]init]; 153 | // if ([self.session canSetSessionPreset:AVCaptureSessionPreset1280x720]) { 154 | // self.session.sessionPreset = AVCaptureSessionPreset1280x720; 155 | // } 156 | if ([self.session canAddInput:self.input]) { 157 | [self.session addInput:self.input]; 158 | } 159 | if ([self.session canAddOutput:self.ImageOutPut]) { 160 | [self.session addOutput:self.ImageOutPut]; 161 | } 162 | 163 | //使用self.session,初始化预览层,self.session负责驱动input进行信息的采集,layer负责把图像渲染显示 164 | self.previewLayer = [[AVCaptureVideoPreviewLayer alloc]initWithSession:self.session]; 165 | self.previewLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); 166 | self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 167 | [self.layer addSublayer:self.previewLayer]; 168 | [self.layer insertSublayer:self.previewLayer atIndex:0]; 169 | 170 | //开始启动 171 | [self.session startRunning]; 172 | if ([_device lockForConfiguration:nil]) { 173 | if ([_device isFlashModeSupported:AVCaptureFlashModeAuto]) { 174 | [_device setFlashMode:AVCaptureFlashModeAuto]; 175 | } 176 | //自动白平衡 177 | if ([_device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) { 178 | [_device setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance]; 179 | } 180 | [_device unlockForConfiguration]; 181 | } 182 | 183 | 184 | UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(focusGesture:)]; 185 | [self addGestureRecognizer:tapGesture]; 186 | } 187 | 188 | #pragma mark - Action 189 | 190 | //聚焦手势 191 | - (void)focusGesture:(UITapGestureRecognizer*)gesture{ 192 | CGPoint point = [gesture locationInView:gesture.view]; 193 | 194 | CGSize size = gesture.view.bounds.size; 195 | CGPoint focusPoint = CGPointMake( point.y /size.height ,1-point.x/size.width ); 196 | NSError *error; 197 | if ([self.device lockForConfiguration:&error]) { 198 | 199 | if ([self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) { 200 | [self.device setFocusPointOfInterest:focusPoint]; 201 | [self.device setFocusMode:AVCaptureFocusModeAutoFocus]; 202 | } 203 | 204 | if ([self.device isExposureModeSupported:AVCaptureExposureModeAutoExpose ]) { 205 | [self.device setExposurePointOfInterest:focusPoint]; 206 | [self.device setExposureMode:AVCaptureExposureModeAutoExpose]; 207 | } 208 | 209 | [self.device unlockForConfiguration]; 210 | _focusView.center = point; 211 | _focusView.hidden = NO; 212 | [UIView animateWithDuration:0.3 animations:^{ 213 | _focusView.transform = CGAffineTransformMakeScale(1.25, 1.25); 214 | }completion:^(BOOL finished) { 215 | [UIView animateWithDuration:0.5 animations:^{ 216 | _focusView.transform = CGAffineTransformIdentity; 217 | } completion:^(BOOL finished) { 218 | _focusView.hidden = YES; 219 | }]; 220 | }]; 221 | } 222 | } 223 | 224 | /**切换闪光灯*/ 225 | - (void)switchLight:(LFCaptureFlashMode)flashMode { 226 | //必须判定是否有闪光灯,否则如果没有闪光灯会崩溃 227 | if ([self.device hasFlash]) { 228 | if ((AVCaptureFlashMode)flashMode == self.device.flashMode) { 229 | return; 230 | } 231 | //修改前必须先锁定 232 | [self.device lockForConfiguration:nil]; 233 | self.device.flashMode = (AVCaptureFlashMode)flashMode; 234 | self.device.torchMode = (AVCaptureTorchMode)flashMode; 235 | [self.device unlockForConfiguration]; 236 | [self.session commitConfiguration]; 237 | } 238 | } 239 | 240 | /**切换摄像头*/ 241 | - (void)switchCamera:(BOOL)isFront { 242 | // AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 243 | // if (authStatus != AVAuthorizationStatusAuthorized) { 244 | // return; 245 | // } 246 | //前后摄像头像素不一样,所以这里要处理下 247 | // if (isFront) { 248 | // if ([self.session canSetSessionPreset:AVCaptureSessionPreset640x480]) { 249 | // self.session.sessionPreset = AVCaptureSessionPreset640x480; 250 | // } 251 | // } else { 252 | // if ([self.session canSetSessionPreset:AVCaptureSessionPreset1920x1080]) { 253 | // self.session.sessionPreset = AVCaptureSessionPreset1920x1080; 254 | // } 255 | // } 256 | 257 | NSArray *inputs = self.session.inputs; 258 | for (AVCaptureDeviceInput *input in inputs ) { 259 | AVCaptureDevice *device = input.device; 260 | if ( [device hasMediaType:AVMediaTypeVideo] ) { 261 | AVCaptureDevicePosition position = isFront ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; 262 | AVCaptureDevice *newCamera = [self cameraWithPosition:position]; 263 | AVCaptureDeviceInput *newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil]; 264 | // beginConfiguration ensures that pending changes are not applied immediately 265 | [self.session beginConfiguration]; 266 | 267 | [self.session removeInput:input]; 268 | if (newInput) { 269 | [self.session addInput:newInput]; 270 | } 271 | 272 | // Changes take effect once the outermost commitConfiguration is invoked. 273 | [self.session commitConfiguration]; 274 | self.isFront = isFront; 275 | break; 276 | } 277 | } 278 | } 279 | 280 | - (void)takePhoto:(void (^)(UIImage *img))resultBlock { 281 | AVCaptureConnection * videoConnection = [self.ImageOutPut connectionWithMediaType:AVMediaTypeVideo]; 282 | if (!videoConnection) { 283 | NSLog(@"take photo failed!"); 284 | return; 285 | } 286 | 287 | if (videoConnection.isVideoOrientationSupported) { 288 | // if (self.effectiveRect.size.width < 1) {//无裁剪才支持方向,因为其他方向裁剪有问题 289 | videoConnection.videoOrientation = [self currentVideoOrientation]; 290 | // } 291 | } 292 | 293 | //如果是前摄像头,则加镜像 294 | if (self.isFront) { 295 | videoConnection.videoMirrored = YES; 296 | } else { 297 | videoConnection.videoMirrored = NO; 298 | } 299 | __weak typeof(self) weakSelf = self; 300 | [self.ImageOutPut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { 301 | if (imageDataSampleBuffer == NULL) { 302 | return; 303 | } 304 | NSData * imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; 305 | UIImage *img = [UIImage imageWithData:imageData]; 306 | [weakSelf.session stopRunning]; 307 | __block UIImage *wImage = img; 308 | dispatch_async(dispatch_get_main_queue(), ^{ 309 | if (weakSelf.effectiveRect.size.width > 0) { 310 | wImage = [weakSelf cutImage:wImage]; 311 | } 312 | if (resultBlock) { 313 | resultBlock(wImage); 314 | } 315 | }); 316 | }]; 317 | } 318 | 319 | #pragma mark - 方法 320 | 321 | //相机是否可用 322 | - (BOOL)canUseCamear{ 323 | AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 324 | if (authStatus == AVAuthorizationStatusAuthorized || authStatus == AVAuthorizationStatusNotDetermined) { 325 | return YES; 326 | } 327 | else{ 328 | return NO; 329 | } 330 | return YES; 331 | } 332 | 333 | /**配置拍摄范围*/ 334 | - (void)setupEffectiveRect{ 335 | [self.layer addSublayer: self.maskLayer]; 336 | [self.layer addSublayer: self.effectiveRectLayer]; 337 | } 338 | 339 | /**生成空缺部分rect的layer*/ 340 | - (UIBezierPath *)getMaskPathWithRect: (CGRect)rect exceptRect: (CGRect)exceptRect 341 | { 342 | if (!CGRectContainsRect(rect, exceptRect)) { 343 | return nil; 344 | } 345 | else if (CGRectEqualToRect(rect, CGRectZero)) { 346 | return nil; 347 | } 348 | 349 | CGFloat boundsInitX = CGRectGetMinX(rect); 350 | CGFloat boundsInitY = CGRectGetMinY(rect); 351 | CGFloat boundsWidth = CGRectGetWidth(rect); 352 | CGFloat boundsHeight = CGRectGetHeight(rect); 353 | 354 | CGFloat minX = CGRectGetMinX(exceptRect); 355 | CGFloat maxX = CGRectGetMaxX(exceptRect); 356 | CGFloat minY = CGRectGetMinY(exceptRect); 357 | CGFloat maxY = CGRectGetMaxY(exceptRect); 358 | CGFloat width = CGRectGetWidth(exceptRect); 359 | 360 | /** 添加路径*/ 361 | UIBezierPath * path = [UIBezierPath bezierPathWithRect: CGRectMake(boundsInitX, boundsInitY, minX, boundsHeight)]; 362 | [path appendPath: [UIBezierPath bezierPathWithRect: CGRectMake(minX, boundsInitY, width, minY)]]; 363 | [path appendPath: [UIBezierPath bezierPathWithRect: CGRectMake(maxX, boundsInitY, boundsWidth - maxX, boundsHeight)]]; 364 | [path appendPath: [UIBezierPath bezierPathWithRect: CGRectMake(minX, maxY, width, boundsHeight - maxY)]]; 365 | 366 | return path; 367 | } 368 | 369 | //生成相应方向的摄像头设备 370 | - (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position { 371 | NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; 372 | for (AVCaptureDevice *device in devices ) 373 | if ( device.position == position ) 374 | return device; 375 | return nil; 376 | } 377 | 378 | // 调整设备取向 379 | - (AVCaptureVideoOrientation)currentVideoOrientation{ 380 | AVCaptureVideoOrientation orientation; 381 | switch (self.deviceOrientation) { 382 | case UIDeviceOrientationPortrait: 383 | orientation = AVCaptureVideoOrientationPortrait; 384 | break; 385 | case UIDeviceOrientationLandscapeRight: 386 | orientation = AVCaptureVideoOrientationLandscapeLeft; 387 | break; 388 | case UIDeviceOrientationPortraitUpsideDown: 389 | orientation = AVCaptureVideoOrientationPortraitUpsideDown; 390 | break; 391 | default: 392 | orientation = AVCaptureVideoOrientationLandscapeRight; 393 | break; 394 | } 395 | return orientation; 396 | } 397 | 398 | /**获取摄像头方向*/ 399 | - (BOOL)isCameraFront { 400 | return self.isFront; 401 | } 402 | 403 | /**获取闪光灯模式*/ 404 | - (LFCaptureFlashMode)getCaptureFlashMode { 405 | return (LFCaptureFlashMode)self.device.torchMode; 406 | } 407 | 408 | //裁剪 409 | - (UIImage *)cutImage:(UIImage *)image { 410 | // NSLog(@"图片朝向%@",@(image.imageOrientation)); 411 | // image = [LFCamera fixOrientation:image]; 412 | //图片缩放比例 413 | float imageZoomRate = 1;//预览视图相对图片大小的缩放比例 414 | CGFloat offsetH = 0; 415 | CGFloat offsetW = 0; 416 | float orignY = self.effectiveRect.origin.y; 417 | float orignX = self.effectiveRect.origin.x; 418 | //相对图片高宽比例修正裁剪区(因为本控件高宽比不一定等于图片高宽比,而用户看到的裁剪框是相对本控件的) 419 | if (image.size.height > image.size.width) {//竖着拍 420 | if ((self.frame.size.height/self.frame.size.width) < (image.size.height/image.size.width)) {//本控件宽度刚好填满,高度超出 421 | imageZoomRate = self.frame.size.width/image.size.width; 422 | } else {//本控件高度刚好填满,宽度超出 423 | imageZoomRate = self.frame.size.height/image.size.height; 424 | } 425 | offsetH = image.size.height-self.frame.size.height/imageZoomRate; 426 | offsetW = image.size.width-self.frame.size.width/imageZoomRate; 427 | orignY = self.effectiveRect.origin.y/imageZoomRate + offsetH/2; 428 | orignX = self.effectiveRect.origin.x/imageZoomRate + offsetW/2; 429 | 430 | //当然这里可以写手机朝下的算法,但我拒绝为这种愚蠢行为写算法 431 | 432 | } else {//横着拍,图片的宽对应本控件的高 433 | if ((self.frame.size.height/self.frame.size.width) < (image.size.width/image.size.height)) {//本控件宽度刚好填满,高度超出 434 | imageZoomRate = self.frame.size.width/image.size.height; 435 | } else {//本控件高度刚好填满,宽度超出 436 | imageZoomRate = self.frame.size.height/image.size.width; 437 | } 438 | 439 | //手机顶部朝左 440 | offsetH = image.size.width-self.frame.size.height/imageZoomRate; 441 | offsetW = image.size.height-self.frame.size.width/imageZoomRate; 442 | orignY = (self.frame.size.width - self.effectiveRect.origin.x - self.effectiveRect.size.width)/imageZoomRate + offsetW/2; 443 | orignX = (self.effectiveRect.origin.y)/imageZoomRate + offsetH/2; 444 | 445 | //手机顶部朝右 446 | if (image.imageOrientation == 1 || image.imageOrientation == 4) { 447 | offsetH = image.size.width-self.frame.size.height/imageZoomRate; 448 | offsetW = image.size.height-self.frame.size.width/imageZoomRate; 449 | orignY = (self.effectiveRect.origin.x)/imageZoomRate + offsetW/2; 450 | orignX = (self.frame.size.height - self.effectiveRect.origin.y - self.effectiveRect.size.height)/imageZoomRate + offsetH/2; 451 | } 452 | } 453 | 454 | CGRect cutImageRect = CGRectZero; 455 | cutImageRect.origin.x = orignX; 456 | cutImageRect.origin.y = orignY; 457 | cutImageRect.size.width = self.effectiveRect.size.width/imageZoomRate; 458 | cutImageRect.size.height = self.effectiveRect.size.height/imageZoomRate; 459 | 460 | // 得到图片上下文,指定绘制范围 461 | UIGraphicsBeginImageContext(image.size); 462 | 463 | // 将图片按照指定大小绘制 464 | [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 465 | 466 | // 从当前图片上下文中导出图片 467 | UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 468 | 469 | // 当前图片上下文出栈 470 | UIGraphicsEndImageContext(); 471 | 472 | //将UIImage转换成CGImageRef 473 | CGImageRef sourceImageRef = [scaledImage CGImage]; 474 | 475 | //按照给定的矩形区域进行剪裁 476 | CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, cutImageRect); 477 | 478 | //将CGImageRef转换成UIImage 479 | UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; 480 | return newImage; 481 | 482 | } 483 | 484 | + (UIImage *)fixOrientation:(UIImage *)aImage { 485 | 486 | // No-op if the orientation is already correct 487 | if (aImage.imageOrientation ==UIImageOrientationUp) 488 | return aImage; 489 | 490 | // We need to calculate the proper transformation to make the image upright. 491 | // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. 492 | CGAffineTransform transform =CGAffineTransformIdentity; 493 | 494 | switch (aImage.imageOrientation) { 495 | case UIImageOrientationDown: 496 | case UIImageOrientationDownMirrored: 497 | transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height); 498 | transform = CGAffineTransformRotate(transform, M_PI); 499 | break; 500 | 501 | case UIImageOrientationLeft: 502 | case UIImageOrientationLeftMirrored: 503 | transform = CGAffineTransformTranslate(transform, aImage.size.width,0); 504 | transform = CGAffineTransformRotate(transform, M_PI_2); 505 | break; 506 | 507 | case UIImageOrientationRight: 508 | case UIImageOrientationRightMirrored: 509 | transform = CGAffineTransformTranslate(transform, 0, aImage.size.height); 510 | transform = CGAffineTransformRotate(transform, -M_PI_2); 511 | break; 512 | default: 513 | break; 514 | } 515 | 516 | switch (aImage.imageOrientation) { 517 | case UIImageOrientationUpMirrored: 518 | case UIImageOrientationDownMirrored: 519 | transform = CGAffineTransformTranslate(transform, aImage.size.width,0); 520 | transform = CGAffineTransformScale(transform, -1, 1); 521 | break; 522 | 523 | case UIImageOrientationLeftMirrored: 524 | case UIImageOrientationRightMirrored: 525 | transform = CGAffineTransformTranslate(transform, aImage.size.height,0); 526 | transform = CGAffineTransformScale(transform, -1, 1); 527 | break; 528 | default: 529 | break; 530 | } 531 | 532 | // Now we draw the underlying CGImage into a new context, applying the transform 533 | // calculated above. 534 | CGContextRef ctx =CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height, 535 | CGImageGetBitsPerComponent(aImage.CGImage),0, 536 | CGImageGetColorSpace(aImage.CGImage), 537 | CGImageGetBitmapInfo(aImage.CGImage)); 538 | CGContextConcatCTM(ctx, transform); 539 | switch (aImage.imageOrientation) { 540 | case UIImageOrientationLeft: 541 | case UIImageOrientationLeftMirrored: 542 | case UIImageOrientationRight: 543 | case UIImageOrientationRightMirrored: 544 | // Grr... 545 | CGContextDrawImage(ctx,CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage); 546 | break; 547 | 548 | default: 549 | CGContextDrawImage(ctx,CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage); 550 | break; 551 | } 552 | 553 | // And now we just create a new UIImage from the drawing context 554 | CGImageRef cgimg =CGBitmapContextCreateImage(ctx); 555 | UIImage *img = [UIImage imageWithCGImage:cgimg]; 556 | CGContextRelease(ctx); 557 | CGImageRelease(cgimg); 558 | return img; 559 | } 560 | 561 | - (void)restart { 562 | [self.session startRunning]; 563 | } 564 | 565 | #pragma mark - 手势缩放焦距 566 | //缩放手势 用于调整焦距 567 | - (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer{ 568 | 569 | BOOL allTouchesAreOnThePreviewLayer = YES; 570 | NSUInteger numTouches = [recognizer numberOfTouches]; 571 | for (NSInteger i = 0; i < numTouches; ++i ) { 572 | CGPoint location = [recognizer locationOfTouch:i inView:self]; 573 | CGPoint convertedLocation = [self.previewLayer convertPoint:location fromLayer:self.previewLayer.superlayer]; 574 | if ( ! [self.previewLayer containsPoint:convertedLocation] ) { 575 | allTouchesAreOnThePreviewLayer = NO; 576 | break; 577 | } 578 | } 579 | 580 | if ( allTouchesAreOnThePreviewLayer ) { 581 | 582 | 583 | self.effectiveScale = self.beginGestureScale * recognizer.scale; 584 | if (self.effectiveScale < 1.0){ 585 | self.effectiveScale = 1.0; 586 | } 587 | 588 | CGFloat maxScaleAndCropFactor = [[self.ImageOutPut connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor]; 589 | 590 | if (self.effectiveScale > maxScaleAndCropFactor) { 591 | self.effectiveScale = maxScaleAndCropFactor; 592 | } 593 | 594 | [CATransaction begin]; 595 | [CATransaction setAnimationDuration:.025]; 596 | [self.previewLayer setAffineTransform:CGAffineTransformMakeScale(self.effectiveScale, self.effectiveScale)]; 597 | [CATransaction commit]; 598 | } 599 | 600 | } 601 | 602 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 603 | { 604 | if ( [gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] ) { 605 | self.beginGestureScale = self.effectiveScale; 606 | } 607 | return YES; 608 | } 609 | 610 | #pragma mark - 懒加载 611 | 612 | /** 有效区域框*/ 613 | - (CAShapeLayer *)effectiveRectLayer { 614 | if (!_effectiveRectLayer) { 615 | CGRect scanRect = self.effectiveRect; 616 | scanRect.origin.x -= 1; 617 | scanRect.origin.y -= 1; 618 | scanRect.size.width += 2; 619 | scanRect.size.height += 2; 620 | 621 | _effectiveRectLayer = [CAShapeLayer layer]; 622 | _effectiveRectLayer.path = [UIBezierPath bezierPathWithRect:scanRect].CGPath; 623 | _effectiveRectLayer.fillColor = [UIColor clearColor].CGColor; 624 | _effectiveRectLayer.strokeColor = self.effectiveRectBorderColor.CGColor; 625 | } 626 | return _effectiveRectLayer; 627 | } 628 | 629 | 630 | /**黑色半透明遮掩层*/ 631 | - (CAShapeLayer *)maskLayer { 632 | if (!_maskLayer) { 633 | _maskLayer = [CAShapeLayer layer]; 634 | _maskLayer.path = [self getMaskPathWithRect:self.bounds exceptRect:self.effectiveRect].CGPath; 635 | _maskLayer.fillColor = self.maskColor.CGColor; 636 | } 637 | return _maskLayer; 638 | } 639 | 640 | - (UIView *)focusView { 641 | if (!_focusView) { 642 | _focusView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)]; 643 | _focusView.backgroundColor = [UIColor clearColor]; 644 | _focusView.layer.borderColor = [UIColor greenColor].CGColor; 645 | _focusView.layer.borderWidth = 1; 646 | _focusView.hidden = YES; 647 | } 648 | return _focusView; 649 | } 650 | 651 | 652 | @end 653 | -------------------------------------------------------------------------------- /LFCamera.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 27700F3D20C87050F3ECF0D6 /* libPods-LFCamera.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AC6615042509FD311FC5344C /* libPods-LFCamera.a */; }; 11 | D13A38091EAE266400811885 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A38081EAE266400811885 /* main.m */; }; 12 | D13A380C1EAE266400811885 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A380B1EAE266400811885 /* AppDelegate.m */; }; 13 | D13A380F1EAE266400811885 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A380E1EAE266400811885 /* ViewController.m */; }; 14 | D13A38121EAE266400811885 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D13A38101EAE266400811885 /* Main.storyboard */; }; 15 | D13A38141EAE266400811885 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D13A38131EAE266400811885 /* Assets.xcassets */; }; 16 | D13A38171EAE266400811885 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D13A38151EAE266400811885 /* LaunchScreen.storyboard */; }; 17 | D13A38221EAE266400811885 /* LFCameraTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A38211EAE266400811885 /* LFCameraTests.m */; }; 18 | D13A382D1EAE266400811885 /* LFCameraUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A382C1EAE266400811885 /* LFCameraUITests.m */; }; 19 | D13A38401EAE278300811885 /* LFCameraResultView.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A383E1EAE278300811885 /* LFCameraResultView.m */; }; 20 | D13A38461EAEE96F00811885 /* LFCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = D13A38451EAEE96F00811885 /* LFCamera.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | D13A381E1EAE266400811885 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = D13A37FC1EAE266300811885 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = D13A38031EAE266400811885; 29 | remoteInfo = LFCamera; 30 | }; 31 | D13A38291EAE266400811885 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = D13A37FC1EAE266300811885 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = D13A38031EAE266400811885; 36 | remoteInfo = LFCamera; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 5A84422769F183F02E9D6618 /* Pods-LFCamera.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFCamera.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera.debug.xcconfig"; sourceTree = ""; }; 42 | 765B3A2D2C4FAC0B76687BD1 /* Pods-LFCamera.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFCamera.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera.release.xcconfig"; sourceTree = ""; }; 43 | AC6615042509FD311FC5344C /* libPods-LFCamera.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFCamera.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | D13A38041EAE266400811885 /* LFCamera.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFCamera.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | D13A38081EAE266400811885 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 46 | D13A380A1EAE266400811885 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 47 | D13A380B1EAE266400811885 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 48 | D13A380D1EAE266400811885 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 49 | D13A380E1EAE266400811885 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 50 | D13A38111EAE266400811885 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | D13A38131EAE266400811885 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | D13A38161EAE266400811885 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | D13A38181EAE266400811885 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | D13A381D1EAE266400811885 /* LFCameraTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LFCameraTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | D13A38211EAE266400811885 /* LFCameraTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LFCameraTests.m; sourceTree = ""; }; 56 | D13A38231EAE266400811885 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | D13A38281EAE266400811885 /* LFCameraUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LFCameraUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | D13A382C1EAE266400811885 /* LFCameraUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LFCameraUITests.m; sourceTree = ""; }; 59 | D13A382E1EAE266400811885 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 60 | D13A383E1EAE278300811885 /* LFCameraResultView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFCameraResultView.m; sourceTree = ""; }; 61 | D13A383F1EAE278300811885 /* LFCameraResultView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFCameraResultView.h; sourceTree = ""; }; 62 | D13A38441EAEE96F00811885 /* LFCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFCamera.h; sourceTree = ""; }; 63 | D13A38451EAEE96F00811885 /* LFCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFCamera.m; sourceTree = ""; }; 64 | D13A38471EAEF5C300811885 /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | D13A38011EAE266400811885 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | 27700F3D20C87050F3ECF0D6 /* libPods-LFCamera.a in Frameworks */, 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | D13A381A1EAE266400811885 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | D13A38251EAE266400811885 /* Frameworks */ = { 84 | isa = PBXFrameworksBuildPhase; 85 | buildActionMask = 2147483647; 86 | files = ( 87 | ); 88 | runOnlyForDeploymentPostprocessing = 0; 89 | }; 90 | /* End PBXFrameworksBuildPhase section */ 91 | 92 | /* Begin PBXGroup section */ 93 | 3EED0B5D30B4699046E52D59 /* Frameworks */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | AC6615042509FD311FC5344C /* libPods-LFCamera.a */, 97 | ); 98 | name = Frameworks; 99 | sourceTree = ""; 100 | }; 101 | B0C80B840FD10DBC84589A5C /* Pods */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 5A84422769F183F02E9D6618 /* Pods-LFCamera.debug.xcconfig */, 105 | 765B3A2D2C4FAC0B76687BD1 /* Pods-LFCamera.release.xcconfig */, 106 | ); 107 | name = Pods; 108 | sourceTree = ""; 109 | }; 110 | D13A37FB1EAE266300811885 = { 111 | isa = PBXGroup; 112 | children = ( 113 | D13A38061EAE266400811885 /* LFCamera */, 114 | D13A38201EAE266400811885 /* LFCameraTests */, 115 | D13A382B1EAE266400811885 /* LFCameraUITests */, 116 | D13A38051EAE266400811885 /* Products */, 117 | B0C80B840FD10DBC84589A5C /* Pods */, 118 | 3EED0B5D30B4699046E52D59 /* Frameworks */, 119 | ); 120 | sourceTree = ""; 121 | }; 122 | D13A38051EAE266400811885 /* Products */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | D13A38041EAE266400811885 /* LFCamera.app */, 126 | D13A381D1EAE266400811885 /* LFCameraTests.xctest */, 127 | D13A38281EAE266400811885 /* LFCameraUITests.xctest */, 128 | ); 129 | name = Products; 130 | sourceTree = ""; 131 | }; 132 | D13A38061EAE266400811885 /* LFCamera */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | D13A383A1EAE26EA00811885 /* LFCamera */, 136 | D13A380A1EAE266400811885 /* AppDelegate.h */, 137 | D13A380B1EAE266400811885 /* AppDelegate.m */, 138 | D13A380D1EAE266400811885 /* ViewController.h */, 139 | D13A380E1EAE266400811885 /* ViewController.m */, 140 | D13A38101EAE266400811885 /* Main.storyboard */, 141 | D13A38131EAE266400811885 /* Assets.xcassets */, 142 | D13A38151EAE266400811885 /* LaunchScreen.storyboard */, 143 | D13A38181EAE266400811885 /* Info.plist */, 144 | D13A38071EAE266400811885 /* Supporting Files */, 145 | ); 146 | path = LFCamera; 147 | sourceTree = ""; 148 | }; 149 | D13A38071EAE266400811885 /* Supporting Files */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | D13A38081EAE266400811885 /* main.m */, 153 | D13A38471EAEF5C300811885 /* PrefixHeader.pch */, 154 | ); 155 | name = "Supporting Files"; 156 | sourceTree = ""; 157 | }; 158 | D13A38201EAE266400811885 /* LFCameraTests */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | D13A38211EAE266400811885 /* LFCameraTests.m */, 162 | D13A38231EAE266400811885 /* Info.plist */, 163 | ); 164 | path = LFCameraTests; 165 | sourceTree = ""; 166 | }; 167 | D13A382B1EAE266400811885 /* LFCameraUITests */ = { 168 | isa = PBXGroup; 169 | children = ( 170 | D13A382C1EAE266400811885 /* LFCameraUITests.m */, 171 | D13A382E1EAE266400811885 /* Info.plist */, 172 | ); 173 | path = LFCameraUITests; 174 | sourceTree = ""; 175 | }; 176 | D13A383A1EAE26EA00811885 /* LFCamera */ = { 177 | isa = PBXGroup; 178 | children = ( 179 | D13A38441EAEE96F00811885 /* LFCamera.h */, 180 | D13A38451EAEE96F00811885 /* LFCamera.m */, 181 | D13A383F1EAE278300811885 /* LFCameraResultView.h */, 182 | D13A383E1EAE278300811885 /* LFCameraResultView.m */, 183 | ); 184 | path = LFCamera; 185 | sourceTree = ""; 186 | }; 187 | /* End PBXGroup section */ 188 | 189 | /* Begin PBXNativeTarget section */ 190 | D13A38031EAE266400811885 /* LFCamera */ = { 191 | isa = PBXNativeTarget; 192 | buildConfigurationList = D13A38311EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCamera" */; 193 | buildPhases = ( 194 | 0E4D22BA8ED065882D08DCD5 /* [CP] Check Pods Manifest.lock */, 195 | D13A38001EAE266400811885 /* Sources */, 196 | D13A38011EAE266400811885 /* Frameworks */, 197 | D13A38021EAE266400811885 /* Resources */, 198 | E34FB6A5E041061947EB6D35 /* [CP] Embed Pods Frameworks */, 199 | 41FC4387250BEA460C87DBCD /* [CP] Copy Pods Resources */, 200 | ); 201 | buildRules = ( 202 | ); 203 | dependencies = ( 204 | ); 205 | name = LFCamera; 206 | productName = LFCamera; 207 | productReference = D13A38041EAE266400811885 /* LFCamera.app */; 208 | productType = "com.apple.product-type.application"; 209 | }; 210 | D13A381C1EAE266400811885 /* LFCameraTests */ = { 211 | isa = PBXNativeTarget; 212 | buildConfigurationList = D13A38341EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCameraTests" */; 213 | buildPhases = ( 214 | D13A38191EAE266400811885 /* Sources */, 215 | D13A381A1EAE266400811885 /* Frameworks */, 216 | D13A381B1EAE266400811885 /* Resources */, 217 | ); 218 | buildRules = ( 219 | ); 220 | dependencies = ( 221 | D13A381F1EAE266400811885 /* PBXTargetDependency */, 222 | ); 223 | name = LFCameraTests; 224 | productName = LFCameraTests; 225 | productReference = D13A381D1EAE266400811885 /* LFCameraTests.xctest */; 226 | productType = "com.apple.product-type.bundle.unit-test"; 227 | }; 228 | D13A38271EAE266400811885 /* LFCameraUITests */ = { 229 | isa = PBXNativeTarget; 230 | buildConfigurationList = D13A38371EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCameraUITests" */; 231 | buildPhases = ( 232 | D13A38241EAE266400811885 /* Sources */, 233 | D13A38251EAE266400811885 /* Frameworks */, 234 | D13A38261EAE266400811885 /* Resources */, 235 | ); 236 | buildRules = ( 237 | ); 238 | dependencies = ( 239 | D13A382A1EAE266400811885 /* PBXTargetDependency */, 240 | ); 241 | name = LFCameraUITests; 242 | productName = LFCameraUITests; 243 | productReference = D13A38281EAE266400811885 /* LFCameraUITests.xctest */; 244 | productType = "com.apple.product-type.bundle.ui-testing"; 245 | }; 246 | /* End PBXNativeTarget section */ 247 | 248 | /* Begin PBXProject section */ 249 | D13A37FC1EAE266300811885 /* Project object */ = { 250 | isa = PBXProject; 251 | attributes = { 252 | LastUpgradeCheck = 0830; 253 | ORGANIZATIONNAME = "张林峰"; 254 | TargetAttributes = { 255 | D13A38031EAE266400811885 = { 256 | CreatedOnToolsVersion = 8.3.1; 257 | DevelopmentTeam = D975HMHLA6; 258 | ProvisioningStyle = Automatic; 259 | }; 260 | D13A381C1EAE266400811885 = { 261 | CreatedOnToolsVersion = 8.3.1; 262 | ProvisioningStyle = Automatic; 263 | TestTargetID = D13A38031EAE266400811885; 264 | }; 265 | D13A38271EAE266400811885 = { 266 | CreatedOnToolsVersion = 8.3.1; 267 | ProvisioningStyle = Automatic; 268 | TestTargetID = D13A38031EAE266400811885; 269 | }; 270 | }; 271 | }; 272 | buildConfigurationList = D13A37FF1EAE266300811885 /* Build configuration list for PBXProject "LFCamera" */; 273 | compatibilityVersion = "Xcode 3.2"; 274 | developmentRegion = English; 275 | hasScannedForEncodings = 0; 276 | knownRegions = ( 277 | en, 278 | Base, 279 | ); 280 | mainGroup = D13A37FB1EAE266300811885; 281 | productRefGroup = D13A38051EAE266400811885 /* Products */; 282 | projectDirPath = ""; 283 | projectRoot = ""; 284 | targets = ( 285 | D13A38031EAE266400811885 /* LFCamera */, 286 | D13A381C1EAE266400811885 /* LFCameraTests */, 287 | D13A38271EAE266400811885 /* LFCameraUITests */, 288 | ); 289 | }; 290 | /* End PBXProject section */ 291 | 292 | /* Begin PBXResourcesBuildPhase section */ 293 | D13A38021EAE266400811885 /* Resources */ = { 294 | isa = PBXResourcesBuildPhase; 295 | buildActionMask = 2147483647; 296 | files = ( 297 | D13A38171EAE266400811885 /* LaunchScreen.storyboard in Resources */, 298 | D13A38141EAE266400811885 /* Assets.xcassets in Resources */, 299 | D13A38121EAE266400811885 /* Main.storyboard in Resources */, 300 | ); 301 | runOnlyForDeploymentPostprocessing = 0; 302 | }; 303 | D13A381B1EAE266400811885 /* Resources */ = { 304 | isa = PBXResourcesBuildPhase; 305 | buildActionMask = 2147483647; 306 | files = ( 307 | ); 308 | runOnlyForDeploymentPostprocessing = 0; 309 | }; 310 | D13A38261EAE266400811885 /* Resources */ = { 311 | isa = PBXResourcesBuildPhase; 312 | buildActionMask = 2147483647; 313 | files = ( 314 | ); 315 | runOnlyForDeploymentPostprocessing = 0; 316 | }; 317 | /* End PBXResourcesBuildPhase section */ 318 | 319 | /* Begin PBXShellScriptBuildPhase section */ 320 | 0E4D22BA8ED065882D08DCD5 /* [CP] Check Pods Manifest.lock */ = { 321 | isa = PBXShellScriptBuildPhase; 322 | buildActionMask = 2147483647; 323 | files = ( 324 | ); 325 | inputPaths = ( 326 | ); 327 | name = "[CP] Check Pods Manifest.lock"; 328 | outputPaths = ( 329 | ); 330 | runOnlyForDeploymentPostprocessing = 0; 331 | shellPath = /bin/sh; 332 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; 333 | showEnvVarsInLog = 0; 334 | }; 335 | 41FC4387250BEA460C87DBCD /* [CP] Copy Pods Resources */ = { 336 | isa = PBXShellScriptBuildPhase; 337 | buildActionMask = 2147483647; 338 | files = ( 339 | ); 340 | inputPaths = ( 341 | ); 342 | name = "[CP] Copy Pods Resources"; 343 | outputPaths = ( 344 | ); 345 | runOnlyForDeploymentPostprocessing = 0; 346 | shellPath = /bin/sh; 347 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-resources.sh\"\n"; 348 | showEnvVarsInLog = 0; 349 | }; 350 | E34FB6A5E041061947EB6D35 /* [CP] Embed Pods Frameworks */ = { 351 | isa = PBXShellScriptBuildPhase; 352 | buildActionMask = 2147483647; 353 | files = ( 354 | ); 355 | inputPaths = ( 356 | ); 357 | name = "[CP] Embed Pods Frameworks"; 358 | outputPaths = ( 359 | ); 360 | runOnlyForDeploymentPostprocessing = 0; 361 | shellPath = /bin/sh; 362 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFCamera/Pods-LFCamera-frameworks.sh\"\n"; 363 | showEnvVarsInLog = 0; 364 | }; 365 | /* End PBXShellScriptBuildPhase section */ 366 | 367 | /* Begin PBXSourcesBuildPhase section */ 368 | D13A38001EAE266400811885 /* Sources */ = { 369 | isa = PBXSourcesBuildPhase; 370 | buildActionMask = 2147483647; 371 | files = ( 372 | D13A38461EAEE96F00811885 /* LFCamera.m in Sources */, 373 | D13A380F1EAE266400811885 /* ViewController.m in Sources */, 374 | D13A38401EAE278300811885 /* LFCameraResultView.m in Sources */, 375 | D13A380C1EAE266400811885 /* AppDelegate.m in Sources */, 376 | D13A38091EAE266400811885 /* main.m in Sources */, 377 | ); 378 | runOnlyForDeploymentPostprocessing = 0; 379 | }; 380 | D13A38191EAE266400811885 /* Sources */ = { 381 | isa = PBXSourcesBuildPhase; 382 | buildActionMask = 2147483647; 383 | files = ( 384 | D13A38221EAE266400811885 /* LFCameraTests.m in Sources */, 385 | ); 386 | runOnlyForDeploymentPostprocessing = 0; 387 | }; 388 | D13A38241EAE266400811885 /* Sources */ = { 389 | isa = PBXSourcesBuildPhase; 390 | buildActionMask = 2147483647; 391 | files = ( 392 | D13A382D1EAE266400811885 /* LFCameraUITests.m in Sources */, 393 | ); 394 | runOnlyForDeploymentPostprocessing = 0; 395 | }; 396 | /* End PBXSourcesBuildPhase section */ 397 | 398 | /* Begin PBXTargetDependency section */ 399 | D13A381F1EAE266400811885 /* PBXTargetDependency */ = { 400 | isa = PBXTargetDependency; 401 | target = D13A38031EAE266400811885 /* LFCamera */; 402 | targetProxy = D13A381E1EAE266400811885 /* PBXContainerItemProxy */; 403 | }; 404 | D13A382A1EAE266400811885 /* PBXTargetDependency */ = { 405 | isa = PBXTargetDependency; 406 | target = D13A38031EAE266400811885 /* LFCamera */; 407 | targetProxy = D13A38291EAE266400811885 /* PBXContainerItemProxy */; 408 | }; 409 | /* End PBXTargetDependency section */ 410 | 411 | /* Begin PBXVariantGroup section */ 412 | D13A38101EAE266400811885 /* Main.storyboard */ = { 413 | isa = PBXVariantGroup; 414 | children = ( 415 | D13A38111EAE266400811885 /* Base */, 416 | ); 417 | name = Main.storyboard; 418 | sourceTree = ""; 419 | }; 420 | D13A38151EAE266400811885 /* LaunchScreen.storyboard */ = { 421 | isa = PBXVariantGroup; 422 | children = ( 423 | D13A38161EAE266400811885 /* Base */, 424 | ); 425 | name = LaunchScreen.storyboard; 426 | sourceTree = ""; 427 | }; 428 | /* End PBXVariantGroup section */ 429 | 430 | /* Begin XCBuildConfiguration section */ 431 | D13A382F1EAE266400811885 /* Debug */ = { 432 | isa = XCBuildConfiguration; 433 | buildSettings = { 434 | ALWAYS_SEARCH_USER_PATHS = NO; 435 | CLANG_ANALYZER_NONNULL = YES; 436 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 437 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 438 | CLANG_CXX_LIBRARY = "libc++"; 439 | CLANG_ENABLE_MODULES = YES; 440 | CLANG_ENABLE_OBJC_ARC = YES; 441 | CLANG_WARN_BOOL_CONVERSION = YES; 442 | CLANG_WARN_CONSTANT_CONVERSION = YES; 443 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 444 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 445 | CLANG_WARN_EMPTY_BODY = YES; 446 | CLANG_WARN_ENUM_CONVERSION = YES; 447 | CLANG_WARN_INFINITE_RECURSION = YES; 448 | CLANG_WARN_INT_CONVERSION = YES; 449 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 450 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 451 | CLANG_WARN_UNREACHABLE_CODE = YES; 452 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 453 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 454 | COPY_PHASE_STRIP = NO; 455 | DEBUG_INFORMATION_FORMAT = dwarf; 456 | ENABLE_STRICT_OBJC_MSGSEND = YES; 457 | ENABLE_TESTABILITY = YES; 458 | GCC_C_LANGUAGE_STANDARD = gnu99; 459 | GCC_DYNAMIC_NO_PIC = NO; 460 | GCC_NO_COMMON_BLOCKS = YES; 461 | GCC_OPTIMIZATION_LEVEL = 0; 462 | GCC_PREPROCESSOR_DEFINITIONS = ( 463 | "DEBUG=1", 464 | "$(inherited)", 465 | ); 466 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 467 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 468 | GCC_WARN_UNDECLARED_SELECTOR = YES; 469 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 470 | GCC_WARN_UNUSED_FUNCTION = YES; 471 | GCC_WARN_UNUSED_VARIABLE = YES; 472 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 473 | MTL_ENABLE_DEBUG_INFO = YES; 474 | ONLY_ACTIVE_ARCH = YES; 475 | SDKROOT = iphoneos; 476 | TARGETED_DEVICE_FAMILY = "1,2"; 477 | }; 478 | name = Debug; 479 | }; 480 | D13A38301EAE266400811885 /* Release */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | ALWAYS_SEARCH_USER_PATHS = NO; 484 | CLANG_ANALYZER_NONNULL = YES; 485 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 486 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 487 | CLANG_CXX_LIBRARY = "libc++"; 488 | CLANG_ENABLE_MODULES = YES; 489 | CLANG_ENABLE_OBJC_ARC = YES; 490 | CLANG_WARN_BOOL_CONVERSION = YES; 491 | CLANG_WARN_CONSTANT_CONVERSION = YES; 492 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 493 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 494 | CLANG_WARN_EMPTY_BODY = YES; 495 | CLANG_WARN_ENUM_CONVERSION = YES; 496 | CLANG_WARN_INFINITE_RECURSION = YES; 497 | CLANG_WARN_INT_CONVERSION = YES; 498 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 499 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 500 | CLANG_WARN_UNREACHABLE_CODE = YES; 501 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 502 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 503 | COPY_PHASE_STRIP = NO; 504 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 505 | ENABLE_NS_ASSERTIONS = NO; 506 | ENABLE_STRICT_OBJC_MSGSEND = YES; 507 | GCC_C_LANGUAGE_STANDARD = gnu99; 508 | GCC_NO_COMMON_BLOCKS = YES; 509 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 510 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 511 | GCC_WARN_UNDECLARED_SELECTOR = YES; 512 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 513 | GCC_WARN_UNUSED_FUNCTION = YES; 514 | GCC_WARN_UNUSED_VARIABLE = YES; 515 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 516 | MTL_ENABLE_DEBUG_INFO = NO; 517 | SDKROOT = iphoneos; 518 | TARGETED_DEVICE_FAMILY = "1,2"; 519 | VALIDATE_PRODUCT = YES; 520 | }; 521 | name = Release; 522 | }; 523 | D13A38321EAE266400811885 /* Debug */ = { 524 | isa = XCBuildConfiguration; 525 | baseConfigurationReference = 5A84422769F183F02E9D6618 /* Pods-LFCamera.debug.xcconfig */; 526 | buildSettings = { 527 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 528 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 529 | DEVELOPMENT_TEAM = D975HMHLA6; 530 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 531 | GCC_PREFIX_HEADER = "$(SRCROOT)/LFCamera/PrefixHeader.pch"; 532 | INFOPLIST_FILE = LFCamera/Info.plist; 533 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 534 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 535 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCamera1; 536 | PRODUCT_NAME = "$(TARGET_NAME)"; 537 | PROVISIONING_PROFILE_SPECIFIER = ""; 538 | }; 539 | name = Debug; 540 | }; 541 | D13A38331EAE266400811885 /* Release */ = { 542 | isa = XCBuildConfiguration; 543 | baseConfigurationReference = 765B3A2D2C4FAC0B76687BD1 /* Pods-LFCamera.release.xcconfig */; 544 | buildSettings = { 545 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 546 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 547 | DEVELOPMENT_TEAM = D975HMHLA6; 548 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 549 | GCC_PREFIX_HEADER = "$(SRCROOT)/LFCamera/PrefixHeader.pch"; 550 | INFOPLIST_FILE = LFCamera/Info.plist; 551 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 552 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 553 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCamera1; 554 | PRODUCT_NAME = "$(TARGET_NAME)"; 555 | PROVISIONING_PROFILE_SPECIFIER = ""; 556 | }; 557 | name = Release; 558 | }; 559 | D13A38351EAE266400811885 /* Debug */ = { 560 | isa = XCBuildConfiguration; 561 | buildSettings = { 562 | BUNDLE_LOADER = "$(TEST_HOST)"; 563 | INFOPLIST_FILE = LFCameraTests/Info.plist; 564 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 565 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCameraTests; 566 | PRODUCT_NAME = "$(TARGET_NAME)"; 567 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LFCamera.app/LFCamera"; 568 | }; 569 | name = Debug; 570 | }; 571 | D13A38361EAE266400811885 /* Release */ = { 572 | isa = XCBuildConfiguration; 573 | buildSettings = { 574 | BUNDLE_LOADER = "$(TEST_HOST)"; 575 | INFOPLIST_FILE = LFCameraTests/Info.plist; 576 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 577 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCameraTests; 578 | PRODUCT_NAME = "$(TARGET_NAME)"; 579 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LFCamera.app/LFCamera"; 580 | }; 581 | name = Release; 582 | }; 583 | D13A38381EAE266400811885 /* Debug */ = { 584 | isa = XCBuildConfiguration; 585 | buildSettings = { 586 | INFOPLIST_FILE = LFCameraUITests/Info.plist; 587 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 588 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCameraUITests; 589 | PRODUCT_NAME = "$(TARGET_NAME)"; 590 | TEST_TARGET_NAME = LFCamera; 591 | }; 592 | name = Debug; 593 | }; 594 | D13A38391EAE266400811885 /* Release */ = { 595 | isa = XCBuildConfiguration; 596 | buildSettings = { 597 | INFOPLIST_FILE = LFCameraUITests/Info.plist; 598 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 599 | PRODUCT_BUNDLE_IDENTIFIER = com.zlf.LFCameraUITests; 600 | PRODUCT_NAME = "$(TARGET_NAME)"; 601 | TEST_TARGET_NAME = LFCamera; 602 | }; 603 | name = Release; 604 | }; 605 | /* End XCBuildConfiguration section */ 606 | 607 | /* Begin XCConfigurationList section */ 608 | D13A37FF1EAE266300811885 /* Build configuration list for PBXProject "LFCamera" */ = { 609 | isa = XCConfigurationList; 610 | buildConfigurations = ( 611 | D13A382F1EAE266400811885 /* Debug */, 612 | D13A38301EAE266400811885 /* Release */, 613 | ); 614 | defaultConfigurationIsVisible = 0; 615 | defaultConfigurationName = Release; 616 | }; 617 | D13A38311EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCamera" */ = { 618 | isa = XCConfigurationList; 619 | buildConfigurations = ( 620 | D13A38321EAE266400811885 /* Debug */, 621 | D13A38331EAE266400811885 /* Release */, 622 | ); 623 | defaultConfigurationIsVisible = 0; 624 | defaultConfigurationName = Release; 625 | }; 626 | D13A38341EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCameraTests" */ = { 627 | isa = XCConfigurationList; 628 | buildConfigurations = ( 629 | D13A38351EAE266400811885 /* Debug */, 630 | D13A38361EAE266400811885 /* Release */, 631 | ); 632 | defaultConfigurationIsVisible = 0; 633 | defaultConfigurationName = Release; 634 | }; 635 | D13A38371EAE266400811885 /* Build configuration list for PBXNativeTarget "LFCameraUITests" */ = { 636 | isa = XCConfigurationList; 637 | buildConfigurations = ( 638 | D13A38381EAE266400811885 /* Debug */, 639 | D13A38391EAE266400811885 /* Release */, 640 | ); 641 | defaultConfigurationIsVisible = 0; 642 | defaultConfigurationName = Release; 643 | }; 644 | /* End XCConfigurationList section */ 645 | }; 646 | rootObject = D13A37FC1EAE266300811885 /* Project object */; 647 | } 648 | --------------------------------------------------------------------------------