iphone – 从左到右的渐变方向

前端之家收集整理的这篇文章主要介绍了iphone – 从左到右的渐变方向前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我完全被这个问题困扰了,它应该是如此简单以至于让我疯狂.

我正在使用这个苹果反射教程.

Apple Reflection Example

它们具有从上到下显示的图像渐变.

>如何从左到右制作渐变
>如何水平翻转图像.在他们的例子中,他们垂直翻转图像.

任何帮助?

//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);
    CGContextScaleCTM(mainViewContentContext,-1.0,1.0);
}

对于水平翻转,您应该添加一个新方法,因为您必须指定宽度,而不是高度.

祝好运!

编辑1:

为了获得渐变,您应该为reflectImage添加另一个修改:withWidth.

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

猜你在找的Xcode相关文章