lixiang1994 / LEEAlert

优雅的可自定义 Alert ActionSheet
MIT License
1.29k stars 203 forks source link

iOS16 横屏时候用默认的show会导致后面画面变形,追踪代码是 [leeWindow makeKeyAndVisible]造成的 #173

Open JasonLxj opened 1 year ago

JasonLxj commented 1 year ago

大概得一个复现代码如下,两个方法,先调用 onHorClick:然后调用 onLandClick: 调用 onLandClick:的时候效果如下:

// SceneDelegate.m
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    if ([scene isKindOfClass:[UIWindowScene class]]) {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        [LEEAlert configMainWindow:windowScene.windows.firstObject];
    }

    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
}

// ViewController.m
- (IBAction)onHorClick:(id)sender {
    NSArray *sceneArray = [[[UIApplication sharedApplication] connectedScenes] allObjects];
    UIWindowScene *scene = sceneArray.firstObject;
    if (scene) {
        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskLandscapeLeft];
        [scene requestGeometryUpdateWithPreferences:geometryPreferences
                                       errorHandler:^(NSError * _Nonnull error) {
            NSLog(@"%@", error.localizedDescription);
        }];
    }
}

- (IBAction)onLandClick:(id)sender {
    LEEAlert.alert.config.LeeAddTitle(^(UILabel * _Nonnull label) {
        label.text = @"测试文字";
    })
    .LeeAddAction(^(LEEAction *action) {
        action.type = LEEActionTypeDefault;
        action.clickBlock = ^{
            NSLog(@"%@", @"点击了");
        };
    })
    .LeeAddAction(^(LEEAction *action) {
        action.type = LEEActionTypeCancel;
        action.clickBlock = ^{
            NSLog(@"%@", @"点击了");
        };
    })
    .LeeShow();
}

1111

https://user-images.githubusercontent.com/15604758/191020740-9acbbd72-31a0-4c49-bf01-4ead54755e38.mp4

JasonLxj commented 1 year ago

经过测试,将 show 里面的 [[LEEAlert shareManager].leeWindow makeKeyAndVisible]; 注释掉,弹窗可以正常显示,而且后面的页面也显示正常。不知道这样是否有别的隐患。

lixiang1994 commented 1 year ago

你的项目使用的是SceneDelegate吗?

lixiang1994 commented 1 year ago

刚刚发布了 1.6.1版本, 你可以更新一下试试, iOS13以上不再调用makeKeyAndVisible

JasonLxj commented 1 year ago

刚刚发布了 1.6.1版本, 你可以更新一下试试, iOS13以上不再调用makeKeyAndVisible了 刚才试了下,貌似还有别的问题。关闭弹窗的时候,会有一个屏幕旋转的过程。这里弄了个demo,如果有时间你可以看下效果。

https://user-images.githubusercontent.com/15604758/191272175-caa86fad-af82-4c9a-b913-a15cbec1ceed.mp4

JasonLxj commented 1 year ago

你的项目使用的是SceneDelegate吗?

使用了。

lixiang1994 commented 1 year ago

视频中关闭的时候 window又变了 我猜测是不是和[[LEEAlert shareManager].leeWindow resignKeyWindow];有关, 你可以尝试注释掉它吗?

JasonLxj commented 1 year ago

视频中关闭的时候 window又变了 我猜测是不是和[[LEEAlert shareManager].leeWindow resignKeyWindow];有关, 你可以尝试注释掉它吗?

刚试了下,不行,感觉是系统管理多Window的问题。。

BigPoro commented 1 year ago

视频中关闭的时候 window又变了 我猜测是不是和[[LEEAlert shareManager].leeWindow resignKeyWindow];有关, 你可以尝试注释掉它吗?

我没有使用SceneDelegate,注释该行代码后bug解决。

lixiang1994 commented 1 year ago

@JasonLxj @BigPoro @kaelding 麻烦各位试一下1.6.4版本是否还有该问题, 如果已经解决 我好关闭这个issue

JacketXia commented 1 year ago

@JasonLxj @BigPoro @kaelding 麻烦各位试一下1.6.4版本是否还有该问题, 如果已经解决 我好关闭这个issue

我项目中使用了1.6.4版本,在iOS16且横屏的情况下,弹出弹窗是没问题的,关闭弹窗时,还是有屏幕旋转的问题。

lixiang1994 commented 1 year ago

@JasonLxj @BigPoro @kaelding 麻烦各位试一下1.6.4版本是否还有该问题, 如果已经解决 我好关闭这个issue

我项目中使用了1.6.4版本,在iOS16且横屏的情况下,弹出弹窗是没问题的,关闭弹窗时,还是有屏幕旋转的问题。

可以用demo复现一下吗? 我好像没有搞出来

syp1027825441 commented 1 year ago

为什么一定要用一个新的window呢,直接加载keywindow上或者appdelegate中的window上不行吗