<span id="Label3"></p><p><p>+-------------------------+</p></p><p><p><span style="font-family:‘Courier New‘">Suppose you have the following questions, perhaps this article will help YOU.</span></p></p> <ol> <ol> <li><span style="font-family:Courier New">The keyboard covers the UIWEBVIEW.</span></li> <li><span style="font-family:Courier New">How to drag the UIWebView to remove the Keyboard.<p></p><p></p></span></li> <li><span style="font-family:Courier New">When the keyboard appears, the content contents of the UIWebView move up. Even the focused text box is outside the viewable area of the UIWEBVIEW.<p></p><p></p></span></li> <li><span style="font-family:Courier New">How to prevent the content of UIWebView from moving up when the keyboard pops up.</span></li> <li><span style="font-family:Courier New">Coordinates cannot be obtained in UIWebView to calculate contentoffset to get the results you want to SHOW.<p></p><p></p></span></li> </ol> </ol><p><p>+-------------------------+</p></p><p><p><br></p></p><span style="font-family:Courier New">Step by step <span style="font-family:Courier New">Instructions:</span></span><span style="color:#663300"><span style="color:#663300">1. Remove the keyboard</span></span><p><p><span style="white-space:pre"></span>Just click on the HTML TextBox control inside the UIWebView and you will pop the keyboard yourself.</p></p><p><p>Of course you need to get the information of the keyboard (height, etc.), or use the uiviewcontroller+notification method, such as the following code:</p></p><p><p></p></p><pre code_snippet_id="455191" snippet_file_name="blog_20140821_1_2969656" name="code" class="objc">Uikeyboardwillshownotification and uikeyboardwillhidenotification The name of the iOS system post notification when the keyboard is ejected or Removed. It is only necessary to define self as the recipient of this Notification. Viewwillappear: and viewwilldisappear: It should be clear to everyone that the two methods run after self Loadview and Removefromsuperview respectively. Special Note: Here the object should be nil, or not the keyboard userinfo-(void) viewwillappear: (BOOL) animated {[super viewwillappear:animated]; [[nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillshow:) name: Uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillhide:) name: Uikeyboardwillhidenotification object:nil]; }-(void) viewwilldisappear: (BOOL) Animated {[super viewwilldisappear:animated]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillhidenotification object:nil];} -(void) keyboardwillshow: (nsnotification *) notification {nsdictionary *userinfo = [notification userInfo]; nsvalue* value = [userInfo objectforkey:uikeyboardframeenduserinfokey]; CGRect keyboardrect = [value cgrectvalue]; Here you get the keyboard frame//your operation, such as the keyboard appears. control view Up}-(void) keyboardwillhide: (nsnotification *) notification {//get info with the above method//your operation, such as keyboard removal. control view restore, etc.}</pre><br><span style="color:#663300"><span style="color:#663300">2. Remove the keyboard by dragging UIWebView</span></span><p><p><span style="color:rgb(102,51,0); white-space:pre"></span><span style="color:#330000">Seeing very many people on the internet has done a lot of work to achieve this Function. But Apple has provided this to us in iOS7. The code is as Follows:</span></p></p><pre code_snippet_id="455191" snippet_file_name="blog_20140821_2_9839737" name="code" class="objc" style="color: rgb(51, 0, 0);"><pre code_snippet_id="455191" snippet_file_name="blog_20140821_2_9839737" name="code" class="objc" style="color: rgb(51, 0, 0);">Self.webView.scrollView.keyboardDismissMode = uiscrollviewkeyboarddismissmodeondrag; Remove keyboard when dragging</pre></pre><p><p><span style="color:rgb(102,51,0); white-space:pre"></span>Assuming is iOS7 below, please take a look at <span style="color:#ff0000">6</span> to set, approximate idea, first add a private flag to indicate whether the keyboard exists today, when present, through <span style="color:#ff0000">6</span> to get the event off the Keyboard.</p></p><span style="color:#663300"><span style="color:#663300">3. The keyboard covers the UIWebView</span></span><span style="white-space:pre"><span style="white-space:pre"></span></span>This solution can be<span style="color:#ff0000"><span style="color:#ff0000">1</span></span>In the keyboardwillshow: inside Operation. By changing the origin of WEBVIEW.<span style="color:#663300"><span style="color:#663300">4. When the keyboard appears, the content contents of the UIWebView move up. Even the focused text box is outside the viewable area of the UIWebView</span></span><p><p><span style="white-space:pre"></span>In uiwebview, only the keyboard appears. UIWebView will certainly move upward, as for the fit is not good to say, the assumption is not Appropriate. Just use disable yourself to move actively.</p></p><span style="color:#663300"><span style="color:#663300">5. How to prevent the content of UIWebView from moving up when the keyboard pops up</span></span><p><p><span style="white-space:pre"></span>This method. I've been looking for a very long time. But still found, thanks to powerful netizens, code such as the Following:</p></p><p><p></p></p><pre code_snippet_id="455191" snippet_file_name="blog_20140821_3_3569491" name="code" class="objc"><pre code_snippet_id="455191" snippet_file_name="blog_20140821_3_3569491" name="code" class="objc">@interface Xxx:uiviewcontroller<uiscrollviewdelegate>//join uiscrollviewdelegate, Step 1self.webview.scrollview.delegate = self; Register Agent. Step 2-(uiview*) viewforzoominginscrollview: (uiscrollview*) scrollview{//implement proxy method, Step 3 return nil;}</pre></pre><p><p></p></p><span style="color:#663300"><span style="color:#663300">6. How to get the click coordinates in UIWebView</span></span><p><p><span style="white-space:pre"></span>As is known to all, UIWebView eats all the touch events. Otherwise there will not be so many people to make javascript, but can not be set does not mean that can not be replaced in the second way. Approximate idea: add gestures to Webview's superview, and then implement multiple gesture filtering settings. Why do you want to set up Multi-gesture filtering? I'll explain here, because UIWebView has its own gesture by default, it intercepts your gestures, and Superview can't receive Gestures. The code is as Follows:</p></p><p><p></p></p><pre code_snippet_id="455191" snippet_file_name="blog_20140821_4_6743620" name="code" class="objc"><pre code_snippet_id="455191" snippet_file_name="blog_20140821_4_6743620" name="code" class="objc"> @interface Xxx:uiviewcontroller<uigesturerecognizerdelegate>//join uigesturerecognizerdelegate, Step 1//add gesture, Step 2UITapGestureRecognizer *webtap = [[uitapgesturerecognizer alloc] initwithtarget:self action: @selector (webtap:)]; webtap.numberoftouchesrequired = 1;webtap.numberoftapsrequired = 1;webtap.delegate = self; Webtap.cancelstouchesinview = NO; [self.view addgesturerecognizer:webtap];//settings filter, Ruturn Yes is received at the same time, this gesture can be through the WEBVIEW. Let your superview also be able to receive, step (BOOL) gesturerecognizer: (uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (uigesturerecognizer *) Othergesturerecognizer{return YES;} -(void) webtap: (uitapgesturerecognizer *) sender{cgpoint tappoint = [sender locationInView:self.webView.scrollView] ; Gets the coordinates relative to the webview, assuming that the change to Self.view gets the coordinates relative to superview, step 4 NSLog (@ "tappoint x:%f y:%f", tappoint.x,tappoint.y);} </pre> </pre><br>UIWebView keyboard processing can think of only these, Welcome to Add.<p><p></p></p><p><p></p></p><p><p></p></p>BB: Reprint please indicate the source<span style="color:#000000"><span style="color:#000000">http://blog.csdn.net/assholeu/article/details/38714123</span></span><br>Data references:<span style="white-space:pre"><span style="white-space:pre"></span></span>Thank<span style="color:#000000"><span style="color:#000000">http://blog.csdn.net/abel_tu/article/details/12134261</span></span><p><p><br></p></p><p><p>IOS UIWebView Keyboard Control</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service