如何在iOS中为CATransition设置框架

时间:2014-11-14 09:44:26

标签: ios

我对ios开发很新。我有一个与CATransition有关的疑问。我从屏幕的顶部到中间放置了一个图像视图(0,0,320,250)。我使用动画在viewdidload中从下到上动画图像方法。但是图像是从self.view的底部制作动画,但我需要从高度250而不是从568动画图像。

我使用的代码如下:

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;

[topImage.layer addAnimation:transition forKey:nil];

enter image description here

在我们有青色的图像中,我将图像放在那里。我需要从黑色开始为图像设置动画。

如果有任何答案,请告诉我。

提前致谢.....

1 个答案:

答案 0 :(得分:0)

@ 09121989编写以下代码

CABasicAnimation *moveUP;
moveUP            = [CABasicAnimation animationWithKeyPath:@"position.y"];
  [moveUP setFromValue:[NSNumber numberWithFloat:([UIScreen mainScreen].bounds.size.height-imag.frame.size.height/2)]];
    moveUP.toValue = [NSNumber numberWithFloat:imag.frame.size.height/2.0];
moveUP.duration   = 2.0;
moveUP.removedOnCompletion = NO;
moveUP.fillMode   = kCAFillModeForwards;
moveUP.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
return moveUP;