撤消popoverview后恢复第一响应者 [英] Restoring first responder after dismissing popoverview

查看:48
本文介绍了撤消popoverview后恢复第一响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主视图控制器上有一个文本视图.我在视图控制器的导航栏上有一个栏按钮项.应用启动时,我将执行以下操作:

I have a text view on the main view controller. I have a bar button item on the view controller's navigation bar. When the app starts, I perform the following actions:

  1. 点击文本视图以开始编辑并显示键盘.
  2. 点击bar按钮以显示弹出视图.
  3. 在不关闭弹出视图的情况下,我关闭了键盘.
  4. 通过点击屏幕上的任何其他视图来关闭弹出视图.

在iOS 11之前,键盘不会在步骤4之后再次出现.但是,在iOS 11中,它将出现.似乎在iOS 11中,它在关闭弹出窗口视图后恢复了第一响应者.

Before iOS 11, the keyboard will NOT show up again after Step 4. However, in iOS 11, it will show up. It seems that in iOS 11, it restores the first responder after dismissing the popover view.

这是我的问题:

  1. 是Bug,还是iOS 11中的某些更改?
  2. 如果它是新的,那么如何在关闭弹出窗口视图后阻止键盘显示?

另请参阅以下视频:

对于iOS 11:

https://www.dropbox.com/s/88wyv0y0idsmu5c/iOS%2011.mov?dl=0

对于iOS 10.3:

For 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

推荐答案

我刚刚在iOS 11上使用快速应用程序遇到了这个问题.唯一的解决办法是在关闭新控制器之前随时调用[textView resignFirstResponder].[view endEditing]还不够.

I just had this issue on iOS 11 with a swift app. Calling [textView resignFirstResponder] any time before dismissing the new controller was the only fix. [view endEditing] was not enough.

这篇关于撤消popoverview后恢复第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆