gpt4 book ai didi

ios - NSTextContainer exclusionPaths 卡住应用程序并在 iOS 7.1 上使用 99% 的 CPU - 解决方法?

转载 作者:技术小花猫 更新时间:2023-10-29 11:06:48 30 4
gpt4 key购买 nike

我正在尝试使用 NSTextContainer 的 excludePaths 排除 UITextView 中的一个正方形,如下所示:

NSTextStorage* textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString];
NSLayoutManager *layoutManager = [NSLayoutManager new];
[textStorage addLayoutManager:layoutManager];

NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:self.bounds.size];

UIBezierPath *rectanglePath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 250, 250)];
textContainer.exclusionPaths = @[rectanglePath];

[layoutManager addTextContainer:textContainer];

self.textView = [[UITextView alloc] initWithFrame:self.bounds textContainer:textContainer];
self.textView.editable = NO;
self.textView.scrollEnabled = NO;
[self addSubview:self.textView];

这在 iOS 7.0 中工作正常:

with iOS 7.0

然而,在 iOS 7.1 中,这将导致 NSTextContainer 的 lineFragmentRectForProposedRect:atIndex:writingDirection:remainingRect: 某处出现无限循环,使用 99% 的 CPU 并疯狂地泄漏内存。该应用程序完全没有响应,最终由于内存使用而终止。显然这是 iOS 7.1 中的错误。

当我将排除矩形的 x 原点更改一个点(原点为 {1,0})时,它有效,但看起来很糟糕:

with iOS 7.1 and one point to the right

该错误似乎只在第一行的第一个字符受到排除矩形的影响时才会发生。当我将排除矩形更改为 {0,30} 时,它也会起作用:

iOS 7.1 and 0,30

但显然这不是我想要的。有谁知道我该如何解决这个错误?

最佳答案

我有同样的问题,为了解决这个问题,我放置了:

mytextView.exclusionPaths = @[rectanglePath] 

进入layoutSubview方法。我希望这会对某人有所帮助

关于ios - NSTextContainer exclusionPaths 卡住应用程序并在 iOS 7.1 上使用 99% 的 CPU - 解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23542316/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com