Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UIWebView中调整iOS键盘高度的限制_Ios_Objective C_Uiwebview_Autolayout - Fatal编程技术网

在UIWebView中调整iOS键盘高度的限制

在UIWebView中调整iOS键盘高度的限制,ios,objective-c,uiwebview,autolayout,Ios,Objective C,Uiwebview,Autolayout,我有一个简单的浏览器视图控制器,用作故事板的一部分。一开始看起来很棒。我的UIToolBar通过垂直空间约束0锚定到UIView的底部 当你在网页上点击某个打开键盘的东西时。UIToolBar被隐藏。因此,我为键盘可见性更改添加了一个侦听器,并根据键盘的高度调整了约束。这似乎很有效 但是,如果用户点击键盘上的最小化按钮,键盘不会完全消失。允许在输入字段之间切换的箭头键的顶部栏(我不知道如何称呼它)将保持可见。因此,我无法将约束设置回0,我必须根据可视键盘的高度(我认为会包括顶部栏)再次设置约

我有一个简单的浏览器视图控制器,用作故事板的一部分。一开始看起来很棒。我的
UIToolBar
通过垂直空间约束0锚定到
UIView
的底部

当你在网页上点击某个打开键盘的东西时。
UIToolBar
被隐藏。因此,我为键盘可见性更改添加了一个侦听器,并根据键盘的高度调整了约束。这似乎很有效

但是,如果用户点击键盘上的最小化按钮,键盘不会完全消失。允许在输入字段之间切换的箭头键的顶部栏(我不知道如何称呼它)将保持可见。因此,我无法将约束设置回0,我必须根据可视键盘的高度(我认为会包括顶部栏)再次设置约束

但是,当我的
UIKeyboardDidHideNotification
启动时,键盘高度仍然相同,因此我最终会这样

我移动约束的逻辑基于以下方式获取键盘高度:

   // get height of visible keyboard
    NSDictionary* keyboardInfo = [aNotification userInfo];
    NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

    _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;
UIKeyboardFrameBeginUserInfo键是否不是隐藏键盘时使用的基础值

这个视图控制器的整个源代码目前实际上非常简单,所以我将包括所有的源代码,以防以后有人需要它

    #import "LEPopupBrowserViewController.h"

    @interface LEPopupBrowserViewController ()
    @property (weak, nonatomic) IBOutlet UIWebView *webView;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *toolbarBottomVerticalSpaceConstraint;

    @end

    @implementation LEPopupBrowserViewController

    - (void)viewDidLoad {
        [super viewDidLoad];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

        if (_url != nil) {
            NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:_url]];
            [_webView loadRequest:request];
        }
    }

- (void) viewDidUnload {
    [[NSNotificationCenter defaultCenter]  removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]  removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

    // Called when the UIKeyboardDidShowNotification is sent.
    - (void)keyboardWillShow:(NSNotification*)aNotification
    {
        // get height of visible keyboard
        NSDictionary* keyboardInfo = [aNotification userInfo];
        NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
        CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

        _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;
    }

    // Called when the UIKeyboardWillHideNotification is sent
    - (void)keyboardDidHide:(NSNotification*)aNotification
    {
        // get height of visible keyboard
        NSDictionary* keyboardInfo = [aNotification userInfo];
        NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
        CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];

        _toolbarBottomVerticalSpaceConstraint.constant = -1 * keyboardFrameBeginRect.size.height;
    }


    /*
    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    - (IBAction)doneButtonPressed:(id)sender {
        // close keyboard if present
        [self.view endEditing:YES];

        // dismiss ourselves
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    @end
更新

我通过一些附加视图发现,这个附加视图被称为
accessoryView
。我看到很多人都在尝试,但是没有发现任何你能轻易找到它的高度的东西。对我来说,删除它的麻烦之处在于苹果可能会拒绝你的应用