博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS隐藏键盘
阅读量:7125 次
发布时间:2019-06-28

本文共 2118 字,大约阅读时间需要 7 分钟。

最近遇到二个键盘会自动弹出的问题:

1、UIWebView加载网页后,点击网页内的链接在UIWebView内进行跳转时,键盘自动弹起;

2、调用选择照片时,iPod上选择照片后也会自动弹出键盘,比如从图库进到具体某个文件夹内,或者再返回图库,直接点中照片然后编辑的时候,都会自动弹出;

 

问题一是这样处理的

- (void)webViewDidStartLoad:(UIWebView*)webView {
    [activityIndicatorView_ startAnimating];         // update by zhangyi     [[[UIApplication sharedApplication] keyWindow] endEditing:YES];     [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)webViewDidFinishLoad:(UIWebView*)webView {
    [activityIndicatorView_ stopAnimating];         [[[UIApplication sharedApplication] keyWindow] endEditing:YES];     [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; } - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error {
    [activityIndicatorView_ stopAnimating];         UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:@"" message:[error localizedDescription]  delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];     [alterview show];     [alterview release]; }

网页开始加载或加载结束时关闭键盘并发送关闭键盘的事件,如果webViewDidFinishLoad()不被调用是因为uiwebview对象需要设置delegate为self。UIWebView的透明设置,只需要增加二个属性

webView_.opaque = NO; webView_.backgroundColor = [UIColor clearColor];

 

第二个问题的处理方案是,在导航切换的时候隐藏键盘并发送关闭键盘的事件

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size;     [self HiddenStatusBarForIOS7];         // update by zhangyi     [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; }   // update by zhangyi -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];        [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; }

 

因为接触ios也不算特别多,暂时就使用了上述的方法来处理了。

 

 

参考:

转载地址:http://jheel.baihongyu.com/

你可能感兴趣的文章
div 居中
查看>>
Scala 深入浅出实战经典 第65讲:Scala中隐式转换内幕揭秘、最佳实践及其在Spark中的应用源码解析...
查看>>
UIKit的手风琴菜单,单条展开和多条同时展开
查看>>
Entity Framework 学习总结之一:ADO.NET 实体框架概述
查看>>
缺少动态连接库.so--cannot open shared object file: No such file or directory
查看>>
Myeclipse 10/2014 配置插件(svn、maven、properties、velocity)方法
查看>>
emacs quick open and jump file (or buffer) which name is current word
查看>>
(二) 第十二回:廊前无心曲动人 场边有意文偏心【林大帅作品】
查看>>
理解SVG的图形填充规则
查看>>
在Android下运行Linux平台编译的程序
查看>>
C语言中getch()、getche()和getchar()
查看>>
如何调试 Android 上 HTTP(S) 流量
查看>>
这么多开源框架,该用哪个好?
查看>>
Android onTouch、OnLongClick、onClick和ScrollView滑动事件冲突
查看>>
Chromium Graphics: GPUclient的原理和实现分析之间的同步机制-Part II
查看>>
倒车流程2
查看>>
Oracle 12C -- plug unplugged PDB into CDB
查看>>
php多进程编程相关资料(以备参考)
查看>>
js原生设计模式——3简单工厂模式\js面向对象编程实例
查看>>
Xcode真机测试could not find developer disk image解决方法
查看>>