Tag: calayer

子视图出现在superviews下面layer.border?

我有一个UIView ,我用下面的方式定义它的边界: self.layer.borderColor = [UIColor blackColor].CGColor; self.layer.borderWidth = 3; 我附加一个子视图到这个UIView ,当我把子视图移到边界上时,它就在它的下面。 这是预期的行为? 无论如何,使子视图上呢?

CALayer – 暗影导致性能下降?

所以我在我的导航控制器上做了一些自定义的animation,以及它推动和popupviewControllers的方式。 一切顺利。 只要我添加下面的代码(在UINavigationController的子类),我面临巨大的性能打击。 添加一个阴影后,所有的animation变得非常滞后。 这是预期还是我在代码中做错了什么? // This code gets called once during NavigationController initialization. [self.view setClipsToBounds:NO]; [self.view.layer setCornerRadius:5]; [self.view.layer setShadowOffset:CGSizeMake(0, 20)]; [self.view.layer setShadowColor:[[UIColor yellowColor] CGColor]]; [self.view.layer setShadowRadius:20.0]; [self.view.layer setShadowOpacity:1]; 编辑: 改变我的影子半径为1,它仍然很慢

如何禁用CALayer隐式animation?

这让我疯狂! 我正在绘制应用程序。 假设我正在使用一个名为sheet的UIView 。 我添加了一些子层到这个视图( [sheet.layer addSublayer:…] ),然后我想绘制它们。 为此,我创build了一个CGImageRef并将其放入图层的contents 。 但它是animation,我不想要的。 我尝试了一切: removeAnimationForKey: removeAllAnimations 设置动作字典 使用操作层delegate [CATransaction setDisableAnimations:YES] 这似乎是正确的。 我不明白为什么这层还是animation的; 难道我做错了什么? 有没有秘密的方法?

如何根据框架在video中设置CATextLayer?

我已经尝试了许多想法,但没有成功,我的问题是,我有一个video,我提供了一个function,在video上写文本,并拖放到video上的文本现在我魔棒设置CATextlayervideo与propper由用户设置的位置,但不显示在正确的位置,所以请帮助我。 这是我为此使用的代码。 CATextLayer *titleLayer = [CATextLayer layer];//<========code to set the text titleLayer.string = self.strText; titleLayer.font = (__bridge CFTypeRef)(self.fonts);; titleLayer.fontSize = titleLayer.fontSize; titleLayer.position = CGPointMake (titleLayer.fontSize,titleLayer.fontSize); //?? titleLayer.shadowOpacity = 0.5; titleLayer.alignmentMode = kCAAlignmentCenter; titleLayer.bounds = CGRectMake(self.rectText.origin.x,self.rectText.origin.y-52, 480, 480); //You may need to adjust this for proper display [titleLayer setBackgroundColor:[UIColor redColor].CGColor]; [parentLayer addSublayer:titleLayer]; //ONLY IF WE ADDED […]

Swift:沿着贝塞尔path渐变(使用CALayers)

我有一个相对直观的实现与CALayer对象设置的进度视图。 进度视图本身是UIView的子视图。 以下是设置进度环的代码: self.progressRingLayer = CAShapeLayer() let innerRect = CGRectInset(bounds, CGFloat(self.lineWidth) / 2, CGFloat(self.lineWidth) / 2) let innerPath = UIBezierPath(ovalInRect: innerRect) self.progressRingLayer.path = innerPath.CGPath self.progressRingLayer.fillColor = UIColor.clearColor().CGColor self.progressRingLayer.strokeColor = kProgressColor.CGColor self.progressRingLayer.anchorPoint = CGPointMake(0.5, 0.5) self.progressRingLayer.transform = CATransform3DRotate(self.progressRingLayer.transform, (CGFloat(M_PI))*1, 0, 0, 1) self.progressRingLayer.lineCap = kCALineCapRound self.progressRingLayer.lineWidth = CGFloat(self.lineWidth) self.layer.addSublayer(self.progressRingLayer) 我现在要做的就是向progressRingLayer添加一个渐变(跟随(或弯曲))path。 我已经成功地为填充添加线性渐变,但不是仅添加到path。 这里是我想要什么效果的一个例子: 到目前为止,我发现的所有东西都需要一些CoreGraphics和CGContext的附加步骤,这些步骤不太适合我的实现。 任何帮助将是伟大的,谢谢!

在已过滤的图像之间滑动

我试图让用户在静态图像上的filter之间滑动。 这个想法是,当filter在它上面滚动时,图像保持原位。 Snapchat最近发布了一个实现这个function的版本。 这个video显示了我正在努力完成1:05。 到目前为止,我已经尝试将三个UIImageView放入原始图像的左侧和右侧的scrollview中,并使用scrollView的contentOffset.x调整其框架origin.x和size.width。 我在另一篇文章中发现了这个想法。 将左右内容模式更改为UIViewContentModeLeft和UIViewContentModeRight没有帮助。 接下来,我尝试将所有三个UIImageView堆叠在一起。 我制作了两个CALayer蒙版,并将它们插入到堆栈左侧和右侧的scrollView中,这样当您滚动蒙版时将会展示已过滤的图像。 这不适合我。 任何帮助将不胜感激。

iOS的animation/变形形状从圆形到方形

我试图把一个圆圈变成一个正方形,反之亦然,我快到了。 然而它并不像预期的那样animation。 我希望广场的所有angular落都能同时进行animation/变形,但我得到的是以下内容: 我使用CAShapeLayer和CABasicAnimation为了animation形状属性。 以下是我如何创build圆path: – (UIBezierPath *)circlePathWithCenter:(CGPoint)center radius:(CGFloat)radius { UIBezierPath *circlePath = [UIBezierPath bezierPath]; [circlePath addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:3*M_PI/2 endAngle:M_PI clockwise:YES]; [circlePath closePath]; return circlePath; } 这是方形path: – (UIBezierPath *)squarePathWithCenter:(CGPoint)center size:(CGFloat)size { CGFloat startX = center.x-size/2; CGFloat […]

CoreAnimation – 不透明度淡入和淡出animation不工作

我正在试图创build一个相当简单的CoreAnimation在AVComposition使用。 我的目标是创build一个CALayer ,通过各个子层,淡入淡出标题,然后淡入淡出图像。 幻灯片,基本上。 这是使用AVAssetWriter导出到.mov。 在WWDC 2011 AVEditDemo的帮助下,我已经能够得到一个标题和图像出现。 问题是他们都在同一时间在屏幕上! 我创build了不透明度为0.0的每个图层。 然后我使用下面的代码添加了一个CABasicAnimation使它们从0.0到1.0淡出: CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0]; fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0]; fadeInAnimation.additive = NO; fadeInAnimation.removedOnCompletion = YES; fadeInAnimation.beginTime = 1.0; fadeInAnimation.duration = 1.0; fadeInAnimation.fillMode = kCAFillModeForwards; [titleLayer addAnimation:fadeInAnimation forKey:nil]; 问题似乎是“beginTime”属性。 “1.0”意味着延迟,所以从animation开始1秒后开始。 但是,它直接出现在屏幕上。 淡出animation 这个代码的反面,淡出,只是简单地将fromValue更改为1.0,toValue更改为0.0。 它有一个开始时间4.0和完美的作品。 我正在使用以下来创buildanimatedTitleLayer : CATextLayer *titleLayer = [CATextLayer layer]; […]

iOS中的自定义图像蒙版

我有掩盖图像的问题。 我做游戏“拼图”,必须制作自定义图像。 我发现并尝试了2种自定义裁剪方式: 使用CALayer.mask属性。 使用UIImage.mask属性。 在第一个选项我创build我的自定义path,然后将其分配给CAShapeLayer.path属性,然后将CAShapeLayer分配给CALayer.mask属性。 最后,我有自定义裁剪图像。 在第二个选项中,我首先使用CGImageMaskCreate()方法(我使用以前创build的黑色面具图像拼图),然后CGContextClipToMask() 。 在任何一个选项我都有性能问题(主要是当我裁剪图像成16个谜题,并在屏幕上拖动)。 有没有其他的方法来自定义的方式来裁剪图像。 (我不知道如何解决性能问题)。 提前致谢。

如何用CAShapeLayer和UIBezierPath绘制一个平滑的圆?

我试图通过使用CAShapeLayer并在其上设置循环path来绘制一个描边圈。 但是,这种方法在渲染到屏幕上的准确性比使用borderRadius时要less得多,或者直接在CGContextRef中绘制path。 以下是所有三种方法的结果: 请注意,第三个渲染效果不好,特别是在顶部和底部的中风。 我已经将contentsScale属性设置为[UIScreen mainScreen].scale 。 这是我的这三个圈子的绘图代码。 缺less什么使CAShapeLayer平滑绘制? @interface BCViewController () @end @interface BCDrawingView : UIView @end @implementation BCDrawingView – (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.backgroundColor = nil; self.opaque = YES; } return self; } – (void)drawRect:(CGRect)rect { [super drawRect:rect]; [[UIColor whiteColor] setFill]; CGContextFillRect(UIGraphicsGetCurrentContext(), rect); CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), NULL); [[UIColor redColor] setStroke]; CGContextSetLineWidth(UIGraphicsGetCurrentContext(), […]