向左滑动&右边一直工作,但向上/向下滑动不起作用

时间:2014-08-06 22:24:53

标签: ios objective-c uiview uiswipegesturerecognizer

我有一个基于UIView的对象,我已设置识别滑动手势。视图中间有另一个基于UIView的对象。

当我向左或向右滑动时,无论我放在哪里,都会触发正确的事件。

当我向上或向下滑动正确的事件时,如果我的手指没有在中间的子视图中启动,则只会触发?

为什么?

这是对象的初始化代码:

- (id)init
{
    self = [super init];
    if (self) {
        [self setFrame:CGRectMake(0,
                                  0,
                                  [self getScreenWidth],
                                  [self getScreenHeight])];
        backView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                            0,
                                                            [self getScreenWidth],
                                                            [self getScreenHeight])];
        backView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backView];
        [self bringSubviewToFront:backView];

        theCard = [[actCard alloc] init:CARD_POS_CENTER];
        [backView addSubview:theCard];
        [backView bringSubviewToFront:theCard];

        swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                              action:@selector(showGestureForSwipeRecognizer:)];
        swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                               action:@selector(showGestureForSwipeRecognizer:)];
        swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                            action:@selector(showGestureForSwipeRecognizer:)];
        swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                              action:@selector(showGestureForSwipeRecognizer:)];
        [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
        [self addGestureRecognizer:swipeLeft];
        [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
        [self addGestureRecognizer:swipeRight];
        [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
        [self addGestureRecognizer:swipeUp];
        [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
        [self addGestureRecognizer:swipeDown];
        NSLog(@"Enabled: %d",swipeLeft.isEnabled);
        NSLog(@"Enabled: %d",swipeRight.isEnabled);
        NSLog(@"Enabled: %d",swipeUp.isEnabled);
        NSLog(@"Enabled: %d",swipeDown.isEnabled);

    }
    return self;
}

2 个答案:

答案 0 :(得分:0)

尝试将向上滑动和向下滑动的代理设置为您的MainViewController。如:

swipeDown .delegate  =   self;
swipeUp .delegate = self;

这应该使您的主视图控制器(包含辅助UIView)负责接收的手势。

希望这有帮助!

答案 1 :(得分:0)

明显!我真是个新手。 UITextView仍然具有scrollEnabled。这意味着UITextView采用了up&在滑动时,他们不会被传递到视图中。