iOS 将一张图像向上滑动到另一张图像上,显示下面的图像。 (A-la jQuery.slide())

2023-12-06

我正在尝试做以下事情 -

我有同一图像的两个版本,一种是彩色的,一种是黑白的。我希望黑白“向上滑动”以显示其下方的图像。

我尝试设置高度和框架,但无法让它按照我想要的方式工作。

例如,这将是两个 UIImage 的组合,其中一个显示另一个,但不移动:

enter image description here

有任何想法吗? :)


好的,这是在灰色视图上使用蒙版的另一种方法。我实际上用 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 将一张图像向上滑动到另一张图像上,显示下面的图像。 (A-la jQuery.slide()) 的相关文章

随机推荐