Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 #36

Closed
hydyy opened this issue Nov 26, 2015 · 33 comments

Comments

@hydyy
Copy link

hydyy commented Nov 26, 2015

  • (void)textViewDidChange:(YYTextView *)textView {

    NSAttributedString *text = textView.attributedText;
    if ([textView.text isEqualToString:@""]) {
    text = textView.placeholderAttributedText;
    }

    CGSize size = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:text];

    CGSize newSize = CGSizeMake(layout.textBoundingSize.width, layout.textBoundingSize.height);

    NSLog(@"layout.textBoundingSize :%@",NSStringFromCGSize(layout.textBoundingSize));
    NSLog(@"self.textView.contentSize :%@",NSStringFromCGSize(self.textView.contentSize));

    self.textView.size = newSize;
    self.textView.contentSize = newSize;

}

log:
2015-11-26 17:48:49.218 testTextView[8110:1979479] layout.textBoundingSize :{249, 23}
2015-11-26 17:48:49.218 testTextView[8110:1979479] self.textView.contentSize :{240, 50}

@hydyy
Copy link
Author

hydyy commented Nov 26, 2015

ios9 下面会崩溃。 找不到原因。。。。

@ibireme
Copy link
Owner

ibireme commented Nov 26, 2015

  1. 文本跳动有两个原因:一个是当改变了布局方向宽度时,文本要重排;另一个是输入文本后,内容会用动画滑动到当前输入的位置。这个稍后我会进行优化、添加配置属性。
  2. 崩溃这个我没有定位到,能提供一下 crash log 或者 crash 断点处的截图吗?

@hydyy
Copy link
Author

hydyy commented Nov 26, 2015

谢大婶! 我发给您的viewcontroller 在ios9崩溃 捉不到是哪里引起的 好奇怪 .. 方便加您微信嘛? 明儿我去公司了把问题拍图给你啊 ! 大婶 交个微信吧

发自我的 iPhone

在 2015年11月26日,下午10:47,Yaoyuan notifications@github.com 写道:

文本跳动有两个原因:一个是当改变了布局方向宽度时,文本要重排;另一个是输入文本后,内容会用动画滑动到当前输入的位置。这个稍后我会进行优化、添加配置属性。

崩溃这个我没有定位到,能提供一下 crash log 或者 crash 断点处的截图吗?


Reply to this email directly or view it on GitHub.

@LiuSky
Copy link

LiuSky commented Nov 27, 2015

不需要根据2015-11-26 17:48:49.218 testTextView[8110:1979479] layout.textBoundingSize :{249, 23}
2015-11-26 17:48:49.218 testTextView[8110:1979479] self.textView.contentSize :{240, 50} 这两个属性,如果你的行高固定,你可以通过textLayout.rowCount 来反推textview的高度,我是这样子做的。也不会动画抖动多次。而且我是去观察contentSize 的变化。

@ibireme
Copy link
Owner

ibireme commented Nov 27, 2015

Github Issues 这里可以直接贴图片的,把图片拖到发布框就可以上传了。

@hydyy
Copy link
Author

hydyy commented Nov 27, 2015

@LiuSky 固宽用contentSize没什么问题, 宽度也要随着发生变化的。
另外,文字跳动的问题这样也解决不了呀。

rowCount 我刚刚看了一下,换行之后count还是没有变。

@hydyy
Copy link
Author

hydyy commented Nov 27, 2015

@ibireme sorry 崩溃的问题跟框架无关, 已经解决了。

1、单行跳动
2、换行高度没有计算
3、早上看了下发现如果拖动的话上面会有好多空行。
Uploading demo.gif…

@LiuSky
Copy link

LiuSky commented Nov 27, 2015

@hydyy 哪我就不知道你怎么写的了。我这边完全没问题,估计你是没观察contentSize

@ibireme
Copy link
Owner

ibireme commented Nov 27, 2015

请楼上更新一下代码,这是之前的一个已知 bug:#27

@hydyy
Copy link
Author

hydyy commented Nov 27, 2015

@ibireme okok, 弱弱的问一下, 那个单行跳动 换行高度计算 这俩问题 额 怎么解决呀

@ibireme
Copy link
Owner

ibireme commented Nov 29, 2015

  1. 对于你的单行跳动,目前只能给一个 workaround:不要修改文本框的宽度。。
    之后我可能会尝试修改文本重排的逻辑和配置。。
  2. CoreText/YYTextLayout 对于文本结尾的换行符是不会计算高度的。
    YYTextView 内部为了保证输入的可见性,是为文本额外加了一个空格来进行排版的,
    而 YYLabel 则仅会按照 CoreText/YYTextLayout 排版结果进行显示。

如果你希望额外增加结尾换行的高度,目前的 workaround 是为文本结尾处增加一个空格然后再计算。

@hydyy
Copy link
Author

hydyy commented Nov 30, 2015

@ibireme thx ,我先想想办法。

@hydyy
Copy link
Author

hydyy commented Dec 10, 2015

YYTextView 设置attributeString 之后是在线程中去绘制的嘛? 我现在的需求是设置完之后需要立即获取截图, 这时候发现YYTextView 是空的, 或者只有一部分文字。

如果是异步绘制,有没有回调呢?

@ibireme
Copy link
Owner

ibireme commented Dec 10, 2015

YYTextView 并没有异步绘制,它会在 RunLoop 结尾处、drawRect 内进行绘制。
如果要截图,可以延迟一个 loop 在进行。

@hydyy
Copy link
Author

hydyy commented Dec 10, 2015

延迟一个loop? sorry 不太懂这块 是说

self performSelector:<#(nonnull SEL)#> withObject:<#(nullable id)#> afterDelay:<#(NSTimeInterval)#> ??

@ibireme
Copy link
Owner

ibireme commented Dec 10, 2015

对~
或者 dispatch_after 也行。

@hydyy
Copy link
Author

hydyy commented Dec 13, 2015

这样的情况会闪退、、、

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月10日(周四) 17:50
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

对~
或者 dispatch_after 也行。

Reply to this email directly or view it on GitHub.

@hydyy
Copy link
Author

hydyy commented Dec 13, 2015

\r 前面加个空格就好了 我没有提代码了 就告诉你一下 我也不确定是否是正确的改法 你看看哇。

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月10日(周四) 17:50
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

对~
或者 dispatch_after 也行。

Reply to this email directly or view it on GitHub.

@ibireme
Copy link
Owner

ibireme commented Dec 14, 2015

能用就行

@ibireme ibireme closed this as completed Dec 14, 2015
@hydyy
Copy link
Author

hydyy commented Dec 14, 2015

额 对! 关键是 我直接修改到你的代码拉。 现在都不敢pod update了

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月14日(周一) 11:03
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

能用就行

Reply to this email directly or view it on GitHub.

@hydyy
Copy link
Author

hydyy commented Dec 15, 2015

这里换行前面的空格去掉就会闪退, 加上这个空格就没事。。 是特殊字符跟了一个换行 就会有问题的意思么

@ibireme
Copy link
Owner

ibireme commented Dec 15, 2015

不清楚,能给下你的使用方法、崩溃日志和断点吗?

@hydyy
Copy link
Author

hydyy commented Dec 15, 2015

ios9.2真机 闪退。
模拟器不会闪退。

就下面这个小demo

/////////////////////////////////////////////

  • (void)viewDidLoad {
    [super viewDidLoad];

    self.currentFont = [UIFont fontWithName:@"Times New Roman" size:20];

    NSString *str = @" 😯狗狗不理(😷🤖👹🤖\n👽😾👊🏼🏛🍜🍠◽️☆_\n🔛🔲🔊🔔🔇🇫🇯🇬🇲☆)入";
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    text.yy_font = self.currentFont;
    text.yy_lineSpacing = 4;

    self.textView.attributedText = text;
    self.textView.center = self.view.center;

    [self.view addSubview:self.textView];
    }

  • (void)textViewDidChange:(YYTextView *)textView {

    NSAttributedString *text = textView.attributedText;
    if ([textView.text isEqualToString:@""]) {
    text = textView.placeholderAttributedText;
    }

    CGSize size = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
    YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:text];

    NSLog(@"layout.rowCount :%@",@(layout.rowCount));

    CGSize newSize = CGSizeMake(layout.textBoundingSize.width, layout.textBoundingSize.height);
    self.textView.size = newSize;
    }

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月15日(周二) 12:14
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

不清楚,能给下你的使用方法、崩溃日志和断点吗?

Reply to this email directly or view it on GitHub.

@ibireme
Copy link
Owner

ibireme commented Dec 15, 2015

找了个 iOS 9.2 的设备测试,没有复现。
你能给个崩溃时,Xcode 停留到的代码行位置吗(All Exceptions 断点)?

@hydyy
Copy link
Author

hydyy commented Dec 18, 2015

我这里容器的大小是根据内容走的, 当容器大小zero的时候, 设置那段文本就会崩溃。

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月15日(周二) 16:17
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

找了个 iOS 9.2 的设备测试,没有复现。
你能给个崩溃时,Xcode 停留到的代码行位置吗(All Exceptions 断点)?

Reply to this email directly or view it on GitHub.

@ibireme
Copy link
Owner

ibireme commented Dec 18, 2015

还没复现。能给个崩溃时的日志或断点吗?你这么描述定位不到问题啊。。

举个例子:
2015-12-18 1 29 09
2015-12-18 1 28 55

@hydyy
Copy link
Author

hydyy commented Dec 18, 2015

哥,真心不是不给你, 是跟着到这 就挂了。。 直接崩溃。。。没有断点。。。

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月18日(周五) 13:31
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

还没复现。能给个崩溃时的日志或断点吗?你这么描述定位不到问题啊。。
举个例子:


Reply to this email directly or view it on GitHub.

@hydyy
Copy link
Author

hydyy commented Dec 18, 2015

我试了, 如果把那个换行干掉 或者前面加个空格 就可以了。。。。。 但是这治标不治本啊~

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月18日(周五) 13:31
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

还没复现。能给个崩溃时的日志或断点吗?你这么描述定位不到问题啊。。
举个例子:


Reply to this email directly or view it on GitHub.

@hydyy
Copy link
Author

hydyy commented Dec 22, 2015

这边bug再修不了就不美妙了。。 压力山大啊。

@ibireme
Copy link
Owner

ibireme commented Dec 22, 2015

我不清楚 bug 是什么。。你又提供不了崩溃日志。。

除非内存不够导致 app 被干掉,不然不可能捕获不到崩溃问题。

@hydyy
Copy link
Author

hydyy commented Dec 22, 2015

6s 理论上不可能内存不够

之前邮件里给您发了截图了 就是在那个位置崩溃的..

情况应该是初始化的时候, 加载了那段文本,是因为内存崩溃的。
我试验了,如果先去设置frame ,再去加载那个文本段,就不会崩溃了。

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月22日(周二) 17:50
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

我不清楚 bug 是什么。。你又提供不了崩溃日志。。
除非内存不够导致 app 被干掉,不然不可能捕获不到崩溃问题。

Reply to this email directly or view it on GitHub.

@ibireme
Copy link
Owner

ibireme commented Dec 22, 2015

如果有图片,最好在 Github Issues 界面里贴图,不要在邮件里回复。我在邮件里没有看到图片。。

首先,在工程配置里设置 Debug 模式:
2015-12-22 6 07 57

开启 Address Sanitizer
2015-12-22 6 08 11

然后加上 All Exceptions 断点
2015-12-22 6 08 19

连机调试,在崩溃时把整个 Xcode 停止的界面截图下来。

@hydyy
Copy link
Author

hydyy commented Dec 22, 2015

原来你没有看到图片啊 哭瞎。。。 我尽快试试 然后发给你

原始邮件
发件人:Yaoyuannotifications@github.com
收件人:ibireme/YYTextYYText@noreply.github.com
抄送:Adamhouyaodong@qq.com
发送时间:2015年12月22日(周二) 18:10
主题:Re: [YYText] 根据内容改变容器size 单行时会跳动, 并且回车换行没有计算到高度里。 (#36)

如果有图片,最好在 Github Issues 界面里贴图,不要在邮件里回复。我在邮件里没有看到图片。。
首先,在工程配置里设置 Debug 模式:

开启 Address Sanitizer

然后加上 All Exceptions 断点

连机调试,在崩溃时把整个 Xcode 停止的界面截图下来。

Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants