ios - CATiledLayer,iOS7 磁贴未更新
<p><p>在从 iOS6 升级到 iOS7 的过程中,我想我发现了 CATiledLayer 的一个错误,我希望在提交给 Apple 之前让社区对其进行验证。</p>
<p>问题在于,如果您的 UIScrollView 中包含许多 CATiledLayers,则图 block 最终将停止更新。</p>
<p>我有一个示例项目在这里展示了这个问题:</p>
<p> <a href="https://github.com/sbudhram/CATiledLayerBug" rel="noreferrer noopener nofollow">https://github.com/sbudhram/CATiledLayerBug</a> </p>
<p>请在运行 iOS6 和 iOS7 的 iPad 上下载并运行。</p>
<p>该项目在一个 UIScrollView 中生成 900 个 CATiledLayers,分辨率为 3 级。随着用户放大,图 block 会更新为更精细的分辨率。该代码适用于 iOS6,但磁贴最终在 iOS7 上停止更新。</p>
<p>我用谷歌搜索看看是否有人遇到过类似的问题,发现了这个:</p>
<blockquote>
<p><a href="http://www.cocoanetics.com/2013/09/welcome-to-ios-7-issues/" rel="noreferrer noopener nofollow">http://www.cocoanetics.com/2013/09/welcome-to-ios-7-issues/</a></p>
</blockquote>
<p>但这是不同的,因为我相信这可以在没有内存警告的情况下发生。</p>
<p>这是 UIViewController 中的相关代码:</p>
<pre><code>- (void)viewDidLoad
{
;
// Do any additional setup after loading the view, typically from a nib.
self.scrollView = [ initWithFrame:self.view.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_scrollView.backgroundColor = ;
_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.contentView = [ initWithFrame:_scrollView.bounds];
_contentView.backgroundColor = ;
;
CGFloat tileSize = 20.0f;
CGFloat tileSpacing = 4.0f;
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; j++) {
CATiledLayer *tLayer = ;
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 = [ scale];
tLayer.masksToBounds = NO;
tLayer.opacity = 1.0f;
tLayer.backgroundColor = .CGColor;
tLayer.levelsOfDetail = 3;
tLayer.levelsOfDetailBias = 3;
tLayer.tileSize = CGSizeMake(1024., 1024.);
;
}
}
}
- (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 = ;
NSLog(@"Drawing - Low");
}
else if (_scrollView.zoomScale < 4) {
drawImage = ;
NSLog(@"Drawing - Med");
}
else {
drawImage = ;
NSLog(@"Drawing - Hi");
}
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -layer.bounds.size.height);
CGContextDrawImage(ctx, layer.bounds, );
}
</code></pre>
<p>以下是 iOS7 上发生的情况的快照(iOS6 上的所有内容均已填写):</p>
<p> <img src="/image/tNM5D.png" alt="iOS7 Bug"/> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>正如 gavi 所说,这现在可以在 7.1 中使用。</p></p>
<p style="font-size: 20px;">关于ios - CATiledLayer,iOS7 磁贴未更新,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19268069/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19268069/
</a>
</p>
页:
[1]