- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这里的函数是为了使 View 动画如下:2 秒淡出,2 秒淡入,2 秒延迟和重复。由于某种原因,动画只预制一次并且不重复。我在这里做错了什么?
UIView.animateWithDuration(6.0,
delay: 0.0,
options: [.AllowUserInteraction,.Repeat,.BeginFromCurrentState],
animations: {
UIView.animateWithDuration(2.0,
delay: 0.0,
options: [.AllowUserInteraction,.BeginFromCurrentState] ,
animations: {
//fade out
self.alpha = 0.5
},
completion: { finished in
UIView.animateWithDuration(2.0,
delay: 0.0,
options: [.AllowUserInteraction,.BeginFromCurrentState],
animations: {
//fade in
self.alpha = 1.0
},
completion: { finished in
UIView.animateWithDuration(2.0,
delay: 0.0,
options: [.AllowUserInteraction,.BeginFromCurrentState],
animations: {
},
completion: { finished in
})
})
})
},
completion: { finished in
})
}
最佳答案
您可以使用 Core Animation delegates 来永远重复您的动画,例如:
func animateCustomView(layer: CALayer) {
let speed = 60.0 / Double(view.layer.frame.size.width)
let duration: NSTimeInterval = Double(view.layer.frame.size.width - layer.frame.origin.x) * speed
let move = CABasicAnimation(keyPath: "position.x")
move.duration = duration
move.toValue = self.view.bounds.size.width + layer.bounds.width / 2
move.delegate = self
move.setValue("view", forKey: "name")
move.setValue(layer, forKey: "layer")
layer.addAnimation(move, forKey: nil)
}
// Core Animation Delegate implementation
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let name = anim.valueForKey("name") as? String{
if name == "view" {
let layer = anim.valueForKey("layer") as? CALayer
layer?.position.x = -(layer?.bounds.width)! / 2
delay(seconds: 0.5, completion: {
self.animateCustomView(layer!)
})
// Here add more delays and in completion handler block, add your chained animations.
} else if name == "other name" {
// or you can reinitialize it your another chained animations, delay it and call it again.
}
}
}
override func viewDidAppear(animated: Bool) {
animateCustomView(viewToAnimate.layer)
// Here call your other chained animations
}
函数的内容只是用于示例目的的代码,您可以在那里添加自定义动画。
关于ios - swift 重复链式动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36841514/
一晃五年没写博客了,依旧再C#上耕耘,依旧没有啥建树,现在也不知道.net上还有多少人再使用,在这里分享一些自己觉得写的还算优雅的代码。 对于自己写着完的代码,我特别喜欢链式(来源于jQuer
我正在构建一个吉他和弦查找应用程序。我使用多维数组来表示指板。数组中的每个元素都由具有字符串属性“Note”的 FretSpace 结构表示。为了初始化指板上的音符属性,我传递了要处理的吉他弦的详细信
我在演示代码中使用 setTimeout 函数模拟了 3 个 ajax 调用。我将从一段运行良好的代码开始:所有调用都是并行进行的,我希望所有调用都能成功,否则会出现错误。 var p1 = func
谁能解释一下? a = [2,3,4] b = [5,6,8,9] print(len(a) > 0) print(len(b) > 0) print((len(a) > 0) & len(b) >
我正在处理具有多个子 JSONObject 的 JSONObject。这是我填写内容的方式: myJson.getJSONObject(CAT_NAME).put(VAR_NAME, var)
想象一下这种情况,我有一个需要检查属性的对象。但是,该对象当前可以具有空值。 如何在一个“if”条件下检查这两个条件? 目前,我必须做这样的事情: if (myObject != null) {
我有一个对象集合,称它们为obj。他们有一个 act() 方法。 act() 方法最终会导致 o 上的 event() observable 调用 onComplete。 链接这些的好方法是什么? 即
假设我有一个列表变量 datalist 存储 10,000 个字符串实体。QTableView 只需要显示其中的一些实体。这就是为什么 QTableView 被指定为 QSortFilterProxy
我正在寻找支持链式 MSI 安装的工具(最好不是 InstallShield,而且最好是便宜/免费的)。我有几个小型安装需要能够单独部署,但也需要作为一个组部署,我不想维护多个安装程序。 看起来我需要
在这种情况下,我想迭代集合中除最后 2 个元素之外的所有元素。 假设我采用了一种奇怪的方式,例如 x.Reverse().Skip(2).Reverse()。 每个 LINQ 操作是否会有效地生成一个
对于javascript来说非常陌生,我有两个html数字选择,包括年份,我想将第二个选择与第一个选择链接起来,这样当我在第一个选择中选择年份时(而第二个选择没有选项)首先),第二个选择应包括从所选数
有人可以向我解释一下为什么以下两个链式函数: // returns zero if okay var resetCounter = function (model) { return new Prom
所以我有 2 个 promise 函数。当第一个函数出现错误时,我希望它显示错误消息。当完成或失败时,我希望他们执行一个finally catch all 函数,但由于某种原因它不起作用。我的代码如下
我有一个函数 const func = () => server.insertPatientSurveyQuestionToDataBase(Store.getPatientID(), SurveyN
(async function() { var a,b; function flush(){ return new Promise(res => {
这个问题已经有答案了: Promise chaining: Use result from previous promise in next then callback [duplicate] (1
这可能不是专业正则表达式理解的问题。唯一重要的是因为我正在运行多个链式替换命令,这些命令会影响文本文件中的某些相同文本。我还想象在替换之前,根据分隔符词(需要多次替换)的使用方式对 txt 文件进行分
我正在尝试构建一组类来定义 OSI 堆栈中协议(protocol)的分层属性...从抽象意义上讲,我只需要从父 python 类继承属性,但我需要能够调用整个类链一次...所以,我正在寻找这样的东西.
我正在努力兑现 promise ,到目前为止我偶然发现了这一点: new Promise((resolve, reject) => { setTimeout(() => { r
我试图理解 promise ,我需要链接它们并装饰来自不同端点的对象宽度数据。 例如: 我的 Node-express 应用程序中有这个 //controller.js export const ge
我是一名优秀的程序员,十分优秀!