在其他视图iOS上重叠幻灯片过渡的动画图像

时间:2013-02-20 11:49:47

标签: iphone ios animation slide catransition

我有两个并排的imageViews,如图所示:enter image description here

我需要通过重复动画作为滑动视图来更改这些图像。我这样做是通过使用NSTimer。

以下是我用于创建动画的代码:

CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]] ;

[[imgVwTry layer] addAnimation:animation forKey:@"@asdf"];

但是,Left ImageView中的动画从图像视图的超出范围开始。相同如下图所示:

enter image description here

让我以更清晰的方式解释:

正在发生的动画与Right ImageView重叠。但是,我希望动画仅出现在为LeftImageView指定的区域中。像这样的东西: enter image description here

我应该在动画代码中做出什么改变,我可以删除重叠。或者还有其他方法可以为图像设置动画吗?

一个更快的问题, 如果我使用UIImageView的startAnimation方法,我可以将动画更改为幻灯片动画吗?

1 个答案:

答案 0 :(得分:1)

您应该在包含您正在谈论的图像的超级视图上将clipsToBounds设置为YES。这将阻止子视图显示,直到它在您的框架范围内。