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 触控


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01