Top down gradient

This next question is the direction of the gradient from left to right.

In this example, the apple fix code

Apple Reflection Example

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

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

enter image description here

What to do if the image for reflection was on top. Therefore, to show this correctly, I need to open it from top to bottom, and not from bottom to top. This is the effect that I am trying to achieve. In this case, I just moved the UIImageViews in my storyboard example. Now you see my dilemma

0
source share
2 answers

It is very similar to @ Putz1103. You must create a new method, starting with the previous one - (UIImage *) reflectionImage: (UIImageView *) fromImage withWidth: (NSUInteger).

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

Then in the slideAction method use something like:

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

Good luck

+1
source

My guess would be this:

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

If you change it to this, it should do the opposite:

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

Basically you need to set the crop rectangle at the bottom of the image instead of the top of the image. This will invert what your slider does, but it is easy to resolve, and I will leave it for your exercise.

0
source

All Articles