我在主视图控制器上有一个文本视图。我在视图控制器的导航栏上有一个条形按钮项。当应用程序启动时,我执行以下操作:
在iOS 11之前,键盘将不会在步骤4之后再次显示。但是,在iOS 11中,它将显示出来。似乎在iOS 11中,它在解除弹出视图后恢复第一个响应者。
以下是我的问题:
另请参阅以下视频:
对于iOS 11:
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
以下是一些代码:
#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
答案 0 :(得分:0)
我刚刚在iOS 11上使用swift应用程序解决了这个问题。在解除新控制器之前随时调用[textView resignFirstResponder]是唯一的解决方法。 [查看endEditing]还不够。