Tag: calayer

animation之后,我的CALayer变换保持不变,但视angular消失

我有下面的代码,在Y轴上旋转CALayer -45degrees: #define D2R(x) (x * (M_PI/180.0)) – (void) swipe:(UISwipeGestureRecognizer *)recognizer { CATransform3D transform = CATransform3DMakeRotation(D2R(-45), 0, 1.0, 0); transform.m34 = -1.0 / 850; CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath: @"transform"]; transformAnimation.fillMode = kCAFillModeForwards; transformAnimation.removedOnCompletion = NO; transformAnimation.toValue = [NSValue valueWithCATransform3D:transform]; transformAnimation.duration = 0.5; [self.layer addAnimation:transformAnimation forKey:@"transform"]; } animation的作品,除了没有视angular结束 – 忽略了我的m34设置,如果我正确地理解的东西。 中途: 最后: 我究竟做错了什么?

如何创build像月球一样在地球周围旋转的CAAnimation效果,并在IOS中同时自行旋转?

我知道在IOS中创造使月球在地球上盘旋的效果很简单。 假设月亮是一个CALayer对象,只要把这个对象的锚点改为地球,那么它就会在地球上绕行。 但是如何创造同时旋转的月球呢? 因为月球只能有一个锚点,似乎我不能让这个CALayer对象自己旋转了。 你们有什么感想? 谢谢。

在Swift中animation自定义UIView属性

所有! 我创build了一个使用CoreGraphics的循环进度视图,看起来和更新像这样: 50% 75% 这个类是一个UIView类,它有一个名为“progress”的variables,它决定了多less圆被填充。 它运作良好,但我想能够animation变化的进度variables,使酒吧animation顺利。 我已经从无数的例子中看到,我需要有一个CALayer类和我所做的View类,但是它根本没有animation。 两个问题: 我可以保留在Core Graphics中绘制的graphics,还是需要以某种方式在CALayer中重绘它? 我目前(尝试)的解决scheme崩溃在: anim.fromValue = pres.progress底部。 这是怎么回事? class CircleProgressView: UIView { @IBInspectable var backFillColor: UIColor = UIColor.blueColor() @IBInspectable var fillColor: UIColor = UIColor.greenColor() @IBInspectable var strokeColor: UIColor = UIColor.greenColor() dynamic var progress: CGFloat = 0.00 { didSet { self.layer.setValue(progress, forKey: "progress") } } var distToDestination: CGFloat = […]

drawRect:/ renderInContext:问题

似乎有一个问题试图将我的观点绘制到上下文中。 我的基本设置是,我有一个视图控制器,拥有一个UIPageViewController ,其中我加载控制器的视图,可以由用户的手指绘制。 基本上我有一本书可以画出来。 当书中的页面被打开时,我通过调用来保存图像 – (UIImage *)wholeImage { // Render the layer into an image and return UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *wholePageImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return wholePageImage; } 这个返回值然后被保存到一个文件。 但是,当我调用这个保存方法,然后行 [self.layer renderInContext:UIGraphicsGetCurrentContext()]; 被击中,这似乎打电话给我的drawRect:方法,这是覆盖如下, – (void)drawRect:(CGRect)rect { // Draw the current state of the image [self.currentImage drawAtPoint:CGPointMake(0.0f, 0.0f)]; CGPoint midPoint1 = [self midPointOfPoint1:previousPoint1 point2:previousPoint2]; CGPoint […]

使用CALayer设置UITableViewCell背景颜色

在iOS上,我将一个CALayer添加到UITableViewCell的图层中。 这是我第一次使用CALayer,它只是改变表格单元格的背景颜色。 我的目标是(1)学习如何使用CALayer,(2)使用Instruments来testing绘图是否比当前的实现更快,这会降低CGContextFillRect的速度。 ( 技术问答QA1708是所有这一切的催化剂。) 目前的实施(工程) – (void)drawRect:(CGRect)r { UIColor *myColor = [self someColor]; [myColor set]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextFillRect(context, r); // draw the background color // now draw everything else // […] } 尝试新的实施(不起作用) #import <QuartzCore/QuartzCore.h> @implementation MyCell { CALayer *backgroundLayer; } – (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; […]

UIView图层的子图层在每次出现视图时显示不同/随机

我有一个简单的自定义CALayer在我的UIView上创build一个叠加渐变效果。 这里是代码: class GradientLayer: CALayer { var locations: [CGFloat]? var origin: CGPoint? var radius: CGFloat? var color: CGColor? convenience init(view: UIView, locations: [CGFloat]?, origin: CGPoint?, radius: CGFloat?, color: UIColor?) { self.init() self.locations = locations self.origin = origin self.radius = radius self.color = color?.CGColor self.frame = view.bounds } override func drawInContext(ctx: CGContext) { super.drawInContext(ctx) guard let […]

连续显示多个CALayer 60秒?

我在这里有一个情况。 我正在使用AVFoundation捕捉相机框架。 现在我想要做的是对于某些帧,我需要显示一个循序渐进的方式旋转的图片。 我想要做的是,我正在采取4个CALayers组成的一个对象的前后左右图像,并使用CALayer时间属性和组animation属性,我想显示所有的图像一个接一个经过一定的毫秒间隔使连续的图像看起来像一个animation。 如何去呢? 请帮我在这里编码。

核心animation隐式animation不会为新添加的子层触发

不知道为什么这不起作用。 我不能为新添加的子层做隐式animation,除非有人甚至像触发button或从另一个方法中调用它。 即使我认为我应该这样下面这个不animation。 它只是显示图层的“之后”状态。 CAGradientLayer *newBar = [CAGradientLayer layer]; CGFloat barHeight = ((pair.amount.floatValue/self.model.maxModelValue.floatValue)*maxBarHeight); newBar.bounds=R(0,0,self.barWidth,0); newBar.anchorPoint=P(0, 1); newBar.position=P((i*barSpacing), self.insideLayer.bounds.size.height); newBar.backgroundColor=self.lowerColor.CGColor; newBar.colors=[NSArray arrayWithObjects:(id)self.upperColor.CGColor, self.lowerColor.CGColor, nil]; newBar.cornerRadius=self.cornerRadius; newBar.opacity=1.0; [self.insideLayer addSublayer:newBar]; //animation line: newBar.opacity=0.5;

如何在整个层次结构中pipe理CALayeranimation

这是如何同步CALayer和UIViewanimation上下复杂层次结构的后续问题 比方说,我有一个复合层(上),是CALayer的子类,并有任何数量的子。 顶部有2个子层。 第一个子层(A)应该总是固定的宽度 – 比如说100像素宽。 第二个子图层(B)应该是Top大小的其余部分。 A和B都应该占据Top的整个高度。 这在layoutSubviews中编码非常简单。 假设Top没有A或B的知识。还假设Top有一个控制何时应该被animation的委托(委托提供actionForLayer:forKey:并且没有其他的CALayer委托函数)。 我想制定一个策略,对于Top的每一个可能的大小,用户将总是看到A和B按照上面列出的约束进行渲染 – 即使当Top的大小被dynamic化时,即使它正在被animation各种animation参数(持续时间,function,偏移量等)。 正如Top的animation是通过其委托来驱动一些包含的视图或图层 – 似乎A和B应该有他们的animation设置其包含的图层 – 顶部。 我想把事情做得很好,所以我不希望top中的A&B的布局需要被Top以外的任何东西所理解。 所以 – 问题是将animation链接到图层树中以保持所有animation参数同步的最佳策略是什么?

使用负速度恢复CABasicAnimation?

我用下面的代码恢复我的CABasicAnimation: CFTimeInterval pausedtime = layer.timeOffset; layer.speed = 1.0; layer.timeOffset = 0.0; layer.beginTime = [layer convertTime:CACurrentMediaTime() toLayer:nil] – pausedTime; 这很简单。 在本文的最后,作者指出,负speed值animation反转。 我不明白什么beginTime应该像这样的情况下, PS我知道,我可以通过从表示层获取当前值并将其设置为值和fromValue来反转animation。 我想知道是否有速度属性可能。