我试图在scrollview中设置一些子视图的位置。我想创建一个特定的效果,因为他们滑入。我只是通过更改UIView上的框架来使用隐式动画,但是当它们滑入时它看起来太机器人。所以我希望创建一个反弹效果,让它们在幻灯片中滑入,稍微走远,然后返回到其预期的位置,非常接近滚动视图到达结尾时的样子,恰好相反。CoreAnimation动画帧
无论如何,我不能让它动画改变框架的起源。我不确定我错过了什么,因为如果我切换出正在进行动画制作(将第一个// *改为/ *),它可以很好地改变不透明度。
- (void)slideInStories;
{
float scrollViewContentWidth = 0;
for (StoryViewController *storyController in storyControllers) {
NSMutableArray *animationPoints = [NSMutableArray array];
CGRect viewFrame = storyController.view.frame;
//*
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
[animationPoints addObject:[NSValue valueWithCGRect:viewFrame]];
viewFrame.origin.x = scrollViewContentWidth - 10;
[animationPoints addObject:[NSValue valueWithCGRect:viewFrame]];
viewFrame.origin.x = scrollViewContentWidth;
[animationPoints addObject:[NSValue valueWithCGRect:viewFrame]];
/*/
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
[animationPoints addObject:[NSNumber numberWithFloat:0.75]];
[animationPoints addObject:[NSNumber numberWithFloat:0.0]];
[animationPoints addObject:[NSNumber numberWithFloat:0.75]];
//*/
[animation setValues:animationPoints];
[animation setDuration:4.0];
viewFrame.origin.x = scrollViewContentWidth;
scrollViewContentWidth += viewFrame.size.width;
[storyController.view.layer setFrame:viewFrame];
[storyController.view.layer setOpacity:1.0];
[storyController.view.layer addAnimation:animation forKey:nil];
}
[scrollView setContentSize:CGSizeMake(scrollViewContentWidth, 187.0f)];
}
您是否尝试过,只是为了踢腿,而不是用动画中心? – 2011-05-18 06:14:31
@Josh Caswell - 是的,我可以做的很好。 – dustins 2011-05-18 12:29:23