ios - UITextView 中包含新行的排除路径不正确

标签 ios cocoa-touch

当 textView 具有换行符时,我遇到排除路径问题:

这是我的代码:

- (void)viewDidLoad
{
  [super viewDidLoad];
  UIView *view = [[UIView alloc] init];
  UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 333, 360, 480)];
  view.frame = CGRectMake(50, 0, 50, 50);
  view.backgroundColor = [UIColor blackColor];
  NSLog(@"%@", NSStringFromCGRect(view.frame));
  [textView addSubview:view];

  CGRect relativeRect = [textView convertRect:view.bounds fromView:view];

  UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRect:relativeRect];
  textView.text = @"asddsaadasddsasdasdjsdhfjkdhkjdhfgjkldhsgfjlk\n\nhfdsgjklhdfsljkghdklfjgshdgjklfshdfgjklhfglkjdshjklgfdshjklgdfshkljfdsghfjkldghlkjfdghskljgdfhslkjgdfshjklgfdshjkgfdshlkjgdfhskljdgfhsjklgdhsjklfgdshjkglfdshjklgfdshlkjfgdhjklgdfshjdfkslghkjfdlsghjkldsfghjkhdfsgkjlhjgkldfshgdflksjhfdksgjhdfkjlgshfkljdshgjkdfhskjglhdfsjkghdfkjglhdsfkjghkljdfhgkjlhdsfkjlghjkldsfghjklhgsfdjklhgsdfkjlghdsfklgfdhsklg";
  textView.textContainer.exclusionPaths = @[bezierPath];
  [self.view addSubview:textView];

}

结果如下:

enter image description here

问题是新行字符使排除路径比应有的大。此处还描述了该问题:Newlines in iOS 7 UITextView breaking Text Kit exclusion zone wrapping ,但它展示了如果使用 Interface Builder 创建 UITextView 如何修复此 iOS 7 错误。我将如何以编程方式解决这个问题?谢谢!

最佳答案

因此,要禁用的获胜属性是“scrollEnabled”:

textView.editable = NO
textView.scrollEnabled = NO

上面的代码解决了我的排除路径问题

关于ios - UITextView 中包含新行的排除路径不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681960/

相关文章:

ios - writeToFile 和 writeToURL 有什么区别?

iPhone - 在屏幕上绘图以响应触摸事件

ios - 在 MonoTouch 中使用字典

ios - 自定义 Segue 动画不工作

ios - 如何在 Sprite 套件游戏的触摸方法中编写 UIbuttons/IBactions

objective-c - UICollectionView header 未显示

iphone - 从 iTunes Connect 自动下载销售报告

ios - Swift 2.0 ContactsUI 框架

ios - 如何在级联中设置 UIPickerView

iphone - 非法改变 NSFetchedResultsController 的获取请求