2013-08-03 84 views
0

我一直在研究我的图书应用程序,但是我有一个UIBarButtonItem困境。我已经在工具栏上设置了3个按钮,如下图所示。它们工作正常,直到我设置了代码中最后2行的单击识别器。我想要做的是通过一次敲击跳出此模式屏幕,而不是双击,而不是在工具栏上添加另一个“取消”按钮。设置了单击识别器后,没有任何条形按钮项目可以工作。我怎样才能摆脱这种困境。任何人都可以告诉我如何解决这个问题吗?感谢您的时间。toolbaritem的困境

UIToolbar* toolbar = [[UIToolbar alloc] init]; 
toolbar.barStyle = UIBarStyleDefault; 
[toolbar sizeToFit]; 
toolbar.frame = CGRectMake(0, 410, 320, 50); 
toolbar.tintColor = _label.backgroundColor; 

self.title = @"Test For Toolbar"; 
UIBarButtonItem* TofC = [[UIBarButtonItem alloc] initWithTitle:@"T of C" 
                 style:UIBarButtonItemStyleBordered 
                 target:self 
                 action:@selector(showTofC)]; 


UIBarButtonItem* bookMark = 
    [[UIBarButtonItem alloc] initWithTitle:@"Book Mark"style:UIBarButtonItemStyleBordered 
                 target:self 
                 action:@selector(bookMarkIt)]; 


UIBarButtonItem* searchBtn = [[UIBarButtonItem alloc] initWithTitle:@"Search" 
                 style:UIBarButtonItemStyleBordered 
                 target:self 
                 action:@selector(searchIt)]; 


UIBarButtonItem* spacer = [[UIBarButtonItem alloc]  
        initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
             target:self 
             action:nil]; 





NSArray* buttons = 
      [NSArray arrayWithObjects:TofC, spacer, bookMark, spacer, searchBtn, nil]; 


self.navigationController.toolbarHidden = NO; 


[toolbar setItems:buttons animated:NO]; 
[self.view addSubview:toolbar]; 

/* 
// Single Tap 
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] 
             initWithTarget:self 
             action:@selector(handleTapGesture:)]; 
[self.view addGestureRecognizer:tapGesture]; 

*/ 

// Single Tap 
Dum2ViewController* dum2ViewController = [[Dum2ViewController alloc] init]; 
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] 
             initWithTarget:dum2ViewController 
             action:@selector(handleTapGesture:)]; 
[dum2ViewController.view addGestureRecognizer:tapGesture]; 

回答

0

您已将工具栏添加为主视图的子视图,然后将手势识别器附加到主视图。

因此,只要您触摸工具栏,触摸就会首先进入主视图,并在将其传递到工具栏项之前拦截手势识别器。

我推荐做的是在当前视图中的任何内容(另一个子视图?)上设置一个手势识别器。这样工具栏中的一个触摸将被路由到工具栏,并且视图中的一个触摸将转到(内容)子视图并被手势识别器捕获。

有意义吗?

+0

嗨,谢谢你的建议。我喜欢你的建议,但不是运气。请看看我上面添加的代码。再次感谢。 – boochan224