当textView具有换行符时,exclusionPaths存在问题:
这是我的代码:
- (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]; }
结果如下:
问题在于换行符使exclusionPaths超出其应有的大小。在此处还描述了该问题:iOS 7 UITextView中的换行符打破了文本工具包排除区域的环绕,但它显示了如何使用Interface Builder创建UITextView时解决此iOS 7错误。如何以编程方式解决此问题?谢谢!
因此要禁用的获胜属性是“ scrollEnabled”:
textView.editable = NO textView.scrollEnabled = NO
上面的代码解决了exclusionPaths的问题