- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为 CALayer 的边界设置动画,但它不起作用。这是代码:
class CircleView < UIIVew
def initWithFrame(frame)
super
# determine the dimensions
radius = (bounds.size.width < bounds.size.height ? bounds.size.width : bounds.size.height) / 2
# create the circle layer
@circle = CAShapeLayer.layer
@circle.bounds = bounds
@circle.path = UIBezierPath.bezierPathWithRoundedRect(bounds, cornerRadius: radius).CGPath
@circle.fillColor = UIColor.blueColor.CGColor
# add the circle to the view
self.layer.addSublayer(@circle)
shrink
self
end
private
# Applies the shrink animation to the provided circle layer.
def shrink
# determine the bounds
old_bounds = @circle.bounds
new_bounds = CGRectMake(old_bounds.size.width / 2, old_bounds.size.height / 2, 0, 0)
# animate the shrinking
animation = CABasicAnimation.animationWithKeyPath("bounds")
animation.fromValue = NSValue.valueWithCGRect(old_bounds)
animation.toValue = NSValue.valueWithCGRect(new_bounds)
animation.duration = 3.0
@circle.addAnimation(animation, forKey:"bounds")
# set the bounds so the animation doesn't bounce back when it's complete
@circle.bounds = new_bounds
end
# Applies the shrink animation to the provided circle layer.
def disappear
# animate the shirnk
animation = CABasicAnimation.animationWithKeyPath("opacity")
animation.fromValue = NSNumber.numberWithFloat(1.0)
animation.toValue = NSNumber.numberWithFloat(0.0)
animation.duration = 3.0
@circle.addAnimation(animation, forKey:"opacity")
# set the value so the animation doesn't bound back when it's completed
@circle.opacity = 0.0
end
end
如果我从 initWithFrame
方法中调用 disappear,动画效果很好。但是,调用 shrink 什么也不做。我做错了什么?
最佳答案
那是因为您正在使用 CAShapeLayer
。 path
独立于 bounds
,因此您必须单独为其设置动画。
我可以使用粗略翻译成 Objective C 的代码版本重现您的问题。当我将 shrink
方法更改为此时,它起作用了:
-(void)shrink
{
CGRect old_bounds = self.circle.bounds;
CGRect new_bounds = CGRectMake(old_bounds.size.width / 2, old_bounds.size.height / 2, 0, 0);
// bounds
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"bounds"];
animation.fromValue = [NSValue valueWithCGRect: old_bounds];
animation.toValue = [NSValue valueWithCGRect: new_bounds];
animation.duration = 3.0;
[self.circle addAnimation: animation forKey: @"bounds"];
// path
CGPathRef old_path = self.circle.path;
CGPathRef new_path = [UIBezierPath bezierPathWithRoundedRect:new_bounds cornerRadius:0].CGPath;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath: @"path"];
pathAnimation.fromValue = (__bridge id)(old_path);
pathAnimation.toValue = (__bridge id)(new_path);
pathAnimation.duration = 3.0;
[self.circle addAnimation: pathAnimation forKey: @"path"];
//set the value so the animation doesn't bound back when it's completed
self.circle.bounds = new_bounds;
self.circle.path = new_path;
}
从技术上讲,您甚至不必为边界设置动画。如果您在 circle
层上设置了不同的 backgroundColor
,您可以进行一些试验,更容易地了解 bounds
和 path
可以或多或少地独立设置和动画(例如,在您的原始代码中,您可以看到边界实际上是动画的,但路径保持不变)。
关于ios - CALayer 不透明度动画有效但边界动画无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17869180/
我正在制作一个应用程序,我需要使用 ffmpeg 将两个视频文件叠加在另一个之上。 .我尝试了各种命令,但它所做的只是合并视频。 最佳答案 基本方法是 ffmpeg -i in1 -i in2 -fi
我将 Qt3D 与 offscreen renderer 结合使用并修改框架图以包含背景图像,例如 here . 不幸的是,使用 QPhongAlphaMaterial 为绘制在背景图像上的对象添加透
我正在开发的这个组件有视觉问题。它是带有 2 个 JTextField 和 2 个 JLabel 的 JPanel。我不能做坚实的背景。我尝试了几种不透明/背景颜色组合但没有成功。 我不允许附加图像,
我正在使用 Gnuplot 成功绘制一些时间序列数据。然而,该系列相当密集(大约 5 英寸空间中有 10,000 个样本),当我绘制多个系列时,很难看到绘制在顶部的系列下方。 有什么方法可以使线条具有
我正在尝试设置一个自定义拖动图标以在 NSTableView 中使用。一切似乎都正常,但由于我对 Quartz 缺乏经验,我遇到了问题。 - (NSImage *)dragImageForRowsWi
是否可以制作例如 20% 透明的 TMemo 或其他 vcl 组件?像 TButton 或 TEdit 吗? 在谷歌搜索解决方案时,我发现了这个: From Here ,然后我想,如果我在窗体上绘制图
我目前正在学习如何使用 Scenekit,并且遇到了透明对象的问题。我写了一个着色器来增加正面看脸时的透明度,当我选择白色背景时,一切都按预期工作...... transparency with wh
我对 openGL 中的 alpha 混合有疑问... 我尝试了一些绘制透明对象的方法...通过在绘制透明面之前禁用 GL_DEPTH_TEST 并在绘制透明面后再次重新启用 GL_DEPTH_TES
我正试图让我的背景 webView 像那样透明: webView.setBackgroundColor(0x00000000); 但它不起作用,如果我添加这一行,一切都是透明的(我看不到我的 html
我目前正在创建一个应用程序并且出现了这个问题,我想让 TabLayout 透明。当我使用 RelativeLayout TabLayout 覆盖内容时,当我使用 LinearLayout TabLay
我有一个 UINavigationItem(不是 UINavigationBar),我想使其透明或不透明。这是在我建立从导航 Controller 到我的 UIViewController 子类的关系
是否可以让您的 android Activity 以透明模式在当前正在运行的 Activity 之上运行,以便您可以通过它看到它下面的 Activity ?如果可能,您可以设置不同级别的透明度吗? 最
我正在使用 noUiSlider 范围 slider 。这是 jsfiddle: https://jsfiddle.net/oun5p1xz/ behaviourSlider = document.g
有没有办法改变控制台的不透明度使其半透明? 还有办法将控制台的背景颜色更改为自定义颜色吗? 最佳答案 快速谷歌显示 this site其中包含用于具有透明窗口的控制台应用程序的代码。 本质上,您必须获
主.xml: 这是我的 main.xml,我试图使按钮最透明,但我仍然想看到它们,但我不知道要添加什么以及在哪里添加,请用低不透明度更正我的 xml在按钮
如何将实际内容 Pane 的背景设置为不透明,我添加到其中的面板我已经设置为不透明,但即使我这样做,选项卡 Pane 的主要区域仍显示为蓝色 JTabbedPane tabbedPane = new
是否可以继承颜色但覆盖不透明度值?以下是伪 CSS 中的示例: .color-class { background-color: rgba(255, 0, 0, 0); } .lighten
我正在尝试让我的导航栏变得 100% 透明,以便 UINavigationButtonItems 只可见并且背景(通常为白色)应该显示背景图像。 我试过了 HomeNavigationControll
RGBA 非常有趣,-webkit-gradient、-moz-gradient 和呃... progid:DXImageTransform.Microsoft.gradient 也是如此...是的。
我一直在尝试使用 AppBarLayout,但找不到使它的背景透明的方法。 我的意思是: 这是我的 XML: 如您所见,我使用的是颜色 #8000
我是一名优秀的程序员,十分优秀!