2013-08-03 83 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