2010-06-14 83 views
1
-(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 OS弃用它不与DONE创建工具栏按钮请指导我,我怎么能做到这一点UIKeyboardBoundsUserInfoKey在iPhone 4.0 OS

回答

1

您可以

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

尝试,但你不能躲,我认为。你可以把你的自定义视图,但隐藏UIKeyboard我不认为它会适用于iOS 4.

相关问题