Iphone 从上到下的渐变

Iphone 从上到下的渐变,iphone,ios,xcode,Iphone,Ios,Xcode,这是一项跟进质询—— 在这个苹果反射示例代码中 移动“大小”滑块时,将从下到上剪切图像。移动滑块时,如何从上到下剪切?我正在努力更好地理解本教程 //I know the code is in this section here but I can't figure out what to change - (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height { ... }

这是一项跟进质询——

在这个苹果反射示例代码中

移动“大小”滑块时,将从下到上剪切图像。移动滑块时,如何从上到下剪切?我正在努力更好地理解本教程

//I know the code is in this section here but I can't figure out what to change
- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height
{
...
}

    //it probably has something to do with this code. 
//I think this tells it how much to cut. 
//Though I can't figure out how does it know where the 0,0 of the image is and why 
// keep 0,0 of the image on the top? I am assuming this is where it hinges its 
//point and cuts the image from bottom to top
CGContextRef MyCreateBitmapContext(int pixelsWide, int pixelsHigh)
{

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    // create the bitmap context
    CGContextRef bitmapContext = CGBitmapContextCreate (NULL, pixelsWide, pixelsHigh, 8, 0, colorSpace,(kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
    CGColorSpaceRelease(colorSpace);

    return bitmapContext;
}


如果要反射的图像在顶部会怎样。所以为了正确地展示它,我需要从上到下而不是从下到上展示它。那个这就是我想要达到的效果。在本例中,我只是在情节提要示例中移动了UIImageView。你现在看到了我的困境

我的猜测是这样的:

CGContextClipToMask(mainViewContentContext, CGRectMake(0.0, 0.0, fromImage.bounds.size.width, height), gradientMaskImage);
如果将其更改为此,则应执行相反的操作:

CGContextClipToMask(mainViewContentContext, CGRectMake(0.0, fromImage.bounds.size.height - height, fromImage.bounds.size.width, height), gradientMaskImage);

基本上,您需要将剪切矩形设置为图像的底部,而不是图像的顶部。这将反转滑块的作用,但这很容易解决,我将留给您练习。

这与@Putz1103答案非常相似。您应该从前面的-(UIImage*)ReflectImage:(UIImageView*)fromImage withWidth:(NSInteger)width创建一个新方法

然后在slideAction方法中,使用类似以下内容:

self.reflectionView.image = [self reflectedImage:self.imageView withWidth:self.imageView.bounds.size.width andHeight:reflectionHeight];

祝你好运

我只是试了一下,但没有成功。还是从头到脚谢谢你帮了我。不幸的是,这不起作用。如果您注意到图像的渐变仍然位于底部。我想做的是让它向另一个方向翻转。不幸的是,你给我的代码没有做到这一点。我的意思是,我看不出行为上有什么不同。我试图陶醉的形象就在上面。请看我帖子中的截图和一些解释。路易斯-你看到顶部的黑色渐变了吗?当你移动尺寸滑块时,梯度会保持在反转图像的顶部吗?我刚刚清理并再次下载了本教程的一份新副本,做了您显示的两个更改,但我仍然看到它的行为方式相同。你能把你看到的东西贴一张照片吗?@SamBudda我把我的回答限制在:“当滑块移动时,我如何从上到下剪切它?”,这对我很有用。您还需要更改渐变的行为吗?
self.reflectionView.image = [self reflectedImage:self.imageView withWidth:self.imageView.bounds.size.width andHeight:reflectionHeight];