【问题标题】:Newlines in iOS 7 UITextView breaking Text Kit exclusion zone wrappingiOS 7 UITextView 中的换行符打破了 Text Kit 禁区换行
【发布时间】:2013-09-28 14:36:53
【问题描述】:

我在 iOS 7 中使用 Text Kit,我发现 NSTextContainer 禁区周围有很多奇怪之处。

我有两个视图:一个UITextView 和一个简单的可拖动UIView;随着UIView 的移动,我从UIView 的框架创建一个贝塞尔路径(调整到UITextView 的坐标空间内),然后更新UITextViewNSTextContainerexclusionPaths数组 - 非常简单。

在第一个屏幕截图中,您可以看到 Text Kit 很好地将文本包裹在一个矩形禁区周围:

但是,当用户在 UITextView 中引入换行符时,TextKit 似乎认为禁区在垂直方向上要大得多 - 似乎与换行符创建的空白一样高。贝塞尔路径完全相同,所以这似乎是文本工具包问题(除非我做错了什么)。

代码:

ViewController.h:

@interface ViewController : UIViewController<UITextViewDelegate>

@property (nonatomic, strong) IBOutlet UITextView *textView;
@property (nonatomic, strong) IBOutlet UIView *dragView;

@end

ViewController.m:

-(void)viewDidLoad
{
    [super viewDidLoad];

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [self.dragView addGestureRecognizer:panRecognizer];

    [self updateExclusionZone];
}

-(void)move:(UIPanGestureRecognizer *)pan
{
    [self.view bringSubviewToFront:[pan view]];

    if ([pan state] == UIGestureRecognizerStateBegan) {
        NSLog(@"pan began");
    }

    self.dragView.center = [pan locationInView:self.view];
    [self updateExclusionZone];

    if ([pan state] == UIGestureRecognizerStateEnded) {
        NSLog(@"pan ended");
    }
}

-(void)updateExclusionZone
{
    CGRect dragViewFrame = self.dragView.frame;
    CGRect exclusionRect = [self.view convertRect:dragViewFrame toView:self.textView];

    UIBezierPath *exclusion = [UIBezierPath bezierPathWithRect:exclusionRect];

    self.textView.textContainer.exclusionPaths = @[exclusion];
}

有什么想法吗?

【问题讨论】:

    标签: objective-c ipad ios7 textkit


    【解决方案1】:

    我今天遇到了同样的问题。

    如果您同时设置editableselectable,似乎会出现此错误。如果只选择了一个或没有选择,它会按预期呈现。两者都默认选中。


    如果您需要这两个选项,只需在代码中设置它们即可。

    _textView.textContainer.exclusionPaths = exclusionPaths;
    _textView.attributedText = attrString;
    _textView.editable = YES;
    _textView.selectable = YES;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-27
      • 2013-11-27
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2016-06-07
      • 1970-01-01
      相关资源
      最近更新 更多