IOS shifts the image across the image, revealing the bottom. (A-la jQuery.slide ())

I am trying to do the following:

I have two versions of the same image, one color and one black and white. I want B & W to "Push Up", showing the one underneath.

I tried to set the height and frame, but could not get it to work the way I want.

For example, it will be a combination of both UIImages, where one shows the other without moving:

enter image description here

Any ideas? :)

+3
source share
2 answers

, . blueView greyView, . , . , , , , .

, XCode viewDidLoad. .

self.view.backgroundColor = [UIColor whiteColor];

UIView* blueView = [[[UIView alloc] init] autorelease];
blueView.backgroundColor = [UIColor blueColor];
blueView.frame = CGRectMake(50,50,100,100);

UIView* grayView = [[[UIView alloc] init] autorelease];
grayView.backgroundColor = [UIColor grayColor];
grayView.frame = CGRectMake(50,50,100,100);

[self.view addSubview:blueView];
[self.view addSubview:grayView];    // gray covers the blue

// Create a mask to allow the grey view to be visible and cover up the blue view
CALayer* mask = [CALayer layer];
mask.contentsScale   = grayView.layer.contentsScale;  // handle retina scaling
mask.frame           = grayView.layer.bounds;
mask.backgroundColor = [UIColor blackColor].CGColor;
grayView.layer.mask = mask;

// Animate the position of the mask off the grey view, as the grey becomes unmasked,
// that part of the grey "dissappears" and is no longer covering the blue underneath
CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"position"];
a.duration  = 4;
a.fromValue = [NSValue valueWithCGPoint:mask.position];
CGPoint newPosition = mask.position;
newPosition.y += mask.bounds.size.height;
a.toValue   = [NSValue valueWithCGPoint:newPosition];
a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[mask addAnimation:a forKey:@"colorize"];   // animate presentation

mask.position = newPosition;        // update actual position

#imports:

#import <QuartzCore/QuartzCore.h>
+4

UIView, B & W , () B & W.

[self.view insertSubview:bwImage aboveSubview:colorImage];

B & W. B & W:

bwImage.clipsToBounds = YES;

, bwImage, 0, B & W . - :

[UIView animateWithDuration:1.0 animations:^{
    CGRect b = bwImage.bounds;
    b.size.height = 0;
    bwImage.bounds = b;
}];

, , .

0

All Articles