Ios 旧swift代码不起作用(为UIView设置动画)
我发现这段代码负责制作UIView的动画,但不幸的是,这段代码不起作用,我无法找出原因(可能是swift的旧版本) 代码如下: (根据创建者,这是辅助功能) 这就是动画Ios 旧swift代码不起作用(为UIView设置动画),ios,swift,animation,uiview,Ios,Swift,Animation,Uiview,我发现这段代码负责制作UIView的动画,但不幸的是,这段代码不起作用,我无法找出原因(可能是swift的旧版本) 代码如下: (根据创建者,这是辅助功能) 这就是动画 //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 trajector
//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
}
}
我引用代码创建者的话
一般步骤:在屏幕右边缘创建一个新面。制作
那张脸是看得见的。将面移到屏幕中间。弹出
面使用下一个面开始该过程。将第一个面移动到下一个面
新面孔一到中间就向左
再次实际幻灯片动画,我们将在此处执行以下操作:移动
在右侧屏幕外查看移动到中间弹出移动到左侧
要获得重复效果,只需在计时器上调用此方法
和总结:
UIView的动画API非常强大。流行音乐和运动
动画的使用取决于此API。如果你一直在努力
创建一个动画,UIView动画块通常是一个很好的地方
开始
注意:我是IOS开发的初学者,如果有人能给我解释一下代码的话确实这个
moveView
方法有一些问题,一个是它是为Swift 1编写的(但也有一些打字错误、错误字符和无用的操作)
以下是固定版本:
func moveView(view view:UIView, toPoint destination: CGPoint, afterAnim: ()->()) {
//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
//if and when animation completes, callback
if complete {
afterAnim()
}
})
})
}
您现在可以这样使用它:
moveView(view: face, toPoint: center) {
//Do your Pop
face.pop()
// Move to left
moveView(view: face, toPoint: left) {
// Do stuff when the move is finished
}
}
观察你的版本和我的版本之间的差异,了解什么是过时/错误的,以及我是如何修复的。如果你被卡住了,我会帮助你。确实,这个
moveView
方法有一些问题,一个是它是为Swift 1编写的(但也有一些打字错误、错误字符和无用的操作)
以下是固定版本:
func moveView(view view:UIView, toPoint destination: CGPoint, afterAnim: ()->()) {
//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
//if and when animation completes, callback
if complete {
afterAnim()
}
})
})
}
您现在可以这样使用它:
moveView(view: face, toPoint: center) {
//Do your Pop
face.pop()
// Move to left
moveView(view: face, toPoint: left) {
// Do stuff when the move is finished
}
}
观察你的版本和我的版本之间的差异,了解什么是过时/错误的,以及我是如何修复的。如果你陷入困境,我会帮助你。一切都好。谢谢你,先生,我真的很感谢你的帮助。一切都很好。谢谢你,先生,我真的很感谢你的帮助。