IOS——UITextField自動適應鍵盤彈出

    //鍵盤變化監聽
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardChange:) name:@"UIKeyboardWillChangeFrameNotification" object:nil];



- (void)keyboardChange:(NSNotification *)aNotification
{
    NSValue *value = [[aNotification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"];
    float keyEnd_y = [value CGRectValue].origin.y;
    float animationDuration = [[aNotification userInfo][@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
    
    
    CGRect frame = [[UIScreen mainScreen]bounds];//屏幕尺寸
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y = keyEnd_y - frame.size.height;
    self.view.frame = viewFrame;
    
    [UIView animateWithDuration:animationDuration animations:^{
    }];
    
}
相關文章
相關標籤/搜索