0

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

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

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


        coverImage.hidden = true;

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

4

3 回答 3

1

//有子类型属性提供从右或从左的转换。您只需设置此属性,如下所示

 animation.subtype = kCATransitionFromRight;
于 2013-06-24T10:30:33.437 回答
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;
}];
于 2013-06-24T10:33:19.370 回答
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;
}];
于 2013-06-24T10:35:30.933 回答