[英]how change the alpha value of half of UIImage or UIImageView
我正在尝试创建一个动画效果,其中开始时alpha值为0.5(大约)的图像逐渐变为1,但不像传统效果那样。 这是我正在寻找的。
原始图像。
一段时间后
过了一段时间
最后
所以基本上如果图像的一部分的alpha值可以减少,我可以显示填充玻璃或接近它的东西的动画。
我不知道这是否可以完成,或者是否可以使用核心图形或核心动画。
PS他们是在photoshop中制作的。
有没有人对应该采取什么措施来实现这种动画?
您可以在上方添加视图并更改其框架。 最好的方法。
如果你正在使用图像,那么sunclass UIView并实现
-(void) drawRect:(CGRect) rect {
//if you want to clip the image, the frame for the view must be smaller then rect
[image drawInRect: rect];
}
我建议如下:
创建一个具有背景颜色和透明度的新UIView:
UIView *transpView = [UIView new]; tranpsView.alpha = 0.4; transpView.frame = self.view.frame; [self.view addSubview:transpView];
为透明视图设置动画以向上滑动:
[UIView animateWithDuration:1.0 animations:^{ transpView.frame = CGRectOffset(transpView.frame, 0, -tranpsView.frame.size.height); }];
完成后不要忘记释放tranpsView
。 可能与completed
块。
要获得“玻璃填充”类型的动画,只需相应地更改tranpsView
的frame
。 tranpsView
可以是任何UIView子类(如液体或其他东西的纹理)。
希望有所帮助。!
这是另一个想法。
将您的UIView *view
的背景设置为alpha = 0.5所需的image.png
。 让
w = view.bounds.size.width;
h = view.bounds.size.height;
使用alpha = 0.5创建另一个UIView *glassView
,并将其添加为子视图:
[view addSubview:glassView];
glassView.frame = CGRectMake(0.0, h, w, 0.0);
创建一个UIImageView *glassImageView
并将其image
设置为image.png
,并将其添加为glassView
的子视图:
[glassView addSubview:glassImageView];
glassImageView.frame = CGRectMake(0.0, -h, w, h);
现在设置了动画,以增加高度和α glassView
,同时保持规模imageGlassView
,是这样的:
[UIView beginAnimations:nil context:NULL]; {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
glassView.alpha = 1.0;
glassView.frame = CGRectMake(0.0, 0.0, w, h);
glassImageView.frame = CGRectMake(0.0, 0.0, w, h);
} [UIView commitAnimations];
公平地说,我没有对此进行过测试,但是沿着这些方向的某些东西似乎可能会起作用。 然后,也许不是。 如果您找到了完美的解决方案,请将其发回。 我很想知道怎么做!
嗯,我知道这个问题已经很老了,而且我是那个问过它的人,但是今天我正在尝试类似的东西,并且发现这个简单的解决方案来解决我10个月前提出的问题。
我正在开发一个项目,要求图像看起来像是从完全白色的加载,0%进展到完全红色图像,这是100%的进展。
我想添加2个包含图像的imageViews并将包含图像的顶部imageview的内容模式设置为底部,这样当你缩小imageview的大小时,图像似乎正在加载并且它起作用。 对于一些动画块,图像似乎正在加载。 然后我想到了这个问题,我问了很久,然后提出了解决我自己问题的方法。
所以这个问题的解决方案是,如果你在彼此的顶部添加2个imageViews,然后减少后面的alpha值并将高度降低到零,然后逐渐增加高度并更改图像视图的y坐标具有alpha值1然后它似乎按照此问题中的要求加载。
我已经使用这两个函数来获得加载图像的错觉。
- (void)startAnimation
{
CGRect rect = loadedImageView.frame;
rect.origin.y = unloadedImageView.frame.origin.y;
rect.size.height = unloadedImageView.frame.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationDidStopSelector:@selector(stopAnimation)];
loadedImageView.frame = rect;
[UIView commitAnimations];
}
- (void)stopAnimation
{
CGRect rect = loadedImageView.frame;
rect.origin.y = unloadedImageView.frame.size.height + unloadedImageView.frame.origin.y;
rect.size.height = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationDidStopSelector:@selector(startAnimation)];
loadedImageView.frame = rect;
[UIView commitAnimations];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.