ios uitextview 怎么设置编辑时弹出ios模拟器键盘不弹出

ios&弹出键盘挡住UITextView的解决方式
有一个320*480的UITextView,点击UITextView的时候,下面的部分会被弹出的软键盘挡住,我们可以将UITextView的高度改为480
- 软键盘的高度,关闭软键盘后,高度恢复为原始高度。
- (void)viewDidLoad
&&& [super
viewDidLoad];&
self.textView = [[UITextView alloc]
initWithFrame:self.view.frame];
self.textView.textColor = [UIColor blackColor];
self.textView.font = [UIFont fontWithName:@"Arial" size:18];
self.textView.backgroundColor = [UIColor
whiteColor];&&&
self.textView.text = @"This is the text view example, we can edit,
delete, add content in the text view.";
self.textView.returnKeyType = UIReturnKeyD
self.textView.keyboardType = UIKeyboardTypeD
self.textView.scrollEnabled = YES;
self.textView.autoresizingMask =
UIViewAutoresizingFlexibleH
&&& [self.view
addSubview: self.textView];
[self.textView release];
- (void)viewDidUnload
&&& [super
viewDidUnload];
self.textView =
- (void)dealloc {
&&& [textView
release], textView =
&&& [super
- (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)viewDidDisappear:(BOOL)animated
&&& [super
viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification object:nil];
- (void)keyboardWillShow:(NSNotification *)aNotification
&&& CGRect
keyboardRect = [[[aNotification userInfo]
objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
NSTimeInterval animationDuration = [[[aNotification userInfo]
objectForKey:UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
&&& CGRect frame
= self.view.
frame.size.height -= keyboardRect.size.
&&& [UIView
beginAnimations:@"ResizeForKeyboard" context:nil];
&&& [UIView
setAnimationDuration:animationDuration];
self.view.frame =
&&& [UIView
commitAnimations];
- (void)keyboardWillHide:(NSNotification *)aNotification
&&& CGRect
keyboardRect = [[[aNotification userInfo]
objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
NSTimeInterval animationDuration = [[[aNotification userInfo]
objectForKey:UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
&&& CGRect frame
= self.view.
frame.size.height += keyboardRect.size.
&&& [UIView
beginAnimations:@"ResizeForKeyboard" context:nil];
&&& [UIView
setAnimationDuration:animationDuration];
self.view.frame =
&&& [UIView
commitAnimations];
也可以参考帖子:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。UITextView怎么让键盘消失同时保持编辑状态_问答_ThinkSAAS
UITextView怎么让键盘消失同时保持编辑状态
UITextView怎么让键盘消失同时保持编辑状态
我的需求是,光标还是在UITextView里,但是需要键盘退下来。如果我用 resignFirstResponder ,光标就不在里边了。
有没有什么办法,让键盘退下去,但是光标不变,还是在里边
1.让提需求的人去死
2.贴个图装一下。。
添加你想要问的问题
PHP开发框架
开发工具/编程工具
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
让ThinkSAAS更好,把建议拿来。
开发客服微信这样的情况大体有三种原因:
1.弹出窗被更高层次的窗口遮挡了,从界面上看不出键盘窗的响应。
我们可以通过以下的方法来检测应用中所有窗口的等级
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
NSLog(@&isKeyWindow = %d window level = %.1f frame = %@ class = %@\n&,
window.isKeyWindow, window.windowLevel,
NSStringFromCGRect(window.frame), window.class.description);
这种原因的解决办法:可以使用UIView的继承关系来代替自定义UIWindow 的使用。
2.iOS的输入控件虽然点击了,但是它没有成为第一响应者(First Response,原因是输入视图复写了UIView的-(Bool)canBecomeFirstResponse,但是返回了NO,因此该输入视图没有成为第一响应者,解决办法是返回 YES.
3.UIViewController支持旋转,这需要通过&来指定一个位掩码来决定转向,keyboard会根据这个位掩码来给出键盘放置的frame,如果位掩码指定出错,那么键盘的位置就有可能绘制在window之外,导致看不到。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1783次
排名:千里之外5524人阅读
转自/Content/420.html
在ios开发中有时候想让文本框获得焦点的时候弹出的不是键盘而是自定义的东西,这个可以通过改变textfield或者textview的inputView来设置;但是要是想在普通键盘上面加一个自定义的view可以通过改变textfield或者textview的inputAccessoryView属性来设置。例如:
(void)viewDidLoad
&&&&[super
viewDidLoad];
keyboardview];
mark - 键盘上的view
-(void)keyboardview
&&&&UIView
*inputview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
&&&&inputview.backgroundColor
= [UIColor blueColor];
&&&&UITextField
*text = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
text.inputAccessoryView
&&&&text.backgroundColor
= [UIColor redColor];
&&&&[self.view
addSubview:text];
这种情况下(设置inputAccessoryView)的效果如下图:
而如果这样
text.inputView
的结果是这样的:
但是如果这样
text.inputView&=//inputView是自定义点击text的时候弹出的view
text.inputAccessoryView =//inputAccessoryView是键盘上面附加的view
两句都执行的话,也不会出现自定义键盘view上还附加view的效果。
并且如果这样
text.inputView&=//inputView是自定义点击text的时候弹出的view
text.inputAccessoryView =//inputAccessoryView是键盘上面附加的view
这样第一句设置未nil是不会有效果的,貌似这两个属性不能同时设置似的。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:35707次
排名:千里之外
原创:23篇
转载:19篇
(1)(2)(1)(1)(5)(2)(5)(3)(8)(4)(3)(1)(1)(3)(1)(1)(2)

我要回帖

更多关于 ios监听键盘弹出事件 的文章

 

随机推荐