2010-06-14 4 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); 
    } 

} 

에서 더 이상 사용되지하지만이 코드는 아이폰 SDK 3.0에서 작동하지만이 코드는 아이폰 SDK에서 작동하지 않습니다 4.0은 uikeyboard 바운스 사용자 정보 키가 완료와 도구 모음을 만들하지 않습니다 아이폰 4.0 OS에서 사용되지 않는 것을 말한다 버튼 내가UIKeyboardBoundsUserInfoKey 아이폰 4.0 OS

답변

1

당신은

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

으로 시도 할 수 있습니다하지만 당신은 내 생각 숨길 수 할 수있는 방법 나를 인도 해주십시오. 사용자 정의보기를 표시 할 수 있지만 숨기기는 UIKeyboard입니다. iOS 4에서는 작동하지 않을 것이라고 생각합니다.