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则会直接下拉出来。

参考博客,给大家安利一下,写的非常棒!:

iPhoneX 适配实践

PS: 如有疑问可以留言,一起学习。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,196评论 4 61
  • 在项目中所实现的是,左侧为导航栏,点击左侧导航栏,右侧为一iframe引用进来的界面,iframe页面上按钮点击,...
    酸辣粉儿阅读 2,773评论 0 1
  • 王涯《秋思赠远》原诗、注释、翻译、赏析 【原文】:秋思赠远王涯厌攀杨柳临清阁,闲采芙蕖傍碧潭。走马台①边人不见,拂...
    xcy无名阅读 1,878评论 0 0
  • 管理就是和人打交道所以它必然是复杂的,琐碎的。这是宁向东清华管理学课给我最大的收获。人和人之间应该是相互帮助,提携...
    烟外晓云阅读 1,462评论 0 0
  • 玉兔东升,红轮西垂。街灯齐刷刷的亮起,夜色如期。 人流依然攒动在街道上,广场上响彻的音乐,总是伴着齐刷刷的舞蹈。 ...
    子龙老师阅读 1,397评论 12 11