Skip to content

Commit db73668

Browse files
committed
-调整相机的开启与关闭时机
1 parent fae9538 commit db73668

1 file changed

Lines changed: 25 additions & 34 deletions

File tree

LFCameraPickerControllerDEMO/LFCameraPickerControllerDEMO/class/Controller/LFCameraTakeViewController.m

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ - (void)viewWillAppear:(BOOL)animated {
289289

290290
/** 激活摄像头 */
291291
[self prepareSession];
292+
293+
[UIView animateWithDuration:0.25f delay:.5f options:UIViewAnimationOptionCurveEaseIn animations:^{
294+
self.tipsLabel.alpha = 1.f;
295+
} completion:^(BOOL finished) {
296+
[UIView animateWithDuration:0.25f delay:4.5f options:UIViewAnimationOptionCurveEaseOut animations:^{
297+
self.tipsLabel.alpha = 0.f;
298+
} completion:^(BOOL finished) {
299+
300+
}];
301+
}];
302+
[self.recorder startRunning];
303+
[self.recorder focusCenter];
304+
// 记录相机的显示大小,正常来说它是全屏的。但刘海屏手机是不会全屏。
305+
self.previewSize = [self.recorder.previewLayer rectForMetadataOutputRectOfInterest:CGRectMake(0, 0, 1, 1)].size;
306+
// 重新调整水印层并获取水印
307+
self.overlayView.frame = (CGRect){CGPointZero, self.previewSize};
308+
self.overlayView.center = self.view.center;
309+
[self getOverlayView:self.myOrientation];
292310
}
293311

294312
- (void)viewWillLayoutSubviews
@@ -318,49 +336,23 @@ - (void)viewDidLayoutSubviews {
318336
- (void)viewDidAppear:(BOOL)animated {
319337
[super viewDidAppear:animated];
320338

321-
[UIView animateWithDuration:0.25f delay:.5f options:UIViewAnimationOptionCurveEaseIn animations:^{
322-
self.tipsLabel.alpha = 1.f;
323-
} completion:^(BOOL finished) {
324-
[UIView animateWithDuration:0.25f delay:4.5f options:UIViewAnimationOptionCurveEaseOut animations:^{
325-
self.tipsLabel.alpha = 0.f;
326-
} completion:^(BOOL finished) {
327-
328-
}];
329-
}];
330-
331-
/** 在 session 完全停止下来之前会始终阻塞线程 */
332-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
333-
[self.recorder startRunning];
334-
335-
336-
dispatch_async(dispatch_get_main_queue(), ^{
337-
// 记录相机的显示大小,正常来说它是全屏的。但刘海屏手机是不会全屏。
338-
self.previewSize = [self.recorder.previewLayer rectForMetadataOutputRectOfInterest:CGRectMake(0, 0, 1, 1)].size;
339-
// 重新调整水印层并获取水印
340-
self.overlayView.frame = (CGRect){CGPointZero, self.previewSize};
341-
self.overlayView.center = self.view.center;
342-
[self getOverlayView:self.myOrientation];
343-
});
344-
345-
346-
});
347339
}
348340

349341
- (void)viewWillDisappear:(BOOL)animated {
350342
[super viewWillDisappear:animated];
351343

352344
[self stopUpdateAccelerometer];
345+
346+
self.tipsLabel.alpha = 0.f;
347+
/** 还原缩放 */
348+
_recorder.videoZoomFactor = 1;
349+
/** 在 session 完全停止下来之前会始终阻塞线程,拍照系统需要播放声音 */
350+
[self.recorder stopRunning];
353351
}
354352

355353
- (void)viewDidDisappear:(BOOL)animated {
356354
[super viewDidDisappear:animated];
357-
self.tipsLabel.alpha = 0.f;
358-
/** 还原缩放 */
359-
_recorder.videoZoomFactor = 1;
360-
/** 在 session 完全停止下来之前会始终阻塞线程,拍照系统需要播放声音,马上关闭录制会导致声音卡顿 */
361-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
362-
[self.recorder stopRunning];
363-
});
355+
364356
}
365357

366358
- (void)dealloc {
@@ -379,7 +371,6 @@ - (void)prepareSession {
379371
session.fileType = AVFileTypeQuickTimeMovie;
380372

381373
_recorder.session = session;
382-
[_recorder focusCenter];
383374
}
384375

385376
[self updateTimeRecorded];

0 commit comments

Comments
 (0)