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