如何在UIScrollView上调整大小和重绘UITextView?

时间:2013-12-21 10:35:52

标签: ios objective-c uiscrollview

我有一个UIView层次结构,如UIScrollView - > DrawingView(UIView) - > UITextView。当我缩放UIScrollView时,它还会缩放UITextView,从而导致模糊文字和大字体。我需要UITextView相同的调整大小框架,但它不应该模糊和正确的字体。

在图片中显示我确切需要的内容。

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

enter image description here

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

enter image description here

当我缩放/或缩放缩放级别时,这是我想要UITextView的样子。

enter image description here

这是我的代码,尝试了一次'TRY'代码,但没有一个。

- (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));
}

1 个答案:

答案 0 :(得分:0)

通过UITextView缩放进行交易,您可以执行以下操作:

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