iOS虚拟键盘上添加动态隐藏按钮
2012-11-30 20:58:37 来源:WEB开发网核心提示:在这个函数方法中值得探讨的是关于键盘所包含信息,因为每一次键盘弹出的时候也是动画形式弹出,iOS虚拟键盘上添加动态隐藏按钮(2),他的坐标位置大小包含在userInfo的字典中,现在我用NSLog(@"-->info:%@",info);打印出info对象,按钮从视图上移除,或者释放按钮,这些
在这个函数方法中值得探讨的是关于键盘所包含信息,因为每一次键盘弹出的时候也是动画形式弹出,他的坐标位置大小包含在userInfo的字典中,现在我用
NSLog(@"-->info:%@",info);打印出info对象,这些信息都可以在不同存储类型,取值的时候注意取值方式,此处只是提一提,希望以后有时间在做探讨,

在这一段代码上,后面注释了5行,因为打算当键盘推出的时候,按钮从视图上移除,或者释放按钮,但是都导致了应用程序崩溃,后来就没有释放和移除操作了
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
NSLog(@"%@",NSStringFromSelector(_cmd));
if (exitButton.hidden==NO) {
exitButton.hidden = YES;
}
// if (exitButton.superview)
// {
// [exitButton removeFromSuperview];
// [exitButton release];
// }
}
-(void)adjustPanelsWithKeyBordHeight:(float) height
{
NSLog(@"%@",NSStringFromSelector(_cmd));
if (exitButton) {
CGRect exitBtFrame = CGRectMake(self.view.frame.size.width - 40, self.view.frame.size.height - height-30, 40.0f, 30.0f);
exitButton.frame = exitBtFrame;
[self.view addSubview:exitButton];
}
// UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
// if (exitButton.superview == nil)
// {
// [tempWindow addSubview:exitButton];
// // 注意这里直接加到window上
// }
}
-(void)CancelBackKeyboard:(id)sender
{
NSLog(@"%@",NSStringFromSelector(_cmd));
[textField resignFirstResponder];
}
- (void)viewDidUnload
{
[self setTextField:nil];
exitButton=nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)dealloc {
[textField release];
[exitButton release];
[[NSNotificationCenter defaultCenter] removeObserver:self];//移除所注册的通知
[super dealloc];
}
更多精彩
赞助商链接
