2017-08-30 48 views
2

我在主視圖控制器上有一個文本視圖。我在視圖控制器的導航欄上有一個酒吧按鈕項目。當應用程序啓動時,我執行以下操作:在解散popoverview後恢復第一響應者

  1. 點擊文本視圖以開始編輯並顯示鍵盤。
  2. 點擊欄按鈕可顯示彈出視圖。
  3. 如果不關閉彈出視圖,我會關閉鍵盤。
  4. 通過點擊屏幕上的任何其他視圖關閉彈窗視圖。

在iOS 11之前,鍵盤在步驟4之後不會再顯示。但是,在iOS 11中,它將顯示出來。看起來在iOS 11中,它在解散彈窗視圖後恢復第一響應者。

這裏是我的問題:

  1. 它是一個錯誤,或者在iOS的11一些變化?
  2. 如果它是新的,那麼在解除彈出視圖後如何防止鍵盤顯示?

另請參閱下面的視頻:

對於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

我剛剛在iOS 11上有一個快速的應用程序的這個問題。在解散新控制器之前調用[textView resignFirstResponder]是唯一的解決方法。 [查看endEditing]是不夠的。

相關問題