1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//使用相机拍照 -(void)takePhotoWithCamer{ if([self isCanUseCamera]){ UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.showsCameraControls = NO; UIView * customCameraView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIButton * takePicture = [UIButton buttonWithType:UIButtonTypeCustom]; takePicture.frame = CGRectMake(0, SGFullScreenHeight-44, SGFullScreenWidth, 44); [takePicture setTitle:@"照相" forState:UIControlStateNormal]; [takePicture sg_handleControlEvent:UIControlEventTouchUpInside withBlock:^(id sender) { [imagePicker takePicture]; }]; [customCameraView addSubview:takePicture]; imagePicker.cameraOverlayView = customCameraView; CGSize screenSize = [[UIScreen mainScreen] bounds].size; float aspectRatio = 4.0/3.0; float scale = screenSize.height/screenSize.width * aspectRatio; imagePicker.cameraViewTransform = CGAffineTransformMakeScale(scale, scale); [self presentViewController:imagePicker animated: YES completion: nil]; }else{ //@"无法使用相机, 请到 系统设置 -> 隐私 -> 相机 里启动权限" } }
//判断相机是否可用 -(BOOL)isCanUseCamera{ AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){ return NO; }else{ return YES; } }
//从相册选照 -(void)choosePhotoFromLibrary{ UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.view.tintColor = self.view.tintColor; imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; imagePicker.allowsEditing = NO; imagePicker.delegate = self; [self presentViewController:imagePicker animated: true completion: nil]; }
|
近期评论