Changing back button in iOS 7 disables swipe to navigate back(在 iOS 7 中更改返回按钮会禁用滑动导航返回)
问题描述
我有一个 iOS 7 应用程序,我在其中设置了一个自定义后退按钮,如下所示:
I have an iOS 7 app where I am setting a custom back button like this:
UIImage *backButtonImage = [UIImage imageNamed:@"back-button"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, 20, 20);
[backButton addTarget:self
action:@selector(popViewController)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
viewController.navigationItem.leftBarButtonItem = backBarButtonItem;
但这会禁用 iOS 7 的从左向右滑动"手势导航到上一个控制器.有谁知道我如何设置自定义按钮并仍然启用此手势?
But this disables the iOS 7 "swipe left to right" gesture to navigate to the previous controller. Does anyone know how I can set a custom button and still keep this gesture enabled?
我尝试改为设置 viewController.navigationItem.backBarButtonItem,但这似乎没有显示我的自定义图像.
I tried to set the viewController.navigationItem.backBarButtonItem instead, but this doesn't seem to show my custom image.
推荐答案
重要提示:这是一个黑客.我建议您看看这个答案.
IMPORTANT: This is a hack. I would recommend taking a look at this answer.
在分配 leftBarButtonItem
后调用以下行对我有用:
Calling the following line after assigning the leftBarButtonItem
worked for me:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
如果在 init
方法中调用,这将不起作用.它应该在 viewDidLoad
或类似方法中调用.
This does not work if called in init
methods. It should be called in viewDidLoad
or similar methods.
这篇关于在 iOS 7 中更改返回按钮会禁用滑动导航返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iOS 7 中更改返回按钮会禁用滑动导航返回
基础教程推荐
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01