gpt4 book ai didi

ios - 如何使用设置了背景图案的 UIView 并使用动画将其垂直缩小

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:48:15 25 4
gpt4 key购买 nike

我希望 View 的顶部在快速动画中与 View 的底部相遇,以使其消失。 (最好先让它生长一秒钟。)

我该怎么做呢? UIView 的背景图案设置为 [UIColor colorWithPattern:],当我执行 self.textOptionsPopover.transform = CGAffineTransformMakeScale(0.0, 0.5); 时,它就完全消失了.

最佳答案

你有错误的 x 比例参数 - CGAffineTransformMakeScale(0.0, 0.5)更改为 CGAffineTransformMakeScale(1.0, 0.5),因为您不想修改宽度。

0.0 是您的 View 消失的原因。

但如果您希望先让它增长一段时间,使用 CAKeyframeAnimation 会更容易 - 您可以轻松控制键时间、值和计时功能。例如你可以这样做:

CAKeyframeAnimation *shrinkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
shrinkAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.4, 1.0)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 0.0, 1.0)],
nil];
shrinkAnimation.keyTimes = [NSArray arrayWithObjects:@0.0, @0.2, @1.0, nil];
shrinkAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
shrinkAnimation.duration = 0.4;
shrinkAnimation.removedOnCompletion = NO;
shrinkAnimation.fillMode = kCAFillModeForwards;
[self. textOptionsPopover.layer addAnimation:shrinkAnimation forKey:@"shrink"];

编辑:如果您希望 View “从上到下”缩小,只需更改图层的 anchor (记住更改 anchor 会更改框架!):

CGRect frame = self.textOptionsPopover.layer.frame;
self.textOptionsPopover.layer.anchorPoint = CGPointMake(0.5, 1.0);
self.textOptionsPopover.layer.frame = frame;

关于ios - 如何使用设置了背景图案的 UIView 并使用动画将其垂直缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com