没有动画,我正在学习核心动画
运行此代码时,屏幕上不显示while (fgets((char *) sampleText, 3000, fp) != NULL)
{
for(int i = 0; sampleText[i]; i++)
{
int temp;
temp = utf8_to_codepoint(&sampleText[i], &lenptr);
printf("%d\n", temp);
printf("i: %d\n", i);
for(int k = 0; k < unicodeData[0].languagecount; k++)
{
if(temp <= unicodeData[k].max && temp >= unicodeData[k].min)
{
unicodeData[k].numChars++;
}
}
}
}
图像。然后4秒钟后,它重新出现并按预期完成。不知道为什么。我想要的是,当应用程序启动时,top
图像会出现在屏幕上,然后在4秒后,top
图像向上移动并离开屏幕。
top
有什么想法吗?
答案 0 :(得分:0)
所以你希望图像在开始时在屏幕上显示,然后在4秒后从顶部飞起来?您可以通过将动画分组在一起来实现此目的
override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
// keep a track of where we want it to be
let y = self.top.layer.position.y
// move it out of the way - this where it will end up after the animation
self.top.layer.position.y = -self.view.bounds.size.height
// do nothing, other than display the image for 4 seconds
let doNothing = CABasicAnimation(keyPath: "position.y")
doNothing.fromValue = y
doNothing.toValue = y
doNothing.duration = 4.0
// zip it away
let openTop = CABasicAnimation(keyPath: "position.y")
openTop.fromValue = y
openTop.toValue = -self.view.bounds.size.height
openTop.duration = 1.0
openTop.beginTime = doNothing.beginTime + doNothing.duration
// create the group
let group = CAAnimationGroup()
group.duration = 5.01
group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
group.removedOnCompletion = false
group.fillMode = kCAFillModeForwards
group.animations = [doNothing, openTop]
self.top.layer.addAnimation(group, forKey: nil)
}
答案 1 :(得分:0)
这是我想出的:
let l = top.layer!
let startingPosition = l.position
l.position = CGPointMake( CGRectGetMidX( self.view.bounds ), -l.frame.height * 0.5 )
l.addAnimation({
let anim = CABasicAnimation( keyPath: "position" )
anim.fromValue = NSValue( CGPoint:startingPosition )
anim.beginTime = CACurrentMediaTime() + 4.0
anim.fillMode = kCAFillModeBoth
return anim
}(), forKey: nil)