xcode 在cameraOverlayView上拍照的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9159140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:13:37  来源:igfitidea点击:

take picture method on cameraOverlayView

iphonexcodeuiimagepickercontrollercustom-view

提问by user921509

My problem; Hide the default camera controls and overlay it with my my own. This is made with the property cameraOverlayView. I also was having problem triggering the takePicture method.

我的问题; 隐藏默认的相机控件并用我自己的控件覆盖它。这是通过属性cameraOverlayView 实现的。我也遇到了触发 takePicture 方法的问题。

回答by u4370109

(Question solved in the comments and in the edits. See Question with no answers, but issue solved in the comments (or extended in chat))

(问题已在评论和编辑中解决。请参阅没有答案的问题,但问题已在评论中解决(或在聊天中扩展)

The OP wrote:

OP写道:

Here is what came to be the solution:

I have two UIViewController. The main ViewController and the CustomOverlay (for the camera controls).

I the ViewController I declare the source type and the overlay for may camera control like this:

这是解决方案:

我有两个 UIViewController。主 ViewController 和 CustomOverlay(用于相机控件)。

我在 ViewController 中声明了源类型和可能像这样的相机控件的叠加层:

- (void)viewDidLoad
{
    // notification from the CustomOverlay Controller that triggers the eTakePicture method
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eTakePicture:) name:@"eTakePicture" object:nil];

    daysBtn.delegate = self;
    daysBtn.hidden = YES;

    picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;
    picker.wantsFullScreenLayout = YES;
    picker.delegate = self;

    overlay = [[CustomOverlay alloc] initWithNibName:@"CustomOverlay" bundle:nil];
    // Overlay for the camera controls, note the "= overlay.view", the ".view" was important
    // because the overlay is a new UIViewcontroller (with xib) so you have to call the
    // view. Most tutorials that I saw were based on UIView so only "= overlay" worked.
    picker.cameraOverlayView = overlay.view;
    [self presentModalViewController:picker animated:NO];

    [super viewDidLoad];
}

Now on the CustomOverlay, which is a UIViewController I have the take picture button and want this button to trigger a method in the main ViewController:

现在在 CustomOverlay,这是一个 UIViewController 我有拍照按钮,并希望这个按钮触发主 ViewController 中的方法:

- (IBAction)shoot:(id)control {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"eTakePicture" object:self];

}

And back to the main ViewController:

回到主 ViewController:

-(void)eTakePicture:(NSNotification *)notification
{
    [picker takePicture];
}

All the code above will change a little more once I review it, specially the first block where I have to have a condition to check if cameraSourceType is available.

Hope that helps somebody out there. Any question, just ask.

一旦我查看了上面的所有代码,它就会发生更多变化,特别是我必须有条件检查 cameraSourceType 是否可用的第一个块。

希望能帮助那里的人。有任何问题,尽管问。