gpt4 book ai didi

iphone - 如何在单个动画中缩放和旋转 View

转载 作者:可可西里 更新时间:2023-11-01 06:16:51 28 4
gpt4 key购买 nike

我试图通过使 View 从屏幕中心出现,同时增长到全尺寸来呈现 View ,同时还以 3D 方式围绕 x 轴旋转它。当我创建 View 时,我对其应用变换以确保它被缩小和旋转以开始(它太小以至于实际上不可见),然后我尝试使用这样的 CATransform3D:

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0, 0);
transform = CATransform3DScale(transform, 1000, 1000, 1000);
transform.m34 = 1.0 / 10000;
[anim setToValue:[NSValue valueWithCATransform3D:transform]];
[anim setDuration:0.75f];
anim.removedOnCompletion = NO;
anim.delegate = self;
[view.layer addAnimation:anim forKey:@"grow"];

但是这个动画并没有改变图层的实际变换,所以我也这样做了:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
view.layer.transform = CATransform3DIdentity;
[view.layer removeAllAnimations];
}

在动画停止后设置变换。然而,这有时会导致动画结束时出现明显的闪烁。我相信这是因为动画将原始变换放回动画阶段的末尾,并且这会在调用 animationDidStop 例程之前瞬间发生。有更好的方法吗?

编辑:将它合并到 UIView 动画中,这样您就可以直接设置变换:

view.layer.transform = CATransform3DScale(CATransform3DIdentity, 0.001, 0.001, 0.001);
view.layer.transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0.0, 0.0);

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
CATransform3D transform = CATransform3DRotate(view.layer.transform, M_PI, 1.0, 0, 0);
transform = CATransform3DScale(rotationTransform, 1000, 1000, 1000);
transform.m34 = 1.0 / -500;
view.layer.transform = transform;
[UIView commitAnimations];

但是,关于如何使用 CAAnimation 成功地实现同样的目的,我仍然想要回答我最初的问题,因为它通常为动画提供了更大的灵 active 。

Edit2:我原来的问题(如何解决 CAAnimation 的问题)的答案似乎非常简单。为了保持结束状态(并消除闪烁),我只需要添加以下行:

anim.fillMode = kCAFillModeForwards;

最佳答案

这可能对您有帮助:

  animationView.layer.anchorPoint = CGPointMake(0.0f, 0.0f);

animationView.center = CGPointMake(0,
(animationView.center.y -
(animationView.bounds.size.height/2.0f)));

// start the Page Open
[UIView beginAnimations:@"Animation" context:nil];
[UIView setAnimationDuration:2.0];
// set angle as per requirement
[animationView.layer setValue:[NSNumber numberWithInt:180]
forKeyPath:@"transform.rotation.x"];

[UIView commitAnimations];

关于iphone - 如何在单个动画中缩放和旋转 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9341332/

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