kCATransitionPush 应用于来自 UIImageview 的幻灯片 in/out 图像,没有 fade/transparent 效果 iOS
kCATransitionPush applied to slide in/out image from UIImageview without fade/transparent effects iOS
我在屏幕上的某个位置有一个 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,但其中 none 似乎有效。任何帮助,将不胜感激。谢谢!
您可以尝试使用另一个图像视图和 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];
}];
我在屏幕上的某个位置有一个 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,但其中 none 似乎有效。任何帮助,将不胜感激。谢谢!
您可以尝试使用另一个图像视图和 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];
}];