热点新闻
iOS16屏幕强制横屏
2023-07-26 16:51  浏览:2729  搜索引擎搜索“手机低淘网”
温馨提示:信息一旦丢失不一定找得到,请务必收藏信息以备急用!本站所有信息均是注册会员发布如遇到侵权请联系文章中的联系方式或客服删除!
联系我时,请说明是在手机低淘网看到的信息,谢谢。
展会发布 展会网站大全 报名观展合作 软文发布

适配iOS16横屏操作

if (@available(iOS 16.0, *)) { @try { NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; UIWindowScene *ws = (UIWindowScene *)array[0]; Class GeometryPreferences = NSClassFromString(@"UIWindowSceneGeometryPreferencesIOS"); id geometryPreferences = [[GeometryPreferences alloc]init]; [geometryPreferences setValue:@(UIInterfaceOrientationMaskLandscapeRight) forKey:@"interfaceOrientations"]; SEL sel_method = NSSelectorFromString(@"requestGeometryUpdateWithPreferences:errorHandler:"); void (^ErrorBlock)(NSError *err) = ^(NSError *err){ NSLog(@"调用了Block%@",err); }; if ([ws respondsToSelector:sel_method]) { (((void (*)(id, SEL,id,id))[ws methodForSelector:sel_method])(ws, sel_method,geometryPreferences,ErrorBlock)); } } @catch (NSException *exception) { NSLog(@"*****************************华丽分割线**************************"); NSLog(@"%@",exception); } @finally { } } else { // 强制旋转回来 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val = UIInterfaceOrientationPortrait; [invocation setArgument:&val atIndex:2]; [invocation invoke]; } }

2022.09.02更新
在调用上面的方法前执行以下方法

- (void)configSupportedInterfaceOrientations:(int)number { id appDel = [[UIApplication sharedApplication] delegate]; SEL sel_clientstate = NSSelectorFromString(@"setClientstate:"); if ([appDel respondsToSelector:sel_clientstate]) { (((void (*)(id, SEL, NSUInteger))[appDel methodForSelector:sel_clientstate])(appDel, sel_clientstate, number)); } }

其中clientstate这个是一个状态值,用来控制 supportedInterfaceOrientationsFor

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { switch clientstate { case 1: return .allButUpsideDown case 2: return .landscape default: return .portrait } }

发布人:ffa2****    IP:125.64.79.***     举报/删稿
展会推荐
让朕来说2句
评论
收藏
点赞
转发