UIGestureRecognizer, мешающий UIToolbar? - PullRequest
3 голосов
/ 05 декабря 2011

Я работаю над движком OpenSource Magazine, который вы можете посмотреть на GitHub:

https://github.com/interactivenyc/Defrag

Я установил UIToolbar в UIView, который я назвал MenuPanel,По какой-то причине UIBarButtonItems в UIToolbar не вызывают свои действия должным образом.Вот синтаксис, который я использую для кнопок:

UIBarButtonItem *homeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];

Что происходит , так это то, что где бы я ни нажимал на своем экране, вместо этого вызывается UITapGestureRecognizer, объявленный в моем основном UIViewController,Это настраивается в этом блоке кода в моем главном контроллере UIViewController:

- (void)setupGestureRecognizers {

//NSLog(@"setupGestureRecognizer NEW");

UISwipeGestureRecognizer *swipeRecognizer;

swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];

swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];

swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];

swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];

UITapGestureRecognizer *tapRecognizer;

tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}

Я уверен, что у меня что-то довольно простое концептуально неправильно с тем, как я пытаюсь это сделать.Может кто-нибудь сказать мне, как я могу решить эту проблему?

Для справки, вы можете увидеть мой основной DefragViewController: UIViewController здесь:

https://gist.github.com/1431722

И мойПанель меню: UIV Просмотреть здесь:

gist.github.com / 1431728

1 Ответ

5 голосов
/ 06 декабря 2011

Я решил свой собственный вопрос.

Я должен был сказать своему UIViewController игнорировать прикосновения с любой панели UIToolbar, например:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    //ignore any touches from a UIToolbar

    if ([touch.view.superview isKindOfClass:[UIToolbar class]]) {
        return NO;
    }

    return YES;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...