如何更改iphone CATiledLayer fadeDuration? [英] How to change iphone CATiledLayer fadeDuration?

查看:92
本文介绍了如何更改iphone CATiledLayer fadeDuration?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个显示平铺地图的iphone应用程序。我目前在UIScrollView中使用CATiledLayer:

I am working on an iphone application that displays tiled maps. I am currently using a CATiledLayer in a UIScrollView :

     MyTiledDelegate *delegate=[[MyTiledDelegate alloc] initWithMapLayer:map];
     tileLayer = [CATiledLayer layer];
     tileLayer.delegate = delegate;
     [scrollView.layer addSublayer:tileLayer];
     [tileLayer setNeedsDisplay];   

我编写并设置了我自己的委托,它实现了绘图层方法,如下所示:

I wrote and set my own delegate which implements the draw layer method like so :

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
    CGRect rect =CGContextGetClipBoundingBox(ctx);
    CGFloat x = fabs(round(rect.origin.x/tileSize));
    CGFloat y = fabs(round(rect.origin.y/tileSize));

    Tile *tile = [map getTileForMapZoom:z x:x y:y];
    CGImageRef img=[tile getRealImage];
    CGContextDrawImage(
        ctx,
        CGRectMake(tile.x*tileSize,tile.y*tileSize, tileSize,tileSize) , 
        img);
    }//edited for brevity

我对CAtiledLayer的默认行为感到恼火绘制瓷砖后的fadein。此外,有时候fadein不完整(停止在90%或95%不透明度)。

I am annoyed by the default behavior of the CAtiledLayer to fadein after the tile is drawn. Also, sometimes the fadein is not complete (it stops at 90 or 95% opacity).

我如何更改或(最好)删除fadein动画?

我玩速度持续时间我的CATiledLayer实例的属性无济于事。我没有在tilesLayer上设置任何动画。 [tiledLayer removeAllAnimation] 也不会改变任何内容。

I played with the speed and duration properties of my CATiledLayer instance, to no avail. I don't set any animation on the tiledLayer. the [tiledLayer removeAllAnimation] does not change anything either.

感谢您的任何指示。

推荐答案

您应该将CATiledLayer子类化并返回0的fadeDuration以禁用淡入:

You should subclass the CATiledLayer and return fadeDuration of 0 to disable fade-in:

@interface FastCATiledLayer : CATiledLayer
@end

@implementation FastCATiledLayer
+(CFTimeInterval)fadeDuration {
  return 0.0;
}
@end

我也有淡入淡出动画的问题完成,有助于将视图的背景颜色设置为 [UIColor clearColor]

I also had the problem with fade in animation not completing, what helped was to set the background color of the view to [UIColor clearColor]

这篇关于如何更改iphone CATiledLayer fadeDuration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆