2
从iOS6升级到iOS7时,我认为我发现了一个CATiledLayer的错误,我希望在提交给Apple之前由社区验证它。CATiledLayer,iOS7瓷砖未更新
问题是,如果您的UIScrollView中包含许多CATiledLayer,则最终会停止更新。
我有一个样本项目展示这里的问题:
https://github.com/sbudhram/CATiledLayerBug
请下载并运行iOS6的VS iOS7的iPad上运行。
该项目在UIScrollView中生成900个CATiledLayer,分辨率为3级。随着用户放大,图块更新为更精细的分辨率。该代码适用于iOS6,但最终在iOS7上停止更新。
我GOOGLE了四周,看看是否有人的有这种类似的问题,并发现这一点:
这是不同的,虽然,因为我相信这可以在没有记忆发生警告。
这里是UIViewController中相关的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_scrollView.backgroundColor = [UIColor yellowColor];
_scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
_scrollView.minimumZoomScale = 1;
_scrollView.maximumZoomScale = 4.1;
_scrollView.zoomScale = 2;
_scrollView.showsHorizontalScrollIndicator = YES;
_scrollView.showsVerticalScrollIndicator = YES;
_scrollView.delegate = self;
[self.view addSubview:_scrollView];
self.contentView = [[UIView alloc] initWithFrame:_scrollView.bounds];
_contentView.backgroundColor = [UIColor lightGrayColor];
[_scrollView addSubview:_contentView];
CGFloat tileSize = 20.0f;
CGFloat tileSpacing = 4.0f;
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
CATiledLayer *tLayer = [CATiledLayer layer];
tLayer.bounds = CGRectMake(0, 0, tileSize, tileSize);
tLayer.position = CGPointMake(tileSize/2 + i*(tileSpacing+tileSize), tileSize/2 + j*(tileSpacing+tileSize));
tLayer.delegate = self;
tLayer.contentsGravity = kCAGravityResize;
tLayer.contentsScale = [[UIScreen mainScreen] scale];
tLayer.masksToBounds = NO;
tLayer.opacity = 1.0f;
tLayer.backgroundColor = [UIColor colorWithRed:.2 green:.2 blue:.8 alpha:.5].CGColor;
tLayer.levelsOfDetail = 3;
tLayer.levelsOfDetailBias = 3;
tLayer.tileSize = CGSizeMake(1024., 1024.);
[_contentView.layer addSublayer:tLayer];
}
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(@"Zoom: %f", scrollView.zoomScale);
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _contentView;
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
UIImage *drawImage = nil;
if (_scrollView.zoomScale < 2) {
drawImage = [UIImage imageNamed:@"low.png"];
NSLog(@"Drawing - Low");
}
else if (_scrollView.zoomScale < 4) {
drawImage = [UIImage imageNamed:@"med.png"];
NSLog(@"Drawing - Med");
}
else {
drawImage = [UIImage imageNamed:@"high.png"];
NSLog(@"Drawing - Hi");
}
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -layer.bounds.size.height);
CGContextDrawImage(ctx, layer.bounds, [drawImage CGImage]);
}
下面是对iOS7会发生什么的快照(一切都充满在iOS6的):
我已经提交了一个错误报告 - 我会保持这个问题的状态更新。 –
进一步的讨论在这里:https://devforums.apple.com/message/884524 – dkmp
看起来像苹果还没有修复它,即使在最新的测试版。有最少的代码更改有什么好的选择? – gavi