UINavigationBar触摸 [英] UINavigationBar Touch

查看:82
本文介绍了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.

我有点

这是否是可能的?

推荐答案

我发现的解决方案是一个按钮,我使用以下(但我不知道如何法律): p>

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");
}

我这样做的方式可能完全错了,但可能会给你一个想法,你可以看看。这当然帮助了我!可能有更好的方法。

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触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆