11纯代码 oc xcode_Xcode11 创建了一个oc项目,加载提示框位置显示错误

在Xcode11更新后,由于SceneDelegate的引入,导致SVProgressHUD加载位置错误。通过导入SceneDelegate.h并修改positionHUD:notification方法,适配iOS 13及以上版本,解决了HUD视图中心位置获取不正确的问题。提供了两种解决方案,一种通过SceneDelegate获取window.bounds,另一种使用UIScreen.mainScreen.bounds,但可能有潜在问题。
摘要由CSDN通过智能技术生成

Xcode 版本更新新增了SceneDelegate,SVProgressHUD的作者在设置HUDView的中心位置时使用的是UIApplication.sharedApplication.delegate.window.bounds 获取的,而版本更新之后获取不到正确的rect,因此把这部分代码进行调整。(鄙人测试没问题)

代码调整:

SVProgressHUD.m中引入#import "SceneDelegate.h" ,

修改 -(void)positionHUD:(NSNotification*)notification 方法开头位置

#if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS

if (@available(ios 13.0, *)) {

UIWindowScene *windowScene = (UIWindowScene *)[[[UIApplication sharedApplication] connectedScenes] allObjects].firstObject;

SceneDelegate *delegate =(SceneDelegate *)windowScene.delegate;

self.frame = delegate.window.bounds;

}else {

self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;

}

UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;

#elif !defined(SV_APP_EXTENSIONS) && !TARGET_OS_IOS

if (@available(ios 13.0, *)) {

UIWindowScene *windowScene = (UIWindowScene *)[[[UIApplication sharedApplication] connectedScenes] allObjects].firstObject;

SceneDelegate *delegate =(SceneDelegate *)windowScene.delegate;

self.frame = delegate.window.bounds;

}else {

self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;

}

#else

或者更简单的调整(可能会出现其他问题,不建议使用):

修改 -(void)positionHUD:(NSNotification*)notification 方法开头位置

#if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS

self.frame = UIScreen.mainScreen.bounds;

UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;

#elif !defined(SV_APP_EXTENSIONS) && !TARGET_OS_IOS

self.frame = UIScreen.mainScreen.bounds;

#else

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值