从左到右的渐变方向 [英] gradient direction from left to right
本文介绍了从左到右的渐变方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对这个问题完全感到困惑,它应该是如此简单,以至于让我发疯.
I am completely stumped on this problem and it should be so simple that its driving me nuts.
我正在使用这个苹果反射教程.
I am working with this apple reflection tutorial.
They have the image gradient that shows up from top to bottom.
- 如何从左到右进行渐变
- 如何水平翻转图像.在他们的示例中,他们垂直翻转图像.
有什么帮助吗?
//The gradient code is here but I don't know what should be the gradient start / end points
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
.....
gradientStartPoint = CGPointZero;
gradientEndPoint = CGPointMake(0, pixelsHigh);
}
//similarly I know the image flip happens here but for life of me I cannot make it flip horizontally
- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height
{
.....
CGContextTranslateCTM(mainViewContentContext, 0.0, height);
CGContextScaleCTM(mainViewContentContext, 1.0, -1.0);
}
推荐答案
尝试一下:
//horizontal gradient
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
.....
gradientStartPoint = CGPointZero;
gradientEndPoint = CGPointMake(pixelsWide, 0);
}
//horizontal flip
- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
.....
CGContextTranslateCTM(mainViewContentContext, width, 0,0);
CGContextScaleCTM(mainViewContentContext, -1.0, 1.0);
}
对于水平翻转,您应该添加一个新方法,因为您必须指定宽度,而不是高度.
For the horizontal flip you should add a new method, since you have to specify the width, no the height.
祝你好运!
为了获得渐变,您应该对ReflectedImage:withWidth添加另一个修改.
In order to get the gradient, you should add another modification to reflectedImage:withWidth.
- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
.....
CGImageRef gradientMaskImage = CreateGradientImage(width, 1);
.....
}
这篇关于从左到右的渐变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文