Rob*_*Rob 5 objective-c ipad ios7 textkit
我正在使用iOS 7中的Text Kit,我在NSTextContainer禁区附近发现了很多奇怪的东西.
我有两种观点:a UITextView和简单的可拖动UIView; 作为UIView移动,我从UIView框架创建了一条bezier路径(调整到UITextView坐标空间内)并更新了UITextViews NSTextContainer的exclusionPaths数组 - 非常简单.
在第一个屏幕截图中,您可以看到Text Kit很好地将文本包装在矩形排除区域周围:

但是,当用户在其中引入换行符时UITextView,TextKit似乎认为禁区的垂直区域要大得多 - 看起来与换行符创建的空格一样高.bezier路径完全相同,所以这似乎是一个Text Kit问题(除非我做错了).

码:
ViewController.h:
@interface ViewController : UIViewController<UITextViewDelegate>
@property (nonatomic, strong) IBOutlet UITextView *textView;
@property (nonatomic, strong) IBOutlet UIView *dragView;
@end
Run Code Online (Sandbox Code Playgroud)
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];
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我今天遇到了同样的问题.
如果你同时设置editable,这个错误似乎就出现selectable了.如果仅选择一个或否,则按预期呈现.两者都默认选中.


如果您需要两个选项,只需在代码中设置它们即可.
_textView.textContainer.exclusionPaths = exclusionPaths;
_textView.attributedText = attrString;
_textView.editable = YES;
_textView.selectable = YES;
Run Code Online (Sandbox Code Playgroud)