ios TextField 使用xib创建borderStyle为UITextBorderStyleNone的时候输入中文向下偏移问题

这种现象用代码创建TextField是不会出现的,xib创建会出现

原因:当在UINavigationController的管理下push到一个新界面的时候,默认的新界面的frame自动下拉了64(也就是导航栏和状态栏的高度),底部不会变,依然会在屏幕的最下方。其实这一切都是automaticallyAdjustsScrollViewInsets在作怪。self.automaticallyAdjustsScrollViewInsets 这个属性是IOS7才有的新方法,目的就是为了让scrollView自动适应屏幕。

xib中创建解决方法:

1.xib中设置borderStyle为UITextBorderStyleRoundedRect,拖线.m文件中,修改borderStyle:

TextField.borderStyle=UITextBorderStyleNone;就可以了

2.创建一个继承TextField的类,重写下如下方法也可解决:

- (CGRect)editingRectForBounds:(CGRect)bounds {

return CGRectInset( bounds , 1 , 0 );

}

你可能感兴趣的:(ios TextField 使用xib创建borderStyle为UITextBorderStyleNone的时候输入中文向下偏移问题)