2015-09-28 30 views
3

所有工作良好,直到iOS的8 但是當文本字段控制用戶水龍頭來直接UIKeyboardWillHideNotification通知 登錄難道不會控制檯找出支持類型4 keyplane鍵盤iPhone-PortraitTruffle-NumberPad;使用675849259_PortraitTruffle_iPhone-簡單Pad_DefaultUIKeyboardWillShowNotification沒有要求,只UIKeyboardWillHideNotification調用的iOS 9

這裏是代碼 -

` 
In view did load 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.txtMobNumber.delegate = self; 
    self.txtMobNumber.keyboardType = UIKeyboardTypeNumberPad; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:@"UIKeyboardWillShowNotification" object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:@"UIKeyboardWillHideNotification" object:nil]; 
} 

notification callback 
- (void)keyboardWillShow:(NSNotification *)notification 
{ 
    // Save the height of keyboard and animation duration 
    NSDictionary *userInfo = [notification userInfo]; 
    CGRect keyboardRect = [userInfo[@"UIKeyboardBoundsUserInfoKey"] CGRectValue]; 
    [UIView beginAnimations:@"moveKeyboard" context:nil]; 
    float height = keyboardRect.size.height-60; 
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - height, self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 
    // [self setNeedsUpdateConstraints]; 
} 
// Reset the desired height 
- (void)keyboardWillHide:(NSNotification *)notification 
{ 
    // Reset the desired height (keep the duration) 
    NSDictionary *userInfo = [notification userInfo]; 
    CGRect keyboardRect = [userInfo[@"UIKeyboardBoundsUserInfoKey"] CGRectValue]; 
    [UIView beginAnimations:@"moveKeyboard" context:nil]; 
    float height = keyboardRect.size.height-60; 
    self.view.frame = CGRectMake(self.view.frame.origin.x,   self.view.frame.origin.y + height, self.view.frame.size.width, self.view.frame.size.height); 
    [UIView commitAnimations]; 

} 

` 
+0

這是模擬器的問題 –

+1

我有一個類似的問題。你的代碼只能在真實的設備上工作嗎? –

回答

10

這可以爲仿真設置,看到菜單中的「硬件>鍵盤>連接鍵盤硬件」有關。如果此選項爲ON,您將獲得UIKeyboardWillHideNotification,但從未UIKeyboardWillShowNotification

相關問題