简体   繁体   English

渐变方向从左到右

[英]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. 我正在使用这个苹果反射教程。

Apple Reflection Example Apple反射示例

They have the image gradient that shows up from top to bottom. 它们具有从上到下显示的图像渐变。

  • How can I make a gradient from left to right 如何从左到右制作渐变
  • how can I flip the image horizontally. 如何水平翻转图像。 In their example they flip the image vertically. 在他们的例子中,他们垂直翻转图像。

any help? 任何帮助?

//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);
}

Try this: 试试这个:

//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. 对于水平翻转,您应该添加一个新方法,因为您必须指定宽度,而不是高度。

Good Luck! 祝好运!

EDIT 1: 编辑1:

In order to get the gradient, you should add another modification to reflectedImage:withWidth. 为了获得渐变,您应该为reflectImage添加另一个修改:withWidth。

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
    .....
    CGImageRef gradientMaskImage = CreateGradientImage(width, 1);
    .....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM