2019-07-11

键盘

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField

{

    UIWindow * window=[[[UIApplication sharedApplication] delegate] window];

    CGRectframe=[textField convertRect: textField.bounds toView:window];

    intoffset = frame.origin.y- (SCREEN_HEIGHT-260.0);//iPhone键盘高度216,iPad的为352

    if (IS_IPHONE_X) {

        offset = frame.origin.y- (SCREEN_HEIGHT-333.0);

    }

    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

    [UIView setAnimationDuration:0.5f];


    //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

    if(offset >0)

        self.view.frame=CGRectMake(0.0f, -offset,SCREEN_WIDTH,self.view.frame.size.height);

    [UIView commitAnimations];

    return YES;

}

- (BOOL)textFieldShouldReturn:(UITextField*)textField {

    self.view.frame = CGRectMake(0, EldenNav_Sta_Height, SCREEN_WIDTH, self.view.frame.size.height);

    [UIView commitAnimations];

    [textFieldresignFirstResponder];

    return YES;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。