ios16 横竖屏切换

        [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( @"横屏错误");

        }];

 
posted @ 2023-01-04 14:03  mingxing  阅读(201)  评论(0编辑  收藏  举报