簡體   English   中英

如何在UIScrollView縮放上更新UIScrollView的ContentView子視圖分辨率?

[英]How to update UIScrollView's ContentView's subviews resolution on UIScrollView zoom?

我有UIScrollView 我的自定義繪圖還具有名為drawingView的UIView 我將drawingView添加到UIScrollview 該工程圖視圖返回CATiledLayer因此在UIScrollView縮放時,我不應使工程圖模糊。

我在諸如UITextView drawingView上也有一些subviews ,但是它們的分辨率無法通過CATiledLayer進行更新,這就是為什么它顯示模糊的原因。 我應該怎么做來更新drawingView的subview( 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;
}

您正在拉伸drawingView,並在其上添加了文本字段。 因此,如果工程圖視圖將縮放,則其子視圖將自動縮放,如文本字段。 改正此問題即可解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM