美文网首页程序员iOS开发记录iOS点点滴滴
修复textView换行不居中的系统bug

修复textView换行不居中的系统bug

作者: Mage | 来源:发表于2016-01-07 17:19 被阅读756次

有时,我们会有这样的需求,在使用UITextView作为输入框时,输入框换行需要输入框自适应变大,但在此过程中,文字经常不居中,如下图


QQ20160107-0.png

处理方法:
设置textView的代理,在textView换行滚动时强行将文字居中,代码如下

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if ([scrollView isKindOfClass:[UITextView class]]) {
        if ( scrollView.contentSize.height <= 200) {// 200  为textView的最大高度
            scrollView.contentOffset = CGPointZero;
        }else if(!scrollView.tag){
            scrollView.contentOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.frame.size.height);
        }
    }
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    scrollView.tag = 1;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    scrollView.tag = 0;
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    scrollView.tag = 1;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    scrollView.tag = 0;
}

相关文章

  • 修复textView换行不居中的系统bug

    有时,我们会有这样的需求,在使用UITextView作为输入框时,输入框换行需要输入框自适应变大,但在此过程中,文...

  • textView换行切换居中显示

    自定义个textView,重写下面2个func外部调用只需要改变textView对应行的高度即可

  • Android:多个TextView自动换行

    一个能够根据TextView长度自动换行的View(可能有bug) 代码 调用示例 xml activity

  • 工作问题记录

    TextView 一行文字不居中:荣耀6 Android 4.4.2 LG 5.0.1没有问题 是机型问题还是系统...

  • setText 换行

    textView 换行是支持"\n"换行符的。 用法是 textView.text=@"你想要输入的文本\n换行后...

  • 更新

    @127@#修复会员系统,修复语音商城bug,修复盗音关不了语音bug#¥http://t.cn/RYS7DZE¥

  • Android设置TextView

    1.设置TextView文字居中 2.设置textview控件在整个布局中居中 3.设置TextView文字上下距...

  • 1.54版本已上线

    1.54版本有一下改进 1. 修复了无法使用系统发音的bug 2. 修复了一些音频文件无法导入的bug 3. 修复...

  • android布局属性

    TextView android:scaleType="center" //居中显示 TableLayout an...

  • 微信热更新Tinker 使用及爬坑(一)

    什么是热修复 **定义 **: 热修复(HotFix)是以补丁的方式动态修复紧急Bug,不再需要重新发布App,不...

网友评论

    本文标题:修复textView换行不居中的系统bug

    本文链接:https://www.haomeiwen.com/subject/edufkttx.html