Unity适配iPhone X—关于Home键指示器适配
Unity摊
相信有些人在iPhone X上玩游戏的时候,总是误触底部白条(Home键指示器,暂且先叫“底部白条”),专业术语:“App需要有从状态栏下拉或底部栏上滑的操作,而这个会和系统的下拉或上滑调出通知中心手势冲突。” 。 于是开始 百度一下
这是什么鬼
这并不是我们想要的解决办法……. how to 办?
经过一系列的尝试, 在iOS11之后iOS增加的新的API,是关于解决手势冲突的问题。
@interface UIViewController (UIScreenEdgesDeferringSystemGestures) // Override to return a child view controller or nil. If non-nil, that view controller's screen edges deferring system gestures will be used. If nil, self is used. Whenever the return value changes, -setNeedsScreenEdgesDeferringSystemGesturesUpdate should be called. - (nullable UIViewController *)childViewControllerForScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos); // Controls the application's preferred screen edges deferring system gestures when this view controller is shown. Default is UIRectEdgeNone. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos); // This should be called whenever the return values for the view controller's screen edges deferring system gestures have changed. - (void)setNeedsUpdateOfScreenEdgesDeferringSystemGestures API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(watchos, tvos); @end
API我们知道了,可是加到哪里?然后通过分析Unity打包后的Xcode工程,在工程目录
Classes->UI->UnityViewControllerBaseiOS.mm
的脚本中,发现被重写的方法,如下:
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures { UIRectEdge res = UIRectEdgeNone; if(UnityGetDeferSystemGesturesTopEdge()) res |= UIRectEdgeTop; if(UnityGetDeferSystemGesturesBottomEdge()) res |= UIRectEdgeBottom; if(UnityGetDeferSystemGesturesLeftEdge()) res |= UIRectEdgeLeft; if(UnityGetDeferSystemGesturesRightEdge()) res |= UIRectEdgeRight; return res; }
我们只需要改成如下即可:
UIRectEdge res = UIRectEdgeNone; //if(UnityGetDeferSystemGesturesTopEdge()) //res |= UIRectEdgeTop; //if(UnityGetDeferSystemGesturesBottomEdge()) //res |= UIRectEdgeBottom; //if(UnityGetDeferSystemGesturesLeftEdge()) //res |= UIRectEdgeLeft; //if(UnityGetDeferSystemGesturesRightEdge()) //res |= UIRectEdgeRight; return UIRectEdgeAll;
设置后第一次下拉“底部白条”只会展示指示器,继续下拉才能将通知中心拉出来。如果返回UIRectEdgeNone则会直接下拉出来。
参考博客,给大家安利一下,写的非常棒!:
PS: 如有疑问可以留言,一起学习。
原文地址:https://www.jianshu.com/p/b91aa36023b2
相关推荐
-
Unity3D UGUI , 3D物体 拖拽跟随鼠标 C#
2019-8-30
-
ASP.NET Core HTTP 管道中的那些事儿 C#
2019-6-30
-
[NewLife.XCode]功能设置 C#
2019-4-20
-
【译】单元测试最佳实践 C#
2019-8-30
-
UnitOfWork知多少 C#
2019-8-31
-
ASP.NET Core MVC/WebAPi 模型绑定探索 C#
2019-5-12
-
C# Memcache集群原理、客户端配置详细解析 C#
2019-9-2
-
ASP.NET Core实现类库项目读取配置文件 C#
2019-5-12
-
C#相等性 – “==” C#
2019-6-15
-
生产制造追溯系统-通过微信小程序实现移动端报表平台 C#
2019-6-3