iphone – 从左到右的渐变方向
发布时间:2020-12-14 17:38:31 所属栏目:百科 来源:网络整理
导读:我完全被这个问题困扰了,它应该是如此简单以至于让我疯狂. 我正在使用这个苹果反射教程. Apple Reflection Example 它们具有从上到下显示的图像渐变. 如何从左到右制作渐变 如何水平翻转图像.在他们的例子中,他们垂直翻转图像. 任何帮助? //The gradient co
我完全被这个问题困扰了,它应该是如此简单以至于让我疯狂.
我正在使用这个苹果反射教程. 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); ..... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |