我在 drawRect()
var rectanglePath = UIBezierPath()
override func drawRect(rect: CGRect) {
rectanglePath = UIBezierPath(rect: self.bounds)
rectanglePath.fillWithBlendMode(kCGBlendModeMultiply, alpha: 0.7)
layer.shouldRasterize = true
}
当 prepareForEditing 函数被调用时,我想为 rectanglePath 设置动画。我试过了
func prepareForEditing(editing:Bool){
UIView.animateWithDuration(0.5,
animations: {
self.rectanglePath = makeNewShape()
}
)
}
没有任何反应。你能告诉我我的代码有什么问题吗?
最佳答案
要为 CGPath 设置动画,您不能使用 UIView.animation 方法。 我创建了自定义 UIView 子类来向您展示如何为 CGPaths 形状设置动画,请引用评论并根据您的要求进行修改:
class MyView: UIView {
let shapeLayer = CAShapeLayer()
let maskLayer = CAShapeLayer()
var rectanglePath = UIBezierPath()
override func didMoveToSuperview() {
super.didMoveToSuperview()
backgroundColor = UIColor.clear
// initial shape of the view
rectanglePath = UIBezierPath(rect: bounds)
// Create initial shape of the view
shapeLayer.path = rectanglePath.cgPath
shapeLayer.strokeColor = UIColor.black.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
layer.addSublayer(shapeLayer)
//mask layer
maskLayer.path = shapeLayer.path
maskLayer.position = shapeLayer.position
layer.mask = maskLayer
}
func prepareForEditing(editing:Bool){
let animation = CABasicAnimation(keyPath: "path")
animation.duration = 2
// Your new shape here
animation.toValue = UIBezierPath(ovalIn: bounds).cgPath
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
// The next two line preserves the final shape of animation,
// if you remove it the shape will return to the original shape after the animation finished
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
shapeLayer.add(animation, forKey: nil)
maskLayer.add(animation, forKey: nil)
}
}
关于animation - 为在 drawRect() Swift 中绘制的贝塞尔曲线路径设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26847408/
Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u
动画/*INITIALIZEANANIMATION 初始化一个动画*-----------------------*/lv_anim_ta;lv_anim_init(&a);/*MANDATORYSETTINGS 必选设置*------------------*//*Setthe"animator"function 设置“动画”功能*/lv_anim_set_exec_cb(&a,(lv_anim_exec_xcb_t)lv_obj_set_x);/*Setthe"animator"function*/lv_anim_set_var(&a,obj);/*Lengthoftheanim
有人知道如何使用Carrierwave+MiniMagick将动画GIF压缩到第一帧吗? 最佳答案 我认为MiniMagick有一些变化,因为我只花了三个小时试图找出为什么Andrey的代码对我不起作用。我收到以下错误:ActiveRecord::RecordInvalid(Validationfailed:ImageFailedtomanipulatewithMiniMagick,maybeitisnotanimage?OriginalError:Command("mogrify-scene/var/folders/0o/0oqN
我正在寻找一种简单的方法来绘制大约10个点和矩形,以便能够查看我的算法哪里出了问题。我查看了gnuplot,但似乎绘制矩形特别糟糕。 最佳答案 SVG(MDNTutorial)是一种非常简单的基于文本(XML)的格式,您可以使用Ruby轻松生成它,而无需任何SVG库,并可以在任何现代Web浏览器中查看。这是一个示例:通过字符串插值的SVG点points=(0..5).map{[rand(100)-50,rand(100)-50]}puts#{points.map{|x,y|""}.join("\n")}ENDSVG输出:http:/
我正在寻找进行对数回归(对数方程的曲线拟合)的Rubygem或库。我试过statsample(http://ruby-statsample.rubyforge.org/),但它似乎没有我要找的东西。有人有什么建议吗? 最佳答案 尝试使用“statsample”gem。您可以使用类似的方法执行指数、对数、幂、正弦或任何其他变换。我希望这有帮助。require'statsample'#IndependentVariablex_data=[Math.exp(1),Math.exp(2),Math.exp(3),Math.exp(4),Ma
我正在尝试编写Ruby代码来检查我发现的特定消息上的椭圆曲线数字签名算法(ECDSA)签名here.问题是我不知道如何将公钥的八位字节字符串转换为OpenSSL::PKey::EC::Point目的。如果我用C写这个,我会把八位字节字符串传递给OpenSSL的o2i_ECPublicKey,它做的事情接近我想要的,实际上被referenceimplementation使用.但是,我搜索了sourcecodeofRuby(MRI)而且它不包含对o2i_ECPublicKey的调用,所以我不知道如何在不编写C扩展的情况下使用Ruby中的该函数。这是十六进制的八位字节字符串。它只是一个0x0
我有一个字符串"1/16"我想将它转换为float并乘以45。但是,我没有得到想要的结果。我在script/console中尝试>>"1/16".to_f=>1.0>>"1/16".to_f*45=>45.0如何获得2.81的预期结果大图:我有一个这样的下拉列表:每当用户选择oz值时,我想将它乘以45我也是这样的:first,*rest=params[:volume].to_s.split(//)ifrest.first=="oz"@indprodprice=@prods.orig_price.to_i*first.to_f*28.3495else@indprodprice=@prod
我正在尝试为每个ajax请求显示一个加载指示器,我在Rails3应用程序中工作。HTML:"loading-indicator",:style=>"display:none")%>CSS:#loading-indicator{position:absolute;left:10px;top:10px;}loading.js:我放在assest/javascripts/$(document).ready(function(){$(document).ajaxSend(function(event,request,settings){$('#loading-indicator').show(
标准Ruby记录器(即::Logger)是否可以在每次写入后自动刷新?更新:我正在根据Howtogettimestampsinyourrubyonrailslogs设置自定义日志格式化程序:classFoodefinitialize(params={})@logger=Logger.new$stdout@logger.formatter=LogFormatter.new@logger.level=params.include?(:log)?params[:log]:Logger::INFO#...endclassLogFormatter我尝试使用来自idlefingers的建议如下:d
我有一个非常基本的应用程序,可让您创建形状并用一条线将它们连接起来。为此,您需要执行以下操作。Example1.Clicknewanimation2.addrectangle3.addchild4.addcircle您可以移动形状、拖动和调整大小。我想知道是否可以在两个对象之间添加动画。因此,例如,一个小圆球会在两个物体之间的线上移动。我已经查看了fabricjs动画页面上的演示,但不确定是否可以从对象b执行。这是FIDDLE. 最佳答案 我不知道你是否可以在fabric中使用内置的动画功能,因为正如你所说,这些对象可能会自己移动。