iOS的向上滑动的图像在图像,露出底下之一。 (A-LA jQuery.slide()) [英] iOS slide up an image over an image, revealing the underneath one. (A-la jQuery.slide())

查看:186
本文介绍了iOS的向上滑动的图像在图像,露出底下之一。 (A-LA jQuery.slide())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着做以下的事情 -

I'm trying to do the following thing -

我有两个版本相同的图像,一种彩色和一个黑色和白色。我想B和W至向上滑动露出其下的人。

I have two version of the same image, one colored and one black and white. I want the B&W to "Slide up" revealing the one under it.

我尝试设置高度和框架,但不能得到它的工作就像我希望它。

I tried setting the height and the frame, but couldn't get it to work like I want it to.

例如,这将是既UIImages其中一个是揭示所述其它的组合,而没有移动

For example , this would be a combination of both UIImages where one is revealing the other, while not moving:

任何想法? :)

推荐答案

确定,这里是用灰色视图口罩不同的方法。其实,我与蓝景和greyView,其中灰色覆盖了蓝色的测试这一点。把灰色层上形成掩模层,使灰层是可见的。现在动画面具从灰层而去,使得灰层消失无移动它,蓝色的节目直通那里的灰色消失。

OK, here is a different method using a mask on the grey view. I actually tested this with a blueView and a greyView, where the grey covers up the blue. Put a mask layer on the grey layer so that the grey layer is visible. Now animate the mask away from the grey layer, making the grey layer disappear without moving it, the blue shows thru where the grey disappears.

如果你想用这个实验,创造X code。将空的项目,单一视图,并且把这种code里面viewDidLoad中。这就是我测试了。

If you want to experiment with this, create an empty project in XCode with a single view, and put this code inside viewDidLoad. That's how I tested this.

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:

Don't forget this line at the top with the #imports:

#import <QuartzCore/QuartzCore.h>

这篇关于iOS的向上滑动的图像在图像,露出底下之一。 (A-LA jQuery.slide())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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