2013-01-16 88 views
4

我完全在这个问题上难住,它应该是如此简单,它使我疯狂。梯度方向从左到右

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

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

回答

4

试试这个:

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

对于你应该添加一个新方法的水平翻转,因为你必须指定宽度,没有高度。

祝你好运!

编辑1:

为了得到梯度,你应该添加另一种变reflectedImage:withWidth。

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

感谢您的代码。水平翻转完美地工作,但从左到右的梯度不起作用。它显示了图像上的渐变,而不是从中间的某个地方开始,一直走到正确的位置 –

+0

ok,正在工作 – LuisEspinoza

+0

我在我的帖子中附加了一个图像,当我输入渐变gradientStartPoint = CGPointZero; gradientEndPoint = CGPointMake(pixelsWide,0); –