當用戶點擊導航欄中的標題時,在Objective-C中,有人能幫助我識別點擊嗎?識別在UINavigation欄中的標題點擊
-3
A
回答
2
嘗試以下操作:
1)添加按鈕,導航
UIButton *titleLabelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleLabelButton setTitle:@"myTitle" forState:UIControlStateNormal];
titleLabelButton.frame = CGRectMake(0, 0, 70, 44);
titleLabelButton.font = [UIFont boldSystemFontOfSize:16];
[titleLabelButton addTarget:self action:@selector(didTapTitleView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleLabelButton;
2你的標題視圖)實施選擇
- (IBAction)didTapTitleView:(id) sender{
//Perform your actions
NSLog(@"Title tap");
}
1
那麼你不能直接具有觸摸title
財產UINavigationItem
的UINavigationBar
事件。
有一個屬性titleView
,您可以設置和觸摸事件。因此,您可以製作一個UILabel
並將其設置爲UINavigationItem
。
[self.navigationItem setTitleView:label];
然後,您可以在此label
上設置點擊事件。
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTitle:)];
[label addGestureRecognizer:tap];
- (void)didTapTitle:(UILabel *)label {
//handle tap...
}
0
您需要使用自定義標題視圖併爲其添加輕擊手勢識別器。
在viewDidLoad
試試這個:
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(navTitleTapped)];
UILabel* navigationTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 500, 50)];
navigationTitleLabel.text = @"The title goes here...";
[navigationTitleLabel addGestureRecognizer:tap];
self.navigationItem.titleView = navigationTitleLabel;
然後,實施navTitleTapped
-(void)navTitleTapped
{
//do what you need to do
}
1
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyBoard)];
tapGesture.cancelsTouchesInView = NO;
[self.navigationController.view addGestureRecognizer:tapGesture];
-(void)hideKeyBoard
{
[self.view endEditing:YES];
}
相關問題
- 1. 認識點擊導航欄標題
- 2. UINavigation欄按鈕,IBAction爲根據點擊
- 3. 標題欄的標題需要點擊
- 4. 在UITableViewCell中點擊UIImageView的識別
- 5. GWT DatePicker識別日曆圖標點擊
- 6. 識別表格單元格,當點擊識別器時點擊
- 7. 識別點擊的對象
- 8. 標題欄上的bootstrap div colapse點擊
- 9. 可點擊的導航欄標題
- 10. 在UINavigation欄中隱藏BackButton
- 11. 標題欄和類別=標題欄之間的區別
- 12. ListView中的OnItemClickListener無法識別點擊
- 13. 識別已被點擊的組在expandableListView
- 14. Appcelerator。檢測點擊導航欄標題
- 15. 識別哪個標籤在qt中被點擊
- 16. 點擊手勢識別器
- 17. Jquery無法識別點擊
- 18. GridView識別點擊行值?
- 19. android:MapView無法識別點擊
- 20. 點擊jquery不被識別
- 21. 識別按鈕點擊
- 22. 處理點擊標籤欄控制器標題中的按鈕
- 23. uitableview標題中的單獨的輕擊手勢識別器
- 24. 識別textarea標記中的url並使其可點擊
- 25. 如何識別Scala中的鼠標點擊?
- 26. 在沒有識別元素的情況下點擊座標
- 27. 點擊2個點擊選項來識別點擊事件
- 28. 標題A不能識別標題B?
- 29. 識別treeview節點集合中點擊的節點
- 30. Swift 3.0,Xcode 8.1,UiNavigation as標籤欄