iPhone 4.0 操作系统中已弃用 UIKeyboardBoundsUserInfoKey
-(void)keyboardWillShow : (NSNotification *)sender {
@try {
// NSLog(@"notification in first view");
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
NSValue *v = [[sender userInfo] valueForKey:UIKeyboardBoundsUserInfoKey];
CGRect kbBounds = [v CGRectValue];
if(keyboardToolbar == nil) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
keyboardToolbar.barStyle=UIBarStyleBlackOpaque;
keyboardToolbar.tintColor = [UIColor colorWithRed:0.6 green:0.2 blue:0.6039 alpha:1];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissKeyboard)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *items = [[NSArray alloc] initWithObjects:flex, barButtonItem, nil];
[keyboardToolbar setItems:items];
[items release];
}
[keyboardToolbar removeFromSuperview];
keyboardToolbar.frame = CGRectMake(0, 0, kbBounds.size.width, 45);
[keyboard addSubview:keyboardToolbar];
keyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y, kbBounds.size.width, kbBounds.size.height + 87);
for(UIView* subKeyboard in [keyboard subviews]) {
if([[subKeyboard description] hasPrefix:@"<UIKeyboardImpl"] == YES) {
subKeyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y - 45, kbBounds.size.width, kbBounds.size.height);
}
}
}
}
}
} @catch (NSException * e) {
// NSLog(@"Problem in keyboardWillShow:%@",e);
}
}
但此代码适用于 iphone sdk 3.0,但此代码不适用于 iphone SDK 4.0 它说 uikeyboard 弹跳用户信息键在 iphone 4.0 操作系统中已弃用 它不会创建带有完成按钮的工具栏 请指导我如何做到这一点
-(void)keyboardWillShow : (NSNotification *)sender {
@try {
// NSLog(@"notification in first view");
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
NSValue *v = [[sender userInfo] valueForKey:UIKeyboardBoundsUserInfoKey];
CGRect kbBounds = [v CGRectValue];
if(keyboardToolbar == nil) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
keyboardToolbar.barStyle=UIBarStyleBlackOpaque;
keyboardToolbar.tintColor = [UIColor colorWithRed:0.6 green:0.2 blue:0.6039 alpha:1];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissKeyboard)];
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *items = [[NSArray alloc] initWithObjects:flex, barButtonItem, nil];
[keyboardToolbar setItems:items];
[items release];
}
[keyboardToolbar removeFromSuperview];
keyboardToolbar.frame = CGRectMake(0, 0, kbBounds.size.width, 45);
[keyboard addSubview:keyboardToolbar];
keyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y, kbBounds.size.width, kbBounds.size.height + 87);
for(UIView* subKeyboard in [keyboard subviews]) {
if([[subKeyboard description] hasPrefix:@"<UIKeyboardImpl"] == YES) {
subKeyboard.bounds = CGRectMake(kbBounds.origin.x, kbBounds.origin.y - 45, kbBounds.size.width, kbBounds.size.height);
}
}
}
}
}
} @catch (NSException * e) {
// NSLog(@"Problem in keyboardWillShow:%@",e);
}
}
but this code works in iphone sdk 3.0 but this code does not work in iphone SDK 4.0 it says that uikeyboard bounce user info key deprecated in iphone 4.0 OS it does not create toolbar with done button please guide me how could i do that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试
但我认为你无法隐藏。您可以将自定义视图放在上面,但隐藏
UIKeyboard
我认为它不适用于 iOS 4。You can try with
But you cannot hide I think. You can put your custom view on it but hide the
UIKeyboard
I don't think it will work for iOS 4.