iPhone 4.0 操作系统中已弃用 UIKeyboardBoundsUserInfoKey

发布于 2024-09-05 17:38:39 字数 2415 浏览 6 评论 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);
    }

}

但此代码适用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间☆小暴躁 2024-09-12 17:38:39

你可以尝试

if ([[currentWindow description] hasPrefix:@"<UITextEffectsWindow"])
        {
            NSLog(@"Key board found");
}

但我认为你无法隐藏。您可以将自定义视图放在上面,但隐藏 UIKeyboard 我认为它不适用于 iOS 4。

You can try with

if ([[currentWindow description] hasPrefix:@"<UITextEffectsWindow"])
        {
            NSLog(@"Key board found");
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文