从顶部到底部的渐变 [英] gradient cut from top to bottom

查看:64
本文介绍了从顶部到底部的渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是针对-从左到右的梯度方向

在此Apple Refection示例代码中,

In this apple refection sample code,

移动大小滑块时,图像从下至上被剪切.移动滑块时,如何从顶部到底部切割它?我试图更好地理解本教程

when the size slider is moved, the image is cut from bottom to top. How can I cut it from top to bottom when the slider is moved? I am trying to understand this tutorial better

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

如果要反射的图像位于顶部,该怎么办.因此,为了正确显示它,我需要从上至下而不是从下至上显示它.那就是我想要达到的效果.在这种情况下,我只是在其故事板示例中移动了UIImageViews.您现在看到了我的困境

What if the image to reflect was on the top. So in order to show it properly, I need to reveal it from top down, not bottom up. That;s the effect I am trying to achieve. In this case I just moved the UIImageViews around in their storyboard example. You now see my dilemma

推荐答案

它与@ Putz1103答案非常相似.您应该从前一个方法创建一个新方法-(UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width.

it's very similar to @Putz1103 answer. You should create a new method starting from the previous - (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width.

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width andHeight:(NSUInteger)height
{
     ....
     CGContextClipToMask(mainViewContentContext, CGRectMake(0.0, 0.0, width, height), gradientMaskImage);
     ....
}

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

Then in slideAction method, use something like:

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

祝你好运!

这篇关于从顶部到底部的渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆