UINavigationBar Touch(UINavigationBar 触控)
问题描述
我想在用户点击我的一个视图的导航栏标题时触发一个触摸事件.
I would like to fire an event on touch when a user taps the title of the navigation bar of one of my views.
我不知道是否可以访问 UINavigationBar 的标题视图以便将触摸事件连接到它.
I'm at a bit of a loss on whether I can access the view of the title of the UINavigationBar in order to wire up a touch event to it.
这可能吗?
推荐答案
我找到的解决方案是一个按钮,我使用如下(但我不知道它有多合法"):
The solution I found is a button, I use the following (but I don't know how "legal" it is):
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;
把那段代码放在你设置标题的地方.然后我在其他地方进行了测试:
Put that bit of code where ever you set your title. Then elsewhere I had this to test:
- (IBAction)didTapTitleView:(id) sender
{
NSLog(@"Title tap");
}
在控制台上记录了Title Tap"!
which logged "Title tap" on the console!
我处理此问题的方式可能完全错误,但可能会让您对可以查看的内容有所了解.这当然帮助了我!不过可能有更好的方法.
The way I've gone about this may be completely wrong, but might give you an idea on what you can look in to. It's certainly helped me out! There's probably a better way of doing it though.
这篇关于UINavigationBar 触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UINavigationBar 触控
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01