【发布时间】:2016-02-12 11:35:56
【问题描述】:
我找到了这段代码,它负责为 UIView 设置动画,但不幸的是代码不起作用,我不知道原因(可能是 swift 的旧版本)
这是代码:
(根据创建者的说法,这是辅助函数)
func moveView(#view:UIView, toPoint destination:CGPoint, completion☹()->())?) {
//Always animate on main thread
dispatch_async(dispatch_get_main_queue(), { () Void in
//Use UIView animation API
UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping:
0.6, initialSpringVelocity: 0.3, options:
UIViewAnimationOptions.AllowAnimatedContent, animations: { () ->
Void in
//do actual move
view.center = destination
}, completion: { (complete) -> Void in
//when animation completes, activate block if not nil
if complete {
if let c = completion {
c()
}
}
})
})
}
这是动画
//Create your face object (Just a UIImageView with a face as the image
var face = Face();
face.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
//find our trajectory points
var center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
var left = CGPointMake(center.x *-0.3, center.y)
var right = CGPointMake(center.x *2.2, center.y)
//place our view off screen
face.center = right
self.view.addSubview(face)
//move to center
moveView(view: face, toPoint: center) { () -> () in
//Do your Pop
face.pop()
// Move to left
moveView(view: face, toPoint: left, completion: { () -> () in
}
}
我引用了代码的创建者
一般步骤:在屏幕的右边缘创建一个新面孔。制作 脸可见。将脸部移动到屏幕中间。弹出 face 用下一张脸开始这个过程。将第一个面移动到 新面孔一到中间就离开。
实际的幻灯片动画 再次,我们将在此处执行以下操作:移动 查看右侧屏幕外移到中心 Pop 移到左侧
要获得重复效果,只需在计时器上调用此方法
和一个总结:
UIView 的动画 API 非常强大。流行和运动 动画使用取决于此 API。如果你坚持尝试 创建动画,UIView 动画块通常是一个好地方 开始。
注意:如果有人可以为我解释代码,我是 IOS 开发的初学者
【问题讨论】:
-
一切都很好。谢谢您,先生,我真的很感谢您的帮助。
标签: ios swift animation uiview