Tag: calayer

如何检测由CATransaction触发的animation的完成?

我有一个CALayer,我只是创build并添加到我的视图控制器的主视图在控制器的initWithNibName的子视图:然后,我执行以下animation: [CATransaction begin]; [CATransaction setAnimationDuration:2]; [logoLayer setOpacity:0]; [CATransaction commit]; 如何知道这个animation何时完成? performSelector:延迟2秒。 方法似乎并不是“正确的方式”去做。

当背景颜色清晰时,阴影不显示

我在我的xib中创build了一个uiview,其背景色为清晰的颜色。 当我在视图的图层上应用阴影时,阴影不会出现。 但是,当我设置清晰的颜色以外的背景颜色,阴影显示。 请帮忙。 这是我的代码 self.cView.layer.shadowColor=[UIColor whiteColor].CGColor; self.cView.layer.shadowOffset=CGSizeZero; self.cView.layer.shadowRadius=30.0; self.cView.layer.shadowOpacity=1.0; self.cView.layer.cornerRadius=10.0;

我可以得到CATransform3DIdentity的基本解释吗?

我慢慢地对核心animation越来越认真,并且会非常欣赏由简短的词语(打字?)组成的解释,慢慢地解释CATransform3DIdentity,以及为什么下面的代码做它做的事情(在“3D”空间中翻转层) kFaceUpTransform = kFaceDownTransform = CATransform3DIdentity; // Construct a 180-degree rotation matrix: kFaceDownTransform.m11 = kFaceDownTransform.m33 = -1; 在第二个想法,快速打字,并使用多音节的话给你的心中的内容,但请温柔。 PS。 我得到的印象是,如果我要更进一步地使用animation,我应该更加适应线性代数…这是正确的吗?

如何在iOS上的CALayer中显示彩色图像?

我需要在CALayer中显示彩色图像。 它适用于UIImageView: imageView.image = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) 但CALayer以原始的颜色显示图像,而不是色彩的颜色。 let tintedImage = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) layer.contents = tintedImage.CGImage 有没有办法在CALayer中显示有色图像? 演示: https://github.com/exchangegroup/calayer-with-tint-colored-image

如何使用线路path来绘制CALayer,如模拟橡皮擦效果?

我想通过触摸事件来模拟橡皮擦效果,以显示顶部背后的图像,例如灰色; 类似的东西: 我已经find了很长时间的解决scheme,但我做不到。 以下是我的自定义视图代码:CustomView.m: -(id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setup]; } return self; } -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } -(void)setup { [self setMultipleTouchEnabled:NO]; [self setBackgroundColor:[UIColor darkGrayColor]]; self.drawingPath = [UIBezierPath bezierPath]; [self.drawingPath moveToPoint:CGPointZero]; [self.drawingPath setLineWidth:5.0]; self.image = [UIImage imageNamed:@"transformers.jpg"]; self.shapeLayer = […]

CALayer.contents在AVMutableComposition中不能正确渲染

我有一个非常简单的方法,用一个静态背景图像来生成一个video,该静态背景图像覆盖了整个video的组成部分,以及一个位于video底部的较小的,部分透明的图像(水印风格)。 背景图像正确呈现,看起来与图像查看器中的完全相同。 然而,应该在video底部呈现的图像是倾斜/扭曲的。 源代码可以在这里下载到GitHub上。 我的代码的预期输出(所需video输出的样机): 我的代码的实际输出(从iOS模拟器部分截图): 正如您所看到的,页脚图像呈45度倾斜并呈波浪状。 以下是我目前用来生成video的代码。 我已经尝试过所有可能的contentGravity组合,但没有运气。 我见过的其他每个例子都只是将CGImageRef设置为图层的contents然后将bounds , position和anchorPoint为适当的值。 我还没有看到其他任何设置其他属性的例子。 我已经阅读了几乎所有的AVFoundation的文件,看看是否有设置,我错过了,但我还没有遇到任何明显的事情。 任何build议将不胜感激。 谢谢! 接口声明: CGSize _renderingSize; float _displayDuration; AVMutableComposition *mutableComposition; AVMutableVideoComposition *videoComposition; AVMutableCompositionTrack *mutableCompositionVideoTrack; AVAssetExportSession *exporter; ViewDidLoad设置: _renderingSize = CGSizeMake(640, 360); _displayDuration = 2.0; 渲染代码块: mutableComposition = [AVMutableComposition composition]; mutableCompositionVideoTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; videoComposition = [AVMutableVideoComposition videoComposition]; videoComposition.renderSize = _renderingSize; videoComposition.frameDuration […]

如何将CAGradientLayer作为另一个CALayer的掩码?

我有一个观点,有CALayer。 当我创build一个CAGradientLayer并将其作为该视图的CALayer的掩码时,没有任何反应。 为什么? 在-initWithFrame:视图中我这样做: CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = self.bounds; gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil]; //[self.layer insertSublayer:gradient atIndex:0]; self.layer.mask = gradient; 如果我更换 self.layer.mask = gradient; 同 [self.layer insertSublayer:gradient atIndex:0]; 然后我看到渐变。 从黑色到白色。 有什么窍门?

如何通过另一个视图的内容来掩盖视图的图层?

我有一个UIImageView和一个UILabel,并希望UILabel的内容来掩盖UIImageView。 目标是文本可以看到图像的内容,但其他的一切都是透明的。 有没有简单的方法来掩盖另一个视图的内容的视图?

触摸CALayer时触发一个动作?

所以我一直在寻找,我还没有find我要找的东西。 我有一个观点,然后是这个观点的子视图。 在第二个视图中,我根据我给出的坐标创buildCALayers。 我希望能够触摸任何CALayers,并触发一些东西。 我发现不同的代码看起来像他们可以帮助,但我还没有能够实现它们。 例如: -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches count] == 1) { for (UITouch *touch in touches) { CGPoint point = [touch locationInView:[touch view]]; point = [[touch view] convertPoint:point toView:nil]; CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point]; layer = layer.modelLayer; layer.opacity = 0.5; } } } 也是这个…. – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent […]

在MKPolyLineView中绘制CAGradient

我只是与我的MKPolyLineView有问题。 我只是尝试为折线创build颜色渐变,但使用CAGradient则可以实现。 我的子类MKPolylineView和重绘 – (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context UIColor *darker = [UIColor blackColor]; CGFloat baseWidth = self.lineWidth / zoomScale; // draw the dark colour thicker CGContextAddPath(context, self.path); CGContextSetStrokeColorWithColor(context, darker.CGColor); CGContextSetLineWidth(context, baseWidth * 1.5); CGContextSetLineCap(context, self.lineCap); CGContextStrokePath(context); // now draw the stroke color with the regular width CGContextAddPath(context, self.path); CGContextSetStrokeColorWithColor(context, self.strokeColor.CGColor); CGContextSetLineWidth(context, baseWidth); CGContextSetLineCap(context, self.lineCap); CGContextStrokePath(context); [super […]