我正在尝试接受iOS开发,所以我还是一个菜鸟。我设法复制并粘贴了相机控制器(从here复制)并使其正常工作。
然而,我正在尝试创建一个间谍相机应用程序,所以我不希望屏幕看起来像一个相机。我想用黑色覆盖它。我尝试将亮度设置为0,但这只会使一切变暗。由于摄像机视图位于前景,因此将背景设置为黑色也不起作用。有没有办法实例化相机控制器并使相机硬件处于活动状态,并以某种方式编辑随之而来的视图,以便它不显示?
#import "EMCameraController.h"
@interface EMCameraController ()
@property (strong, nonatomic) IBOutlet UIImageView *camera;
@end
@implementation EMCameraController
@synthesize camera=_camera;
- (IBAction)showCamera:(id)sender {
[self startCameraControllerFromViewController: self
usingDelegate: self];
NSLog(@"done!");
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: NO];
cameraUI.view.backgroundColor = [UIColor blackColor]; //<-- doesn't work since camera view is in foreground
[[UIScreen mainScreen] setBrightness:0.0]; //<-- not working the way I want it.
return YES;
}
@end
答案 0 :(得分:2)
您应该使用AVCapture*
方法。它允许直接从相机拍摄图像。例如,请查看此示例https://developer.apple.com/library/ios/samplecode/SquareCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011190-Intro-DontLinkElementID_2