gpt4 book ai didi

iphone - 同时调整 UIView 的大小和移动动画

转载 作者:行者123 更新时间:2023-12-03 18:59:02 26 4
gpt4 key购买 nike

我想将 UIView“拉伸(stretch)”到右侧,这意味着使用 [UIView beginAnimations] 将其frame.size.width增加foo像素,同时将其frame.origin.x减少foo像素句法。但是,如果我这样做,当动画开始时, View 会立即调整大小,然后启动原点的动画。

CGRect currFrame = someView.frame;
currFrame.size.width += 100;
currFrame.origin.x -= 100;

[UIView beginAnimations:@"Anim1" context:nil];
someView.frame = currFrame;
[UIView setAnimationDuration:0.7];
[UIView commitAnimations];

我也尝试过将动画分成两部分,但我无法保持正确的位置。

非常感谢任何帮助!

最佳答案

您可能需要下拉到核心动画并将其分成两个显式动画:

CABasicAnimation *stetchAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
stetchAnimation.toValue = [NSNumber numberWithDouble:(someView.frame.size.width+100)/someView.frame.size.width];

CABasicAnimation *slideAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
slideAnimation.toValue = [NSNumber numberWithDouble:-100];

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = [NSArray arrayWithObjects:stetchAnimation,slideAnimation,nil];
animationGroup.removedOnCompletion = NO;
animationGroup.fillMode = kCAFillModeForwards;
animationGroup.duration = 0.7;

[someView.layer addAnimation:animationGroup forKey:@"animations"];

关于iphone - 同时调整 UIView 的大小和移动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2460313/

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