如何在UIScrollView上更新UIScrollView的ContentView的子视图分辨率?

时间:2014-05-09 11:24:14

标签: ios objective-c uiscrollview

我有UIScrollView。我的自定义绘图也有UIView名为drawingView。我将drawingView添加到UIScrollview。此图纸视图返回CATiledLayer,因此在UIScrollView缩放时,我不应该模糊绘图。

我在drawingView上也有一些subviews,如UITextView,但他们的决议不会被CATiledLayer更新,这就是它显示模糊的原因。我该怎么做才能更新drawingView的子视图(UITextView)分辨率?

以下是演示代码。我想,当我缩放UIScrollView时,广场内的文字不应该模糊。

在DrawingView.m

@implementation DrawingView

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
        tiledLayer.levelsOfDetail = 4;
        tiledLayer.levelsOfDetailBias = 4;
    }
    return self;
}

+ layerClass
{
    return [CATiledLayer class];
}

- (void)drawRect:(CGRect)rect
{
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 50, 50)];
    [[UIColor orangeColor] setFill];
    [circlePath fill];
}

@end

在ViewController.m中

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet DrawingView *drawingView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.scrollView.maximumZoomScale = 4.0f;

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 40, 40)];
    textView.backgroundColor = [UIColor clearColor];
    textView.text = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.";
    textView.font = [UIFont fontWithName:@"Helvetica" size:4];
    [self.drawingView addSubview:textView];
}

#pragma mark - Scroll View Delegates

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

1 个答案:

答案 0 :(得分:0)

您正在拉伸drawingView,您已在其上添加了文本字段。因此,如果绘图视图将缩放,则其子项自动缩放为文本字段。纠正这个问题然后你的问题就解决了。