5

iOS 7 采用了一种新手势,在屏幕上从左到右滑动作为 UINavigationController 中返回按钮的快捷方式。

我的应用似乎没有免费采用这种行为。我需要做什么才能使这个手势可用于我的 iOS 应用程序(在 Xcode 4.6.3 中为 iOS 5.1 和更高版本构建)?

这是一篇带视频的文章,从用户的角度来看,您想了解的 iOS 7 中的新手势。

答案可能与作为UIGestureRecognizer子类的interactivePopGestureRecognizer有关。

4

2 回答 2

3

It should work automatically if the back button is visible. If you are displaying a leftBarButtonItem instead of the back button, the gesture will not be present by default. Also, if you are using a UINavigationBar but not a UINavigationController, you won't see this functionality.

If you are using a UINavigationController and your view controller's navigation item contains a leftBarButtonItem, it's still possible to add functionality for the swipe left to right gesture of the navigation controller, by attaching a delegate to the navigation controller's interactivePopGestureRecognizer.

EDIT: I didn't notice that you're building against SDK 5.1. This is a new feature in the iOS 7 SDK, so I believe you'll need to build with Xcode 5 against the iOS 7 SDK in order to make use of the new feature.

于 2013-10-11T19:20:59.790 回答
0

我找到了自定义leftBarButtom问题的完美解决方案

将手势委托设置为导航控制器

您需要继承 UINavigationController 并在其中实现“UIGestureRecognizerDelegate”协议,并在 viewDidLoad 上添加一些代码,请参见下面的代码

自定义导航控制器.m

@interface CBNavigationController : UINavigationController @end

@implementation CBNavigationController

  • (void)viewDidLoad { __weak CBNavigationController *weakSelf = self;

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; } }

@结尾

并且只需将此类继承到您的导航控制器,它将完美运行。

于 2014-07-25T06:49:10.293 回答