我在主视图控制器上有一个文本视图。我在视图控制器的导航栏上有一个栏按钮项目。当应用程序启动时,我执行以下操作:
- 点击文本视图开始编辑并显示键盘。
- 点击栏按钮以显示弹出视图。
- 在不关闭弹出窗口视图的情况下,我关闭了键盘。
- 通过点击屏幕上的任何其他视图来关闭弹出视图。
在 iOS 11 之前,第 4 步之后键盘将不再显示。但是,在 iOS 11 中,它将出现。似乎在 iOS 11 中,它在关闭弹出窗口视图后恢复了第一响应者。
这是我的问题:
- 这是一个错误,还是 iOS 11 中的一些变化?
- 如果它是新的,那么如何防止键盘在关闭弹出视图后显示?
另请参阅以下视频:
对于 iOS 11:
https://www.dropbox.com/s/88wyv0y0idsmu5c/iOS%2011.mov?dl=0 https://www.dropbox.com/s/88wyv0y0idsmu5c/iOS%2011.mov?dl=0
对于 iOS 10.3:
https://www.dropbox.com/s/11gg6h39mcgb0fs/iOS%2010.3.mov?dl=0 https://www.dropbox.com/s/11gg6h39mcgb0fs/iOS%2010.3.mov?dl=0
以下是一些代码:
#import "MainViewController.h"
@interface MainViewController ()
@property(nonatomic, retain)UITextView *textView;
@end
@implementation MainViewController
@synthesize textView = _textView;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor];
self.textView = [[UITextView alloc] init];
self.textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.textView];
self.textView.backgroundColor = [UIColor blueColor];
NSDictionary *dict = @{@"textView" : self.textView};
NSArray *vCons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-3-[textView]-3-|" options:0 metrics:nil views:dict];
NSArray *hCons = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-3-[textView]-3-|" options:0 metrics:nil views:dict];
[self.view addConstraints:vCons];
[self.view addConstraints:hCons];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import "ViewController.h"
#import "MainViewController.h"
@interface ViewController ()
@property(retain,nonatomic)MainViewController *mainVC;
@end
@implementation ViewController
@synthesize mainVC = _mainVC;
- (void)viewDidLoad {
[super viewDidLoad];
self.mainVC = [[MainViewController alloc] init];
UINavigationController *navigCon = [[UINavigationController alloc] initWithRootViewController:self.mainVC];
self.mainVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(showPopover)];
[self.view addSubview:navigCon.view];
}
-(void)showPopover {
UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"Action 1" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Action 2" style:UIAlertActionStyleDefault handler:nil];
[alertCon addAction:action1];
[alertCon addAction:action2];
[alertCon setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alertCon popoverPresentationController];
popPresenter.barButtonItem = self.mainVC.navigationItem.rightBarButtonItem;
[self presentViewController:alertCon animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
我刚刚在 iOS 11 上使用 swift 应用程序遇到了这个问题。在关闭新控制器之前随时调用 [textView resignFirstResponder] 是唯一的修复方法。 [查看结束编辑]还不够。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)