Skip to content

Commit

Permalink
1. fix #141
Browse files Browse the repository at this point in the history
2. 删除多余代码,优化部分逻辑
  • Loading branch information
longitachi committed Nov 15, 2017
1 parent 9735535 commit 2a1dc97
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 66 deletions.
59 changes: 9 additions & 50 deletions PhotoBrowser/ZLCustomCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ - (void)onFinishRecord;
重新拍照或录制
*/
- (void)onRetake;
/**
调整焦距
*/
- (void)onAdjustFocus:(CGFloat)zoomFactor;
/**
点击确定
*/
Expand All @@ -50,10 +46,8 @@ - (void)onDismiss;

@interface CameraToolView : UIView <CAAnimationDelegate, UIGestureRecognizerDelegate>
{
//避免动画及长按收拾触发两次
//避免动画及长按手势触发两次
BOOL _stopRecord;
//是否触发了长按手势的录制,如果触发,则pan手势有效
BOOL _hadTriggerRecord;
BOOL _layoutOK;
}

Expand Down Expand Up @@ -104,6 +98,7 @@ - (void)layoutSubviews
{
[super layoutSubviews];
if (_layoutOK) return;

_layoutOK = YES;
CGFloat height = GetViewHeight(self);
self.bottomView.frame = CGRectMake(0, 0, height*kBottomViewScale, height*kBottomViewScale);
Expand Down Expand Up @@ -131,10 +126,6 @@ - (void)setAllowRecordVideo:(BOOL)allowRecordVideo
longG.minimumPressDuration = .3;
longG.delegate = self;
[self.bottomView addGestureRecognizer:longG];

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
pan.delegate = self;
[self.bottomView addGestureRecognizer:pan];
}
}

Expand Down Expand Up @@ -194,7 +185,6 @@ - (void)longPressAction:(UILongPressGestureRecognizer *)longG
{
//此处不启动动画,由vc界面开始录制之后启动
_stopRecord = NO;
_hadTriggerRecord = YES;
if (self.delegate && [self.delegate respondsToSelector:@selector(onStartRecord)]) {
[self.delegate performSelector:@selector(onStartRecord)];
}
Expand All @@ -203,8 +193,6 @@ - (void)longPressAction:(UILongPressGestureRecognizer *)longG
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded:
{
_hadTriggerRecord = NO;

if (_stopRecord) return;
_stopRecord = YES;
[self stopAnimate];
Expand All @@ -219,26 +207,9 @@ - (void)longPressAction:(UILongPressGestureRecognizer *)longG
}
}

- (void)panAction:(UIPanGestureRecognizer *)pan
{
if (!_hadTriggerRecord) return;

CGRect caremaViewRect = [self convertRect:self.bottomView.frame toView:self.superview];
CGPoint lp = [pan locationInView:self];
CGPoint point = [self convertPoint:lp toView:self.superview];

CGFloat zoomFactor = (CGRectGetMidY(caremaViewRect)-point.y)/CGRectGetMidY(caremaViewRect) * 10;

if (self.delegate && [self.delegate respondsToSelector:@selector(onAdjustFocus:)]) {
[self.delegate performSelector:@selector(onAdjustFocus:) withObject:@(MIN(MAX(zoomFactor, 1), 10))];
}
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer
{
if (([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
||
([otherGestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])) {
if (([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])) {
return YES;
}
return NO;
Expand Down Expand Up @@ -358,8 +329,6 @@ @interface ZLCustomCamera () <CameraToolViewDelegate, AVCaptureFileOutputRecordi
{
//拖拽手势开始的录制
BOOL _dragStart;
//长按手势开始的录制
BOOL _longPressStart;
BOOL _layoutOK;
}

Expand Down Expand Up @@ -402,6 +371,8 @@ - (void)dealloc
if ([_session isRunning]) {
[_session stopRunning];
}

[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
// NSLog(@"%s", __func__);
}
Expand All @@ -413,13 +384,13 @@ - (void)viewDidLoad {
[self setupCamera];
[self observeDeviceMotion];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (!granted) {
[self onDismiss];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];
}
}];
} else {
Expand All @@ -440,7 +411,7 @@ - (void)observeDeviceMotion
{
self.motionManager = [[CMMotionManager alloc] init];
// 提供设备运动数据到指定的时间间隔
self.motionManager.deviceMotionUpdateInterval = .3;
self.motionManager.deviceMotionUpdateInterval = .5;

if (self.motionManager.deviceMotionAvailable) { // 确定是否使用任何可用的态度参考帧来决定设备的运动是否可用
// 启动设备的运动更新,通过给定的队列向给定的处理程序提供数据。
Expand Down Expand Up @@ -543,12 +514,6 @@ - (void)setupUI
if (self.allowRecordVideo) {
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(adjustCameraFocus:)];
[self.view addGestureRecognizer:pan];
//设置
for (UIGestureRecognizer *ges in self.toolView.bottomView.gestureRecognizers) {
if ([ges isKindOfClass:[UIPanGestureRecognizer class]]) {
[ges requireGestureRecognizerToFail:pan];
}
}
}
}

Expand Down Expand Up @@ -682,6 +647,7 @@ - (void)focusWithMode:(AVCaptureFocusMode)focusMode exposureMode:(AVCaptureExpos
#pragma mark - 手势调整焦距
- (void)adjustCameraFocus:(UIPanGestureRecognizer *)pan
{
//TODO: 录像中,点击屏幕聚焦,暂时没有思路,1.若添加tap手势 无法解决pan和tap之间的冲突; 2.使用系统touchesBegan方法,触发pan手势后 touchesBegan 无效
CGRect caremaViewRect = [self.toolView convertRect:self.toolView.bottomView.frame toView:self.view];
CGPoint point = [pan locationInView:self.view];

Expand Down Expand Up @@ -803,7 +769,6 @@ - (void)onTakePicture
//开始录制
- (void)onStartRecord
{
_longPressStart = YES;
AVCaptureConnection *movieConnection = [self.movieFileOutPut connectionWithMediaType:AVMediaTypeVideo];
movieConnection.videoOrientation = self.orientation;
[movieConnection setVideoScaleAndCropFactor:1.0];
Expand All @@ -816,17 +781,11 @@ - (void)onStartRecord
//结束录制
- (void)onFinishRecord
{
_longPressStart = NO;
[self.movieFileOutPut stopRecording];
[self.session stopRunning];
[self setVideoZoomFactor:1];
}

- (void)onAdjustFocus:(CGFloat)zoomFactor
{
[self setVideoZoomFactor:zoomFactor];
}

//重新拍照或录制
- (void)onRetake
{
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#define kViewHeight [[UIScreen mainScreen] bounds].size.height

//app名字
#define kAPPName [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"]
#define kAPPName [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"] ?: [[NSBundle mainBundle].infoDictionary valueForKey:(__bridge NSString *)kCFBundleNameKey]

//自定义图片名称存于plist中的key
#define ZLCustomImageNames @"ZLCustomImageNames"
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLPhotoActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by long on 15/11/25.
// Copyright © 2015年 long. All rights reserved.
//
//pods version 2.5.0.1 - 2017.10.26 update
//pods version 2.5.1.1 - 2017.11.15 update

#import <UIKit/UIKit.h>
#import "ZLDefine.h"
Expand Down
29 changes: 22 additions & 7 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ actionSheet.sender = self;
![image](https://github.com/longitachi/ZLPhotoBrowser/blob/master/效果图/edit.gif)
- 自定义相机效果图及介绍
![image](https://github.com/longitachi/ZLPhotoBrowser/blob/master/效果图/customCamera.gif)
![image](https://github.com/longitachi/ZLPhotoBrowser/blob/master/效果图/introduce.png)
Expand Down
2 changes: 1 addition & 1 deletion ZLPhotoBrowser.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ZLPhotoBrowser'
s.version = '2.5.1'
s.version = '2.5.1.1'
s.summary = 'A simple way to multiselect photos from ablum, force touch to preview photo, support portrait and landscape, edit photo, multiple languages(Chinese,English,Japanese)'
s.homepage = 'https://github.com/longitachi/ZLPhotoBrowser'
s.license = 'MIT'
Expand Down
5 changes: 5 additions & 0 deletions ZLPhotoBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
FD07871C1C0D45A200D17B97 = {
CreatedOnToolsVersion = 7.1;
DevelopmentTeam = 47UY3G7UH6;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 0;
};
};
};
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "1024.png",
"scale" : "1x"
}
],
Expand Down
4 changes: 2 additions & 2 deletions ZLPhotoBrowser/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<string>en</string>
<key>CFBundleDisplayName</key>
<string>ZLPhotoBrowser</string>
<key>NSMicrophoneUsageDescription</key>
<string>是否允许访问你的麦克风?</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -35,6 +33,8 @@
</dict>
<key>NSCameraUsageDescription</key>
<string>是否允许访问你的相机?</string>
<key>NSMicrophoneUsageDescription</key>
<string>是否允许访问你的麦克风?</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>是否允许访问你的相册?</string>
<key>UILaunchStoryboardName</key>
Expand Down
Loading

0 comments on commit 2a1dc97

Please sign in to comment.