kCATransitionPush应用于从UIImageview滑入/滑出图像而没有淡入淡出/透明效果iOS

时间:2015-06-11 17:39:05

标签: ios objective-c xcode uiimageview

我在屏幕上的某个位置有一个UIImageView:

self.imageView = [[UIImageView alloc] init];
self.imageView.clipsToBounds = YES;
self.imageView.image = [UIImage imageNamed:@"food"];
[self.imageView setFrame:CGRectMake(0, 0 , (self.view.frame.size.width/5), 60)];

然后我必须使用以下代码在UIImageView中滑入另一个图像:

self.imageView.image = NULL;
CATransition *animation = [CATransition animation];
        [animation setDuration:0.75];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromLeft];
        animation.delegate = self;
        [[self.imageView layer] addAnimation:animation forKey:nil];

但是当第一张图像滑出时,它会淡出(或者看起来对于imageView的边缘是透明的)。我尝试了很多我能找到的在线解决方案,比如在动画期间设置图层属性以删除淡入淡出或将图层不透明度分配给1.0,但它们似乎都没有工作。任何帮助,将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用其他图片视图和UIView动画尝试不同的方法:

UIImage *newImage = [UIImage imageNamed:@"newImage"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:newImage];
imageView.frame = self.imageView.frame;
[self.view addSubview:imageView];

imageView.transform = CGAffineTransformMakeTranslation(-imageView.frame.size.width, 0);
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveLinear animations:^()
{
    imageView.transform = CGAffineTransformIdentity;
}
                 completion:^(BOOL finished)
{
    self.imageView.image = newImage;
    [imageView removeFromSuperview];
}];