RACameraViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. //
  2. // RACameraViewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/5.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RACameraViewController.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. #import "RATakePhotoPreviewController.h"
  11. #import <CoreMotion/CoreMotion.h>
  12. #import "RAUtils.h"
  13. @interface RACameraViewController ()<AVCapturePhotoCaptureDelegate>
  14. @property (nonatomic,strong) IBOutlet UIView *previewContainer;
  15. @property (nonatomic,strong) IBOutlet UIView *controlContanier;
  16. @property (strong, nonatomic) IBOutlet UIButton *takePhotoBtn;
  17. @property (strong, nonatomic) IBOutlet UIButton *backBtn;
  18. @property (nonatomic,assign) BOOL barHidden;
  19. #pragma mark - Camera
  20. @property (nonatomic,strong) AVCaptureDevice *captureDevice;
  21. @property (nonatomic,strong) AVCaptureSession *captureSession;
  22. @property (nonatomic,strong) AVCaptureDeviceInput *captureInput;
  23. //@property (nonatomic,strong) AVCaptureStillImageOutput *captureOutput;
  24. @property (nonatomic,strong) AVCapturePhotoSettings *photoSetting;
  25. @property (nonatomic,strong) AVCapturePhotoOutput* photoOutput;
  26. @property (nonatomic,strong) AVCaptureVideoPreviewLayer *previewLayer;
  27. @property (nonatomic,assign) BOOL cameraInitial;
  28. @property (nonatomic,assign) AVLayerVideoGravity gravity;
  29. @property (strong, nonatomic) CMMotionManager *motionManager;
  30. @property (assign, nonatomic) UIDeviceOrientation orientationLast;
  31. @end
  32. @implementation RACameraViewController
  33. -(BOOL)shouldAutorotate {
  34. return NO;
  35. }
  36. - (void)initMotionManager
  37. {
  38. if (_motionManager == nil) {
  39. _motionManager = [[CMMotionManager alloc] init];
  40. }
  41. // 提供设备运动数据到指定的时间间隔
  42. _motionManager.deviceMotionUpdateInterval = .3;
  43. if (_motionManager.deviceMotionAvailable) { // 确定是否使用任何可用的态度参考帧来决定设备的运动是否可用
  44. [_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
  45. withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
  46. if (!error) {
  47. [self outputAccelertionData:accelerometerData.acceleration];
  48. }
  49. else{
  50. NSLog(@"%@", error);
  51. }
  52. }];
  53. }else
  54. {
  55. [self setMotionManager:nil];
  56. }
  57. }
  58. - (void)outputAccelertionData:(CMAcceleration)acceleration{
  59. UIDeviceOrientation orientationNew;
  60. // NSLog(@"x %f y %f z %f",acceleration.x,acceleration.y, acceleration.z);
  61. if (acceleration.x >= 0.75) {
  62. orientationNew = UIDeviceOrientationLandscapeRight;
  63. }
  64. else if (acceleration.x <= -0.75) {
  65. orientationNew = UIDeviceOrientationLandscapeLeft;
  66. }
  67. else if (acceleration.y <= -0.75) {
  68. orientationNew = UIDeviceOrientationPortrait;
  69. }
  70. else if (acceleration.y >= 0.75) {
  71. orientationNew = UIDeviceOrientationPortraitUpsideDown;
  72. }
  73. else {
  74. // Consider same as last time
  75. return;
  76. }
  77. if (orientationNew == self.orientationLast)
  78. return;
  79. self.orientationLast = orientationNew;
  80. // [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:orientationNew] forKey:@"orientation"];
  81. // CGRect frame = self.previewContainer.bounds;
  82. // [self resetPreview:frame];
  83. }
  84. + (NSString *)storyboardID {
  85. return NSStringFromClass([self class]);
  86. }
  87. + (instancetype)viewControllerFromStoryboard {
  88. RACameraViewController *cameraVC = [[UIStoryboard storyboardWithName:@"Camera" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  89. cameraVC.takeMode = RACameraTakeModeTakeOnce;
  90. cameraVC.gravity = AVLayerVideoGravityResizeAspectFill;
  91. return cameraVC;
  92. }
  93. + (instancetype)showCameraFromViewController:(UIViewController *)from withTakeMode:(RACameraTakeMode)mode videoGravity:(AVLayerVideoGravity)gravity completion:(void(^)(UIImage *image))completion {
  94. RACameraViewController *vc = [self viewControllerFromStoryboard];
  95. vc.takeMode = mode;
  96. if (!gravity) {
  97. gravity = AVLayerVideoGravityResizeAspectFill;
  98. }
  99. vc.gravity = gravity;
  100. vc.completion = completion;
  101. return vc;
  102. }
  103. - (void)viewDidLoad {
  104. [super viewDidLoad];
  105. // Do any additional setup after loading the view.
  106. [self initMotionManager];
  107. UIImage *normal_img = [self.class imageWithColor:[UIColor redColor] Size:CGSizeMake(60, 60)];
  108. UIImage *highlight_img = [self.class imageWithColor:[UIColor whiteColor] Size:CGSizeMake(60, 60)];
  109. [self.takePhotoBtn setImage:normal_img forState:UIControlStateNormal];
  110. [self.takePhotoBtn setImage:highlight_img forState:UIControlStateHighlighted];
  111. // [self initCapture];
  112. // [self initTakePicture];
  113. if ([self camerAuthorization]) {
  114. [self initCapture];
  115. [self initTakePicture];
  116. } else {
  117. // fix:第一次打开相机的时候授权成功后,未初始化相机
  118. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. if (granted) {
  121. [self initCapture];
  122. [self initTakePicture];
  123. CGRect frame = self.previewContainer.bounds;
  124. [self resetPreview:CGRectOffset(frame, CGRectGetWidth(frame), 0)];
  125. [UIView animateWithDuration:0.3 animations:^{
  126. self.previewLayer.frame = frame;
  127. }];
  128. if (self.cameraInitial && !self.captureSession.isRunning) {
  129. // [self.captureSession startRunning];
  130. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  131. [self.captureSession startRunning];
  132. // sleep(0.3);
  133. // dispatch_async(dispatch_get_main_queue(), ^{
  134. // [self.mask removeFromSuperview];
  135. // });
  136. });
  137. }
  138. } else {
  139. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  140. NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
  141. if (!appName) {
  142. appName = [infoDict objectForKey:@"CFBundleName"];
  143. }
  144. __weak typeof(self) weakSelf = self;
  145. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
  146. UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  147. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  148. }];
  149. [alert addAction:action];
  150. [self presentViewController:alert animated:YES completion:nil];
  151. }
  152. });
  153. }];
  154. }
  155. /**
  156. * 管理导航条
  157. * 在viewDidload的时候隐藏导航条
  158. * 恢复导航条的显示/隐藏有两个地方:1.退出的时候;2.确认使用照片的时候
  159. */
  160. if (self.navigationController) {
  161. BOOL navBarHidden = self.navigationController.navigationBar.hidden;
  162. self.barHidden = navBarHidden;
  163. if (!navBarHidden) {
  164. [self.navigationController setNavigationBarHidden:YES animated:YES];
  165. }
  166. }
  167. }
  168. - (void)didReceiveMemoryWarning {
  169. [super didReceiveMemoryWarning];
  170. // Dispose of any resources that can be recreated.
  171. }
  172. - (void)viewWillAppear:(BOOL)animated {
  173. [super viewWillAppear:animated];
  174. if (self.cameraInitial && !self.captureSession.isRunning) {
  175. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  176. [self.captureSession startRunning];
  177. // sleep(0.3);
  178. // dispatch_async(dispatch_get_main_queue(), ^{
  179. // [self.mask removeFromSuperview];
  180. // });
  181. });
  182. }
  183. }
  184. - (void)viewWillDisappear:(BOOL)animated {
  185. [super viewWillDisappear:animated];
  186. if ([self.captureSession isRunning]) {
  187. [self.captureSession stopRunning];
  188. }
  189. }
  190. - (BOOL)prefersStatusBarHidden {
  191. return YES;
  192. }
  193. - (void)viewDidLayoutSubviews {
  194. [super viewDidLayoutSubviews];
  195. // 强制布局一次,不然 takePhotoBtn frame还没发生改变
  196. [self.controlContanier layoutIfNeeded];
  197. if ([self camerAuthorization] && self.cameraInitial) {
  198. CGRect frame = self.previewContainer.bounds;
  199. UIInterfaceOrientation orientation =[RAUtils query_orientation:self];
  200. BOOL isPortrait = /*self.interfaceOrientation*/orientation == UIInterfaceOrientationPortrait || /*self.interfaceOrientation*/orientation == UIInterfaceOrientationPortraitUpsideDown;
  201. // aspect ratio 3:4
  202. if (self.gravity == AVLayerVideoGravityResizeAspect) {
  203. CGRect backBtnFrame = [self.previewContainer convertRect:self.backBtn.frame fromView:self.controlContanier];
  204. CGRect captureBtnFrame = [self.previewContainer convertRect:self.takePhotoBtn.frame fromView:self.controlContanier];
  205. if (isPortrait) {
  206. CGFloat left = 0;
  207. CGFloat top = CGRectGetMaxY(backBtnFrame);
  208. CGFloat bottom = CGRectGetMinY(captureBtnFrame);
  209. CGFloat width = CGRectGetWidth(self.controlContanier.bounds);
  210. CGFloat height = bottom - top;
  211. frame = CGRectMake(left, top, width, height);
  212. } else {
  213. CGFloat left = CGRectGetMaxX(backBtnFrame);
  214. CGFloat right = CGRectGetMinX(captureBtnFrame);
  215. CGFloat top = 0;
  216. CGFloat width = right - left;
  217. CGFloat bottom = CGRectGetHeight(self.controlContanier.bounds);
  218. CGFloat height = bottom - top;
  219. frame = CGRectMake(left, top, width, height);
  220. }
  221. }
  222. [self resetPreview:frame];
  223. }
  224. }
  225. #pragma mark - Capture
  226. - (void)resetPreview:(CGRect)frame {
  227. self.previewLayer.frame = frame;
  228. // if (self.previewLayer.connection.isVideoOrientationSupported) {
  229. // self.previewLayer.connection.videoOrientation = [self captureVideoOrientation];
  230. // }
  231. //
  232. // if ([self.captureOutput connectionWithMediaType:AVMediaTypeVideo].isVideoOrientationSupported) {
  233. // [self.captureOutput connectionWithMediaType:AVMediaTypeVideo].videoOrientation = [self captureVideoOrientation];
  234. // }
  235. //
  236. }
  237. - (BOOL)camerAuthorization {
  238. AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  239. if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) {
  240. return NO;
  241. }
  242. return YES;
  243. }
  244. - (void)initCapture {
  245. self.cameraInitial = NO;
  246. if (![self camerAuthorization]) {
  247. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  248. NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
  249. if (!appName) {
  250. appName = [infoDict objectForKey:@"CFBundleName"];
  251. }
  252. __weak typeof(self) weakSelf = self;
  253. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Camera access denied, please change %@ setting, allow App use camera. (setting -> privacy -> camera enable %@)",[UIDevice currentDevice].model,appName] preferredStyle:UIAlertControllerStyleAlert];
  254. UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  255. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  256. }];
  257. [alert addAction:action];
  258. [self presentViewController:alert animated:YES completion:nil];
  259. return;
  260. }
  261. self.captureSession = [[AVCaptureSession alloc] init];
  262. self.captureDevice = [self videoDevicePosition:AVCaptureDevicePositionBack];
  263. if (!self.captureDevice) {
  264. NSLog(@"there is no capture device while init camera");
  265. return;
  266. }
  267. NSError *error;
  268. self.captureInput = [[AVCaptureDeviceInput alloc] initWithDevice:self.captureDevice error:&error];
  269. if (error) {
  270. NSLog(@"init camera error: %@",error);
  271. return;
  272. }
  273. [self.captureSession beginConfiguration];
  274. if ([_captureSession canSetSessionPreset:AVCaptureSessionPresetPhoto]) {
  275. _captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
  276. }
  277. // if ([self.captureDevice isFlashAvailable] && [_captureDevice isFlashModeSupported:AVCaptureFlashModeAuto]) {
  278. if ([self.captureDevice isFlashAvailable] && [self.photoOutput supportedFlashModes]) {
  279. NSError *configErr;
  280. [self.captureDevice lockForConfiguration:&configErr];
  281. // AVCapturePhotoSettings.flashMode
  282. // [self.captureDevice setFlashMode:AVCaptureFlashModeAuto];
  283. [self.captureDevice unlockForConfiguration];
  284. }
  285. // if ([self.captureDevice isAdjustingWhiteBalance] && [self.captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) {
  286. // NSError *configErr;
  287. // [self.captureDevice lockForConfiguration:&configErr];
  288. // [self.captureDevice setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];
  289. // [self.captureDevice unlockForConfiguration];
  290. // }
  291. if ([self.captureSession canAddInput:self.captureInput]) {
  292. [self.captureSession addInput:self.captureInput];
  293. // if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080]) {
  294. // self.captureSession.sessionPreset = AVCaptureSessionPreset1920x1080;
  295. // } else {
  296. // if ([self.captureSession canSetSessionPreset:AVCaptureSessionPresetHigh]) {
  297. // self.captureSession.sessionPreset = AVCaptureSessionPresetHigh;
  298. // }
  299. // }
  300. } else {
  301. NSLog(@"init camera can't add input");
  302. return;
  303. }
  304. [self.captureSession commitConfiguration];
  305. self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
  306. self.previewLayer.videoGravity = self.gravity;
  307. [self.previewContainer.layer addSublayer:self.previewLayer];
  308. self.cameraInitial = YES;
  309. }
  310. - (void)initTakePicture {
  311. if (!self.cameraInitial) {
  312. return;
  313. }
  314. // self.captureOutput = [[AVCaptureStillImageOutput alloc] init];
  315. self.photoOutput = [AVCapturePhotoOutput new];
  316. // NSDictionary *setting = @{AVVideoCodecKey:AVVideoCodecJPEG};
  317. // AVVideoCodecTypeJPEG
  318. // self.photoSetting.cod
  319. // [self.captureOutput setOutputSettings:setting];
  320. //
  321. if ([self.captureSession canAddOutput:self.photoOutput]) {
  322. [self.captureSession addOutput:self.photoOutput];
  323. }
  324. // AVCaptureConnection *connection = [self.captureOutput connectionWithMediaType:AVMediaTypeVideo];
  325. // if (connection.isVideoOrientationSupported) { // addOutput之后判断,否则一直都是false
  326. // connection.videoOrientation = [self captureVideoOrientation];
  327. // }
  328. }
  329. - (AVCaptureDevice *) videoDevicePosition:(AVCaptureDevicePosition)position {
  330. // NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
  331. AVCaptureDeviceDiscoverySession * _Nonnull cameras = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera] mediaType:AVMediaTypeVideo position: AVCaptureDevicePositionUnspecified];//AVCaptureDevicePositionFront & AVCaptureDevicePositionBack
  332. // //获取当前摄像头方向
  333. // AVCaptureDevicePosition currentPosition = self.captureDeviceInput.device.position;
  334. // AVCaptureDevicePosition toPosition = AVCaptureDevicePositionUnspecified;
  335. // if (currentPosition == AVCaptureDevicePositionBack || currentPosition == AVCaptureDevicePositionUnspecified) {
  336. // toPosition = AVCaptureDevicePositionFront;
  337. // }else{
  338. // toPosition = AVCaptureDevicePositionBack;
  339. // }
  340. // NSArray* captureDeviceArray = [cameras.devices filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"position == %d",toPosition]];
  341. // if (captureDeviceArray.count == 0) {
  342. // return [self throw_errorWithDomain:@"VideoCapture: reverseCamera failed! get new camera failed!"];
  343. // }
  344. for (AVCaptureDevice *device in cameras.devices) {
  345. if ([device position] == position) {
  346. return device;
  347. }
  348. }
  349. return nil;
  350. }
  351. - (AVCaptureVideoOrientation)captureVideoOrientation {
  352. AVCaptureVideoOrientation result;
  353. // UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
  354. switch (self.orientationLast) {
  355. case UIDeviceOrientationPortrait:
  356. case UIDeviceOrientationFaceUp:
  357. case UIDeviceOrientationFaceDown:
  358. result = AVCaptureVideoOrientationPortrait;
  359. break;
  360. case UIDeviceOrientationPortraitUpsideDown:
  361. //如果这里设置成AVCaptureVideoOrientationPortraitUpsideDown,则视频方向和拍摄时的方向是相反的。
  362. result = AVCaptureVideoOrientationPortraitUpsideDown;
  363. break;
  364. case UIDeviceOrientationLandscapeLeft:
  365. result = AVCaptureVideoOrientationLandscapeRight;
  366. break;
  367. case UIDeviceOrientationLandscapeRight:
  368. result = AVCaptureVideoOrientationLandscapeLeft;
  369. break;
  370. default:
  371. result = AVCaptureVideoOrientationPortrait;
  372. break;
  373. }
  374. return result;
  375. }
  376. #pragma mark - Action
  377. - (IBAction)takePictureBtnClick:(UIButton *)sender {
  378. // UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
  379. // NSLog(@"UIDeviceOrientation %ld",deviceOrientation);
  380. // [self.captureOutput connectionWithMediaType:AVMediaTypeVideo];
  381. if (!self.cameraInitial) {
  382. return;
  383. }
  384. sender.enabled = false;
  385. // AVCaptureConnection *connection = [self.captureOutput connectionWithMediaType:AVMediaTypeVideo];
  386. //
  387. // if (connection.isVideoOrientationSupported) { // addOutput之后判断,否则一直都是false
  388. // connection.videoOrientation = [self captureVideoOrientation];
  389. // }
  390. //
  391. // NSLog(@"capture orientation %ld",connection.videoOrientation);
  392. ;
  393. // __weak typeof(self) weakSelf = self;
  394. self.photoSetting= [AVCapturePhotoSettings photoSettings];
  395. if(self.captureDevice.hasFlash)
  396. {
  397. self.photoSetting.flashMode =AVCaptureFlashModeAuto;
  398. }
  399. [self.photoOutput capturePhotoWithSettings:self.photoSetting delegate:self];
  400. }
  401. - (IBAction)returnButtonClick:(UIButton *)sender {
  402. if (self.navigationController) {
  403. [self.navigationController popViewControllerAnimated:YES];
  404. } else {
  405. [self dismissViewControllerAnimated:YES completion:nil];
  406. }
  407. if (self.navigationController) {
  408. [self.navigationController setNavigationBarHidden:self.barHidden animated:YES];
  409. }
  410. }
  411. #pragma mark - Utils
  412. + (UIImage *)imageWithColor:(UIColor *)color Size:(CGSize)size {
  413. UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
  414. CGContextRef ctx = UIGraphicsGetCurrentContext();
  415. CGContextAddEllipseInRect(ctx, CGRectMake(5, 5, size.width - 10, size.height - 10));
  416. CGContextSetFillColorWithColor(ctx, color.CGColor);
  417. CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
  418. CGContextSetLineWidth(ctx, 3.0f);
  419. CGContextDrawPath(ctx, kCGPathFillStroke);
  420. UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  421. UIGraphicsEndImageContext();
  422. return img;
  423. }
  424. #pragma mark - AVCapturePhotoCaptureDelegate
  425. -(void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error API_AVAILABLE(ios(11.0)) {
  426. if (!error) {
  427. // 使用该方式获取图片,可能图片会存在旋转问题,在使用的时候调整图片即可
  428. NSData *imageData = [photo fileDataRepresentation];
  429. UIImage *image = [UIImage imageWithData:imageData];
  430. // NSData *imageData=[AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
  431. // UIImage *image=[UIImage imageWithData:imageData];
  432. RATakePhotoPreviewController *preVC = [RATakePhotoPreviewController viewControllerFromStoryboard];
  433. preVC.photoHandler = ^(UIImage *img){
  434. if (self.completion) {
  435. self.completion(img);
  436. }
  437. };
  438. preVC.preImage = image;
  439. if (self.takeMode == RACameraTakeModeTakeOnce) {
  440. preVC.popTo = self.fromVC;
  441. preVC.barHidden = self.barHidden;
  442. }
  443. [self.navigationController pushViewController:preVC animated:YES];
  444. } else {
  445. NSLog(@"take picture failed: %@",error);
  446. }
  447. // sender.enabled = true;
  448. self.takePhotoBtn.enabled = true;
  449. }
  450. @end