- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 Core Animation 制作一个简单的动画来绘制一个简单的增长条(如进度条)。
因此,条形图从 x = 0
开始,宽度为 0
,然后逐渐增长以适应框架。
但是,当我为 bounds.size.width
设置动画时,原点被认为是层的中心并且它在两个 x 方向上向外增长,而我希望它是层的最左边的点bar 始终为 0
并且最右边随动画变化——同样,就像一个进度条。
我是否必须为一个额外的属性设置动画,或者除了 bounds.size.width
我应该使用其他东西来实现这个?
作为引用,这是我现在拥有的:
CABasicAnimation * animation;
animation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
animation.fromValue = [NSNumber numberWithInt:0];
animation.toValue = [NSNumber numberWithInt:(self.frame.size.width / 2)];
[animation setValue:@"primary_on" forKey:@"animation_key"];
animation.duration = duration;
[primaryMask addAnimation:animation forKey:@"primary_on"];
(primaryMask
是一个CALayer
)
在这种情况下会发生同样的事情:
animation = [CABasicAnimation animationWithKeyPath:@"bounds"];
CGRect oldBounds = CGRectMake(0, 0, 0, self.frame.size.height);
CGRect newBounds = CGRectMake(0, 0, self.frame.size.width / 2, self.frame.size.height);
animation.fromValue = [NSValue valueWithCGRect:oldBounds];
animation.toValue = [NSValue valueWithCGRect:newBounds];
最佳答案
你需要设置
layer.anchorPoint = CGPointZero;
默认情况下,此属性为 {0.5, 0.5},这是图层的中心。
关于objective-c - CABasicAnimation 使用静态左侧原点增加宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7624292/
这很奇怪: 我有一个包含旋转的 CALayer 的 View 。使用 transform.rotation.z 键路径上的 CABasicAnimation 来旋转图层。工作正常。 然后,包括该层的
如果有人想尝试此代码,您只需 c+p 文件即可运行 实际上我在下面的代码中有 2 个问题。 1- 我有一个 Timer 和一个 CABasicAnimation,它们都在触发 longPressGes
我有一个 CALayer在 AVMutableComposition淡入,应该在屏幕上停留一段时间然后消失。问题是,它应该在没有动画的情况下消失,但是 CABasicAnimation最短持续时间为
我有一个在多个图层上执行的 CABasicAnimation,它所做的就是将 UIImageView 向上移动 10 像素,然后向下移动。我希望这种情况能够无限持续下去。当动画完成后,我不知道如何让它
很多人都在谈论在使用 CABasicAnimation 对象后保留它。 所以通过设置 removedOnCompletion = NO 当动画完成时,动画对象保持附加到图层。在不创建新的 CABasi
我有一个基本的 iPhone 旋转动画。有什么方法可以“暂停”动画以便保持 View 的位置吗?我想这样做的一种方法是使动画“完成”而不是调用“删除”,我该怎么做? CABasicAnimation*
我想在动画 (CABasicAnimation) 完成之前将其删除。 例如: 在我的代码中,我启动了针从旋转值 0 到目标值 5 的动画。当针达到旋转值 3 时如何停止动画? CALayer* lay
我希望图层的行为如下: 相反,它的行为如下: 卡片翻转动画是由在 CAAnimationGroup 中应用的两个 CABasicAnimation 创建的。发生不正确的旋转效果是因为 CALayer
通过下面的代码,我可以从左到右为 CALayer 制作动画 let imageLayer = CALayer() imageLayer.frame = CGRect(x: 0, y: 500, wid
所以基本上我正在尝试创建dialogView。该对话框 View 将包含一个加载微调器和一些将根据状态进行更新的文本。我按照两个指南使用 CAShapeLayer 绘制一个圆,然后为它周围的一条线设置
无论我是否使用 CATransation,我似乎都无法控制简单核心动画的持续时间。 事务完成代码在我的持续时间设置后触发,就像我期望的那样,但旋转动画总是需要大约 0.5 秒,无论它设置为什么持续时间
我正在尝试使用 CABasicAnimation 创建一个简单的动画,它将始终保持恒定的速度,即使动画必须移动的距离永远不会相同。到目前为止,这是我的代码,它正在滚动一个大小总是不同的标签,但还不能保
我有描边动画: - (void)drawBezierAnimate:(BOOL)animate { UIColor* color = [UIColor colorWithRed: 1 green: 0
以下代码指向内存分配泄漏(使用分析器中的分配工具)-有人可以指出为什么 -我正在使用 CABAsicAnimation 来旋转 UIImageView -(void)SetGaugeToValueIn
我有一个圆圈,我将其设置为向外生长并变大的动画。不幸的是,尽管我设置了 anchorPoint 它并没有从中心向外动画,它似乎锁定了左上角的位置。这是怎么回事? 请看这张描述圆圈偏离中心的图片 代码
我有 3 个颜色条的 3 个 CABasicAnimation,它们相互跟随。第三个完成后,3 个小节将停留在其最终位置。到这里为止,一切都很好,这是代码: - (void)animationDidS
我正在旋转一个 UIBarButtonItem。动画效果很好。但是,当我从服务器接收到数据时,我想顺利地停止动画。 我尝试使用 presentationLayer 捕获当前值,但我得到的只是 0。 -
我有以下代码,应该提供 View “摇晃”的效果,然后通过向上滑出屏幕来消除它。 有时完美呈现,但大多数时候摇动动画不会显示, View 只是向上滑动。我无法弄清楚问题可能是什么: CABasicAn
我正在实现彩色动画。 我想把黑色变成渐变色。 我搜索了一些方法,可以使用CAGradientLayer定义渐变颜色,CABasicAnimation可以实现颜色变化动画。 但是我在下面的代码中实现,一
我有一个带有 .fromValue 和 .toValue 的 CABasicAnimation,它们在包含 202 个图像的 PNG 图像中移动,并按顺序显示它们一个 我还使用CALayer来保存im
我是一名优秀的程序员,十分优秀!