变更记录
序号 | 录入时间 | 录入人 | 备注 |
---|---|---|---|
1 | 2017-06-07 | Alfred Jiang | - |
方案名称
UIWindow - 关于弹出提示(Toast View)与键盘以及 Window 的关系梳理
关键字
UIWindow \ Toast View \ 键盘 \ UIRemoteKeyboardWindow
需求场景
- 正确的弹出提示(Toast View)展示逻辑梳理
参考链接
(无)
详细内容
结论
Toast View 在 [[[UIApplication sharedApplication] windows] lastObject] 和 [[UIApplication sharedApplication] keyWindow] 的取舍:
- 在 iOS 7 上推荐添加 Toast View 至 [[[UIApplication sharedApplication] windows] lastObject]
- 在 iOS 8 上添加 Toast View 至任意都可以
- 在 iOS 9 之后推荐添加 Toast View 至 [[UIApplication sharedApplication] keyWindow]
分析数据
iOS 7
(lldb) po [[UIApplication sharedApplication] windows]
<__NSArrayM 0x1cf08620>(
<UIWindow: 0x15df8e40; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15df95f0>; layer = <UIWindowLayer: 0x15df9000>>,
<UITextEffectsWindow: 0x15e36f70; frame = (0 0; 768 1024); hidden = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15e2d9c0>; layer = <UIWindowLayer: 0x15e32a80>>
)
通过 [[[UIApplication sharedApplication] windows] lastObject] 可获取到 UITextEffectsWindow,
在 UITextEffectsWindow 上添加 Toast View
横竖屏切换:正常, Toast View 正常切换
键盘消失:正常,不会导致 Toast View 提前释放
(lldb) po [[UIApplication sharedApplication] keyWindow]
<UIWindow: 0x15df8e40; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x15df95f0>; layer = <UIWindowLayer: 0x15df9000>>
通过 [[UIApplication sharedApplication] keyWindow] 可获取到 UIWindow,
在 UIWindow 上添加 Toast View
横竖屏切换:异常, Toast View 无法正常切换
键盘消失:正常,不会导致 Toast View 提前释放
iOS 8
(lldb) po [[UIApplication sharedApplication] windows]
<__NSArrayM 0x18daf310>(
<UIWindow: 0x13c404a0; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13c40f70>; layer = <UIWindowLayer: 0x13c40690>>,
<UITextEffectsWindow: 0x12ff42b0; frame = (0 0; 768 1024); opaque = NO; gestureRecognizers = <NSArray: 0x12f9b340>; layer = <UIWindowLayer: 0x1852dc90>>
)
通过 [[[UIApplication sharedApplication] windows] lastObject] 可获取到 UITextEffectsWindow,
在 UITextEffectsWindow 上添加 Toast View
横竖屏切换:正常, Toast View 正常切换
键盘消失:正常,不会导致 Toast View 提前释放
(lldb) po [[UIApplication sharedApplication] keyWindow]
<UIWindow: 0x13c404a0; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13c40f70>; layer = <UIWindowLayer: 0x13c40690>>
通过 [[UIApplication sharedApplication] keyWindow] 可获取到 UIWindow,
在 UIWindow, 上添加 Toast View
横竖屏切换:正常, Toast View 正常切换
键盘消失:正常,不会导致 Toast View 提前释放
iOS 9+
(lldb) po [[UIApplication sharedApplication] windows]
<__NSArrayM 0x1c473410>(
<UIWindow: 0x14127c20; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x14039ea0>; layer = <UIWindowLayer: 0x14127ea0>>,
<UITextEffectsWindow: 0x1c706130; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x1c7058f0>>,
<UIRemoteKeyboardWindow: 0x24c4f440; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x24c0be60>>
)
通过 [[[UIApplication sharedApplication] windows] lastObject] 可获取到 UIRemoteKeyboardWindow,
在 UIRemoteKeyboardWindow, 上添加 Toast View
横竖屏切换:正常, Toast View 正常切换
键盘消失:异常,会导致 Toast View 提前释放
(lldb) po [[UIApplication sharedApplication] keyWindow]
<UIWindow: 0x14127c20; frame = (0 0; 768 1024); opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x14039ea0>; layer = <UIWindowLayer: 0x14127ea0>>
通过 [[UIApplication sharedApplication] keyWindow] 可获取到 UIWindow,
在 UIWindow, 上添加 Toast View
横竖屏切换:正常, Toast View 正常切换
键盘消失:正常,不会导致 Toast View 提前释放
效果图
(无)
备注
(无)