相关疑难解决方法(0)

如果全宽并且位于textContainer顶部,则UITextView textContainer排除路径将失败

在iOS 8中,我正在尝试添加UIImageView作为UITextView的子视图,类似于此处所示 - 但是图像下方的文本.

在此输入图像描述

我想使用排除路径来执行此操作,因为在其他设备上,我可能会根据屏幕大小对图像进行不同的定位.

但是有一个问题,如果用于创建排除路径的CGRect的Y原点为0,并占用textView的整个宽度,则排除失败并且文本显示在排除路径中(因此文本显示在后面imageView,你可以在截图中看到).

为了测试这个,我使用"单视图"Xcode模板构建了一个简单的应用程序,具有以下内容:

- (void)viewDidLoad {
    [super viewDidLoad];

    // set up the textView
    CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    UITextView *textView = [[UITextView alloc] initWithFrame:frame];
    [textView setFont:[UIFont systemFontOfSize:36.0]];
    [self.view addSubview:textView];
    textView.text = @"I wish this text appeared below the exclusion rect and not within it.";


    // add the photo

    CGFloat textViewWidth = textView.frame.size.width;

    // uncomment if you want to see that the exclusion path DOES work when not taking up the full width:
    // textViewWidth …
Run Code Online (Sandbox Code Playgroud)

uitextview ios nstextcontainer

14
推荐指数
2
解决办法
2764
查看次数

iOS 7 UITextView中的换行符打破了Text Kit排除区域换行

我正在使用iOS 7中的Text Kit,我在NSTextContainer禁区附近发现了很多奇怪的东西.

我有两种观点:a UITextView和简单的可拖动UIView; 作为UIView移动,我从UIView框架创建了一条bezier路径(调整到UITextView坐标空间内)并更新了UITextViews NSTextContainerexclusionPaths数组 - 非常简单.

在第一个屏幕截图中,您可以看到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 …
Run Code Online (Sandbox Code Playgroud)

objective-c ipad ios7 textkit

5
推荐指数
1
解决办法
3176
查看次数

标签 统计

ios ×1

ios7 ×1

ipad ×1

nstextcontainer ×1

objective-c ×1

textkit ×1

uitextview ×1