IOS / Objective-C / Storyboard:可以使用Tabbar访问整个应用程序的手势识别器?

问题描述 投票:0回答:1

我想创建一个可在整个应用程序中使用的手势识别器,以便用户无论身在何处都可以访问快捷方式/帮助菜单。但是,由于应用程序有很多屏幕,我不想在每个屏幕上创建单独的手势识别器。

我想过使用可用的tabbarcontroller,然而,触摸它上面的任何地方似乎代表了标签栏按钮上的点击。

是否可以在标签栏上放置向上滑动手势识别器,可以区别于按钮?我怎样才能区分这两个动作呢?以下有些修改?

-(void)createUpwardSwipeTabBAr {
    UISwipeGestureRecognizer *upGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleHelp:)];
    leftFilter.direction = UISwipeGestureRecognizerDirectionUp;
    [leftFilter setNumberOfTouchesRequired:1];
    leftFilter.delegate = self;
    [_tabBarController addGestureRecognizer:upwardSwipe];

}

-(void)handleHelp:(UIGestureRecognizer*)recognizer {
[self launchHelpVC];
}

在此先感谢您的任何建议。

ios objective-c uitabbarcontroller gesture uiswipegesturerecognizer
1个回答
0
投票

我有一个简单的想法。它可以工作。

编辑要处理滑动的类,并将手势识别器连接到根视图。

{
  guard let parentView = UIApplication.shared.windows.first else {return}
  // create the recognizer and attach it
  UISwipeGestureRecognizer *upGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleHelp:)];
  ...
  parentView.addGestureRecognizer(upwardSwipe)
}

- (void)handleHelp:(UIGestureRecognizer*)recognizer {
   [self launchHelpVC];
}

我混合了swift和ObjC,但很简单。 UIWindow派生自UIView,因此它应该处理所有未处理的手势并传递给层次结构中的下一个视图。

另一种可能更好的方法是将手势识别器添加到tabBar而不是_tabBarController。使用_tabBarController.tabBar

© www.soinside.com 2019 - 2024. All rights reserved.