首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在react-native中防止锁屏/通知中心向下滑动

在react-native中防止锁屏/通知中心向下滑动
EN

Stack Overflow用户
提问于 2018-08-20 16:51:25
回答 2查看 194关注 0票数 2

从iOS 11开始,在屏幕边缘将自己的手势优先于系统手势的行为发生了变化。

以前,iOS假设如果你隐藏状态栏,你希望屏幕边缘的手势首先被触发。

现在,您必须重写preferredScreenEdgesDeferringSystemGestures方法以获得与此处解释相同的结果:https://useyourloaf.com/blog/avoiding-conflicts-with-system-gestures-at-screen-edges/

我们如何在react-native中做到这一点?在最近的版本中是否已经处理了这个问题?我在react-native源代码中找不到任何对该方法的引用。

EN

回答 2

Stack Overflow用户

发布于 2018-12-30 05:06:57

这可以通过将正在使用的UIViewController交换为以您喜欢的方式实现preferredScreenEdgesDeferringSystemGestures的you来实现。

首先创建一个返回所需值的新类,例如MainViewController

代码语言:javascript
复制
//
//  MainViewController.h
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface MainViewController : UIViewController

@end

NS_ASSUME_NONNULL_END

和:

代码语言:javascript
复制
//
//  MainViewController.m
//

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
  return UIRectEdgeBottom;
}

@end

最后,将通用视图控制器替换为我们刚刚创建的专用视图控制器:

代码语言:javascript
复制
  */

 #import "AppDelegate.h"
+#import "MainViewController.h"

 #import <React/RCTBundleURLProvider.h>
 #import <React/RCTRootView.h>

===== SNIP =====

   rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

   self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
-  UIViewController *rootViewController = [UIViewController new];
+  UIViewController *rootViewController = [MainViewController new];
   rootViewController.view = rootView;
   self.window.rootViewController = rootViewController;
   [self.window makeKeyAndVisible];
票数 0
EN

Stack Overflow用户

发布于 2019-11-11 17:58:29

我设法通过在UIViewController上使用Swift extension的方法swizzle解决了这个问题

代码语言:javascript
复制
extension UIViewController {
fileprivate static func swizzleReduceSystemGestures() {
      guard let aClass = NSClassFromString("RNNNavigationController") ?? NSClassFromString("RNNStackController"), // aClass?.alloc() as? UINavigationController
      let originalMethod = class_getInstanceMethod(aClass, #selector(getter: UIViewController.preferredScreenEdgesDeferringSystemGestures)),
      let swizzledMethod = class_getInstanceMethod(aClass, #selector(getter: preferredScreenEdgesDeferringSystemGesturesSwizzled)) else { return }
      method_exchangeImplementations(originalMethod, swizzledMethod)
  }

  @objc public var preferredScreenEdgesDeferringSystemGesturesSwizzled: UIRectEdge {
       return .all
  }
}

然后在AppDelegate中调用这个静态方法

代码语言:javascript
复制
 UIViewController.swizzleReduceSystemGestures()

类似地,您可以使用swizzle设置prefersHomeIndicatorAutoHidden,它就像一个护身符,直到他们给我们一个适当的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51927188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档