使用CATransition从当前位置滑动图像400px

时间:2013-06-24 10:26:33

标签: iphone ios objective-c

我有一个UIImageView,我已经在我的XIB文件中找到了我想要的位置。当我的viewController被调用时,我想让图像在3秒的时间内向右移动大约400px。然后我希望图像淡出。

我一直在玩QuartzCore和CATransition,并且能够随着时间的推移淡出图像:

CATransition *animation = [CATransition animation];
        animation.type = kCATransitionFade;
        animation.duration = 0.4;
        [coverImage.layer addAnimation:animation forKey:nil];


        coverImage.hidden = true;

但是,我希望图像向右滑动。有人知道怎么做吗?谢谢!

3 个答案:

答案 0 :(得分:1)

//有子类型属性,它提供从右或从左转换。您只需将此属性设置为下面的

 animation.subtype = kCATransitionFromRight;

答案 1 :(得分:1)

使用CATransition进行移动图像非常过分。我建议使用UIView动画,然后你只需要

// UIImageView *coverImage = ...

// This will move the image to the right and then fade it out.
[UIView animateWithDuration:3 animations:^{
    coverImage.center = CGPointMake(coverImage.center.x + 400, coverImage.center.y);
    coverImage.alpha = 0.0f;
}];

答案 2 :(得分:1)

UIImageView *coverImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 300, 200, 400)];
coverImage.backgroundColor = [UIColor blackColor];
[self.view addSubview:coverImage];

[UIView animateWithDuration:0.4 animations:^{
    coverImage.frame = CGRectInset(coverImage.frame, -400, 0);
    coverImage.alpha = 0.0f;
}];