我有一个工具栏,我在其中添加了 3 个按钮作为 UItoolbaritems。现在我还在工具栏中添加了一个手势识别器以显示和隐藏该工具栏。但我需要区分触摸是来自按钮还是外部执行我的功能。我试过这个`
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.toolbar.frame=CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -12, [[UIScreen mainScreen] bounds].size.width, 44);
self.navigationController.toolbar.tintColor=[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
buttonGoBack = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTouchUp:)];
buttonGoBack.tag=1;
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpace.width = 30;
buttonGoForward = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(forwardButtonTouchUp:)];
buttonGoForward.tag=2;
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.navigationController.toolbar addGestureRecognizer:gestureRecognizer];
NSMutableArray *toolBarButtons = [[NSMutableArray alloc] init];
[toolBarButtons addObject:buttonGoBack];
[toolBarButtons addObject:fixedSpace];
[toolBarButtons addObject:buttonGoForward];
`
我把手势识别器做为`
if(sender.view.tag==1)
[self performSelector:@selector(backButtonTouchUp:) withObject:nil];
else if(sender.view.tag==2)
[self performSelector:@selector(forwardButtonTouchUp:) withObject:nil];
else
{
[UIView animateWithDuration:.50
animations:^{
if(self.navigationController.toolbar.frame.origin.y==[[UIScreen mainScreen] bounds].size.height -12)
self.navigationController.toolbar.frame=CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -44, [[UIScreen mainScreen] bounds].size.width, 44);
else
self.navigationController.toolbar.frame=CGRectMake(0, [[UIScreen mainScreen] bounds].size.height -12, [[UIScreen mainScreen] bounds].size.width, 44);
}]
}
` 但是按钮动作没有执行。谁能帮我找出我哪里出错了?