<small id='Nxy8O'></small><noframes id='Nxy8O'>

<tfoot id='Nxy8O'></tfoot>

    <i id='Nxy8O'><tr id='Nxy8O'><dt id='Nxy8O'><q id='Nxy8O'><span id='Nxy8O'><b id='Nxy8O'><form id='Nxy8O'><ins id='Nxy8O'></ins><ul id='Nxy8O'></ul><sub id='Nxy8O'></sub></form><legend id='Nxy8O'></legend><bdo id='Nxy8O'><pre id='Nxy8O'><center id='Nxy8O'></center></pre></bdo></b><th id='Nxy8O'></th></span></q></dt></tr></i><div id='Nxy8O'><tfoot id='Nxy8O'></tfoot><dl id='Nxy8O'><fieldset id='Nxy8O'></fieldset></dl></div>

        <bdo id='Nxy8O'></bdo><ul id='Nxy8O'></ul>
      <legend id='Nxy8O'><style id='Nxy8O'><dir id='Nxy8O'><q id='Nxy8O'></q></dir></style></legend>

    1. UIWebView 与 contentEditable(html 编辑),第一响应者处理?

      UIWebView with contentEditable (html editing), first responder handling?(UIWebView 与 contentEditable(html 编辑),第一响应者处理?)
      <tfoot id='5hRLM'></tfoot>
      <i id='5hRLM'><tr id='5hRLM'><dt id='5hRLM'><q id='5hRLM'><span id='5hRLM'><b id='5hRLM'><form id='5hRLM'><ins id='5hRLM'></ins><ul id='5hRLM'></ul><sub id='5hRLM'></sub></form><legend id='5hRLM'></legend><bdo id='5hRLM'><pre id='5hRLM'><center id='5hRLM'></center></pre></bdo></b><th id='5hRLM'></th></span></q></dt></tr></i><div id='5hRLM'><tfoot id='5hRLM'></tfoot><dl id='5hRLM'><fieldset id='5hRLM'></fieldset></dl></div>
        <tbody id='5hRLM'></tbody>

      <legend id='5hRLM'><style id='5hRLM'><dir id='5hRLM'><q id='5hRLM'></q></dir></style></legend>

          <bdo id='5hRLM'></bdo><ul id='5hRLM'></ul>

          <small id='5hRLM'></small><noframes id='5hRLM'>

                本文介绍了UIWebView 与 contentEditable(html 编辑),第一响应者处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为一个应用程序制作一个 html 编辑器组件(在 iOS 5.0 中使用带有 contentEditable 的 UIWebView),并陷入了如何处理 UIWebView 第一响应者状态

                I'm making an html editor component for an app (using UIWebView with contentEditable in iOS 5.0), and got stuck at how to handle UIWebView first responder status

                [webView isFirstResponder]、[webView becomeFirstResponder] 和 [webView resignFirstResponder] 似乎不起作用,我不知道如何通过代码使 webView 成为或退出它

                [webView isFirstResponder], [webView becomeFirstResponder] and [webView resignFirstResponder] don't seem to work, and i've no idea how to make the webView become or resign it by code

                如果有人知道如何解决这个问题,我将非常感激,在此先感谢!

                If anyone knows how to work this out i would be very grateful, thanks in advance!

                推荐答案

                下面是我如何在 UIWebView 子类中覆盖这些方法(content 是可编辑的 id元素):

                Here is how I overwrite these methods in a UIWebView subclass (content is the id of the editable element):

                -(BOOL)resignFirstResponder {
                    [self setUserInteractionEnabled:NO];[self setUserInteractionEnabled:YES];
                    return [super resignFirstResponder];
                }
                
                // only works on iOS 6+
                -(void)becomeFirstResponder {
                    self.keyboardDisplayRequiresUserAction = NO; // set here or during initialization  
                    // important note: in some situations (newer iOS versions), it is also required to first call `blur()` on the 'content' element, otherwise the keyboard won't show up as expected
                    [self stringByEvaluatingJavaScriptFromString:@"document.getElementById('content').focus()"];
                }
                
                -(BOOL)isFirstResponder{
                    if ([[self stringByEvaluatingJavaScriptFromString:@"document.activeElement.id=='content'"] isEqualToString:@"true"]) {
                        return YES;
                    }
                    else {
                        return NO;
                    }
                }
                

                isFirstResponder 只会在键盘显示后返回 true(例如,在 UIKeyboardWillShowNotification 会返回 false)

                isFirstResponder will only return true after the keyboard is shown (e.g, it will return false at UIKeyboardWillShowNotification)

                如果这是一个问题,另一种检查 UIWebView 是否是第一响应者的方法如下:

                In case this is an issue, another way to check if the UIWebView is the first responder is as follows:

                +(BOOL)isFirstResponder:(UIView *)v{
                    for (UIView *vs in v.subviews) {
                        if ([vs isFirstResponder] || [self isFirstResponder:vs]) {
                            return YES;
                        }
                    }
                    return NO;
                }
                -(BOOL)isFirstResponder{
                    return [[self class] isFirstResponder:self];
                }
                

                这样,即使在键盘动画完成(显示或隐藏)之前/之后,返回的值也会是YES.

                This way, the returned value will be YES even before/after the keyboard animation finishes (showing or hiding).

                这篇关于UIWebView 与 contentEditable(html 编辑),第一响应者处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Embed YouTube video - Refused to display in a frame because it set #39;X-Frame-Options#39; to #39;SAMEORIGIN#39;(嵌入 YouTube 视频 - 拒绝显示在框架中,因为它将“X-Frame-Options设置为“SAMEORIGIN)
                Stop embedded youtube iframe?(停止嵌入 youtube iframe?)
                YouTube iframe API: how do I control an iframe player that#39;s already in the HTML?(YouTube iframe API:如何控制 HTML 中已有的 iframe 播放器?)
                Switch/toggle div (jQuery)(切换/切换 div (jQuery))
                How to avoid name clashes in JavaScript widgets(如何避免 JavaScript 小部件中的名称冲突)
                Widget -what to do and what not(小部件 - 做什么和不做什么)

                  • <legend id='yeLLu'><style id='yeLLu'><dir id='yeLLu'><q id='yeLLu'></q></dir></style></legend>
                        <bdo id='yeLLu'></bdo><ul id='yeLLu'></ul>
                      • <tfoot id='yeLLu'></tfoot>

                        <small id='yeLLu'></small><noframes id='yeLLu'>

                          <tbody id='yeLLu'></tbody>

                          <i id='yeLLu'><tr id='yeLLu'><dt id='yeLLu'><q id='yeLLu'><span id='yeLLu'><b id='yeLLu'><form id='yeLLu'><ins id='yeLLu'></ins><ul id='yeLLu'></ul><sub id='yeLLu'></sub></form><legend id='yeLLu'></legend><bdo id='yeLLu'><pre id='yeLLu'><center id='yeLLu'></center></pre></bdo></b><th id='yeLLu'></th></span></q></dt></tr></i><div id='yeLLu'><tfoot id='yeLLu'></tfoot><dl id='yeLLu'><fieldset id='yeLLu'></fieldset></dl></div>