Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UIScrollView缩放上调整UITextView的大小并重新绘制?_Ios_Objective C_Uiscrollview - Fatal编程技术网

Ios 如何在UIScrollView缩放上调整UITextView的大小并重新绘制?

Ios 如何在UIScrollView缩放上调整UITextView的大小并重新绘制?,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我有这样一个UIView层次结构UIScrollView->DrawingView(UIView)->UITextView。当我缩放UIScrollView时,它还会缩放UITextView,导致文本模糊和字体变大。我需要与UITextView相同的调整大小框架,但它不应该变得模糊,并且字体合适 在图像中显示我真正需要的东西 在缩放之前,我的UITextView应该如下所示: 当我缩放时,它看起来像这样: 这是一幅图像,我希望UITextView在缩放/或最大缩放级别时的样子 这是我的代码

我有这样一个
UIView
层次结构
UIScrollView
->
DrawingView(UIView)
->
UITextView
。当我缩放
UIScrollView
时,它还会缩放
UITextView
,导致文本模糊和字体变大。我需要与
UITextView
相同的调整大小框架,但它不应该变得模糊,并且字体合适

在图像中显示我真正需要的东西

在缩放之前,我的UITextView应该如下所示:

当我缩放时,它看起来像这样:

这是一幅图像,我希望
UITextView
在缩放/或最大缩放级别时的样子

这是我的代码,每个“尝试”代码都尝试了一次,但没有一个有效

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.drawingView;
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
    // TRY 1
    self.textView.bounds = CGRectMake(0, 0, self.textView.frame.size.width*scale, self.textView.frame.size.height*scale);

    // TRY 2
    scale *= [[[scrollView window] screen] scale];
    self.textView.contentScaleFactor = scale;

    // TRY 3
    CGRect frame = self.textView.frame;
    frame.size.width = frame.size.width * scale;
    frame.size.height = frame.size.height * scale;
    self.textView.frame = frame;
    self.textView.contentScaleFactor = 1.0f;

    // TRY 4
    self.textView.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale, scale);

    // TRY 5
    scaleTracker *= scale;
    [self.drawingView setTransform:CGAffineTransformIdentity];
    self.drawingView.frame = CGRectMake((int)self.drawingView.frame.origin.x,
                              (int)self.drawingView.frame.origin.y,
                              (int)(self.drawingView.frame.size.width * scaleTracker),
                              (int)(self.drawingView.frame.size.height * scaleTracker));

    NSLog(@"TextView Frame : %@",NSStringFromCGRect(self.textView.frame));
    NSLog(@"DrawingView Frame : %@",NSStringFromCGRect(self.drawingView.frame));
}

处理UITextView缩放您可以执行以下操作:

    //scale :zoomScale
    for (UIView *subView in self.txtContent.subviews) {
        subView.contentScaleFactor = scale * [UIScreen mainScreen].scale;
    }

为什么将DrawingView作为内容视图?你在那里画什么东西吗?如果是-你也需要重新绘制吗?@yurish,我需要drawingView来绘制,也需要重新绘制。我的错-我删除了我的答案-它适用于标签,但不适用于文本字段。我的想法是更改scrollviewDidScroll上的文本字体大小。将新文本字体基于scrollview
zoomScale
属性。有时,即使放大或缩小,此
zoomScale
属性仍返回1,需要正确处理。