【发布时间】:2011-12-05 00:14:00
【问题描述】:
我正在开发一个开源杂志引擎,您可以在 GitHub 上查看它:
https://github.com/interactivenyc/Defrag
我已经在一个名为 MenuPanel 的 UIView 中设置了一个 UIToolbar。由于某种原因,UIToolbar 中的 UIBarButtonItems 没有正确调用它们的操作。这是我用于按钮的语法:
UIBarButtonItem *homeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];
发生的 是,我在屏幕上单击的任何位置,都会调用在我的主 UIViewController 中声明的 UITapGestureRecognizer。这可以在我的主 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
还有我的 MenuPanel:这里的 UIView:
gist.github.com/1431728
【问题讨论】:
标签: ios open-source