問題:
使用了YYText 后會存在輸入框顯示不出 copy南用,paste等 menu膘怕。
代碼接口邏輯:
在VC添加一個 自定義alertView仿野。alertView是添加在自定義window上面點匆背。
核心代碼如下
#import "AlertViewController.h"
#import <YYText.h>
@interface AlertViewController ()
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, copy) void (^showCompletionBlock)(void);
@property (nonatomic, strong) YYTextView *View11;
@end
@implementation AlertViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.View11 = [[YYTextView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[self.view addSubview:self.View11];
self.View11.backgroundColor = UIColor.redColor;
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 210, 50, 50)];
btn.backgroundColor = [UIColor grayColor];
[btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UITextView *bt22n = [[UITextView alloc] initWithFrame:CGRectMake(300, 210, 100, 0100)];
bt22n.backgroundColor = [UIColor blueColor];
[self.view addSubview:bt22n];
}
- (void)clickBtn
{
[self dismissInWindowAnimateCompletion:nil];
}
- (UIWindow *)window
{
if (!_window) {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.windowLevel = UIWindowLevelAlert;
_window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_window.opaque = NO;
}
return _window;
}
- (void)showAnimated:(NSInteger)level completion:(void (^)(void))completion
{
self.showCompletionBlock = completion;
self.window.windowLevel = level;
if (level == 1000) {
self.window.backgroundColor = UIColor.yellowColor;
self.window.frame = CGRectMake(100, 100, 100, 100);
}
[self.window setRootViewController:self];
[self.window makeKeyAndVisible];
// 1.也可以直接使用window.hidden 這樣就可以不使用 makeKeyAndVisible鸣奔。
// 2典尾, 如果視圖添加了 UITextField 或者 UITextView役拴,當成為第一響應者的時候,系統(tǒng)會將 UITextField 或者 UITextView 所在的window 設置為keyWindow钾埂。
// 3.添加了YYText(其他的第三方也存在可能性)后河闰,如果存在 YYTextEffectWindow 那么該第二點將被打破。不會將 UITextField 或者 UITextView 所在的window 設置為keyWindow勃教。
// self.window.hidden = NO;
}
- (void)dismissInWindowAnimateCompletion:(void (^)(void))completion
{
[UIView animateWithDuration:0.3 animations:^{
self.view.alpha = 0.0;
} completion:^(BOOL finished) {
[self removeWindow];
dispatch_async(dispatch_get_main_queue(), ^{
self.view.alpha = 1.0;
if (completion) {
completion();
}
});
}];
}
- (void)removeWindow
{
self.window.rootViewController = nil;
self.window = nil;
// if (![[UIApplication sharedApplication].windows.firstObject isKindOfClass:[self class]]) {
// [[UIApplication sharedApplication].windows.firstObject makeKeyAndVisible];
// }
}
添加了YYText結(jié)果如下:
image.png
可以看出keyWindow 會變成 YYTextEffectWindow淤击,
不添加 YYText 結(jié)果如下:
- (void)viewDidLoad {
[super viewDidLoad];
// self.View11 = [[YYTextView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
// [self.view addSubview:self.View11];
// self.View11.backgroundColor = UIColor.redColor;
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 210, 50, 50)];
btn.backgroundColor = [UIColor grayColor];
[btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UITextView *bt22n = [[UITextView alloc] initWithFrame:CGRectMake(300, 210, 100, 0100)];
bt22n.backgroundColor = [UIColor blueColor];
[self.view addSubview:bt22n];
}
image.png
解決思路:
self.window = nil; 之后使用
// if (![[UIApplication sharedApplication].windows.firstObject isKindOfClass:[self class]]) {
// [[UIApplication sharedApplication].windows.firstObject makeKeyAndVisible];
// }
將keyWindo修改-
修改庫
image.png
在becomeKeyWindow 內(nèi)加上 異步。