[self setNeedsUpdateOfSupportedInterfaceOrientations];
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = [array firstObject];
// 屏幕方向
UIInterfaceOrientationMask orientation = UIInterfaceOrientationMaskLandscapeRight;
UIWindowSceneGeometryPreferencesIOS *geometryPreferencesIOS = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:orientation];
// 开始切换
[scene requestGeometryUpdateWithPreferences:geometryPreferencesIOS errorHandler:^(NSError * _Nonnull error) {
NSLog( @"横屏错误");
}];
标签:orientation,ios16,横竖,UIWindowSceneGeometryPreferencesIOS,scene,切换,geometryPrefer
From: https://www.cnblogs.com/star001/p/17024675.html