我对这个问题感到非常难过,它应该是如此简单以至于让我疯狂。
我正在使用这个苹果反思教程。
它们具有从上到下显示的图像渐变。
任何帮助?
//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);
}
答案 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:
为了获得渐变,你应该对reflectImage添加另一个修改:withWidth。
- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
.....
CGImageRef gradientMaskImage = CreateGradientImage(width, 1);
.....
}