将Swipe Gesture放在UIImagePickerController上

时间:2014-04-26 15:46:02

标签: ios objective-c cocoa-touch uiimagepickercontroller uiswipegesturerecognizer

我希望能够在使用摄像机隐藏相机控件时向右滑动。视图呈现得很好但是当我滑动时我得到一个错误。

我收到以下错误:

  

VideoStream [13065:60b] - [UILayoutContainerView   toggleControlsWithGesture]:发送到实例的无法识别的选择器   0x1701a1960 2014-04-26 11:37:28.639 VideoStream [13065:60b] *   由于未捕获的异常而终止应用程序   ' NSInvalidArgumentException',原因:' - [UILayoutContainerView   toggleControlsWithGesture]:

以下是代码:

- (BOOL)startCameraControllerFromViewController:(UIViewController *)controller usingDelegate:(id)delegate
{
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
        || (delegate == nil)
        || (controller == nil)) {
        return NO;
    }

    _cameraUI = [[UIImagePickerController alloc] init];
    _cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    _cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
    _cameraUI.allowsEditing = NO;
    _cameraUI.delegate = delegate;

    [controller presentViewController:_cameraUI animated:YES completion:nil];
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] 
                                            initWithTarget:_cameraUI.view 
                                                    action:@selector(toggleControlsWithGesture)];
    swipeRight.delegate = self;

    //And assuming the "Up" direction in your screenshot is no accident
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    [_cameraUI.view addGestureRecognizer:swipeRight];

    return YES;
}

这是滑动代码:

- (void)toggleControlsWithGesture
{
    NSLog(@"BOOM");
    if (_showsControls == YES) {
        _cameraUI.showsCameraControls = NO;
    } else {
        _cameraUI.showsCameraControls = YES;
    }
}

任何可以提供的帮助都非常感谢。

1 个答案:

答案 0 :(得分:2)

而不是:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
                                        initWithTarget:_cameraUI.view 
                                                action:@selector(toggleControlsWithGesture)];

做的:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
                                        initWithTarget:self
                                                action:@selector(toggleControlsWithGesture)];

说明:

对于UISwipeGestureRecognizer对象,您目前正在执行-initWithTarget:_cameraUI.view

这意味着将对{1}}
{1}}方法可在此课程中找到,因此您需要将目标指定为_cameraUI.view


示例: XYZClass.m 中考虑,我们执行以下操作:

_cameraUI.view

这基本上表明-toggleControlsWithGesture将通过触发-toggleControlsWithGesture方法来响应事件 ...为此,self应定义ABCClass *abcObject = [ABCClass alloc] init]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:abcObject action:@selector(doSomething)]; 方法。

在您的情况下,abcObject属于doSomething类,而ABCClass可能是属性或其他类对象。在任何一种情况下,它都没有为您的目的创建 doSomething方法。