gpt4 book ai didi

ios - CABasicAnimation 一直不工作

转载 作者:行者123 更新时间:2023-11-29 12:16:02 25 4
gpt4 key购买 nike

我有以下代码,应该提供 View “摇晃”的效果,然后通过向上滑出屏幕来消除它。

有时完美呈现,但大多数时候摇动动画不会显示, View 只是向上滑动。我无法弄清楚问题可能是什么:

CABasicAnimation *animation =
[CABasicAnimation animationWithKeyPath:@"position"];
[animation setDuration:0.05];
[animation setRepeatCount:8];
[animation setAutoreverses:YES];
[animation setFromValue:[NSValue valueWithCGPoint:
CGPointMake([[self editView] center].x - 20.0f, [[self editView] center].y)]];
[animation setToValue:[NSValue valueWithCGPoint:
CGPointMake([[self editView] center].x + 20.0f, [[self editView] center].y)]];
[[[self editView] layer] addAnimation:animation forKey:@"position"];

[CATransaction begin]; {
[CATransaction setCompletionBlock:^{


[UIView animateWithDuration:0.4f delay:0.7 options:UIViewAnimationOptionTransitionNone animations:^{

_editView.center = CGPointMake(self.navigationController.view.bounds.size.width / 2, 0 - 380);
[_textView resignFirstResponder];

[_tint setAlpha:0];


} completion:^(BOOL finished) {

[_editView removeFromSuperview];
[_tint removeFromSuperview];
}];

}];

} [CATransaction commit];

最佳答案

您唯一需要做的改变是重新放置:

[[[self editView] layer] addAnimation:animation forKey:@"position"];

[CATransaction commit]; 的正上方。

这样,就变成了:

[CATransaction begin];
{
[CATransaction setCompletionBlock:^
{
[UIView animateWithDuration:0.4f delay:0.7f options:UIViewAnimationOptionTransitionNone animations:^
{
_editView.center = CGPointMake(self.navigationController.view.bounds.size.width / 2.0f, -380.0f);
[_textView resignFirstResponder];
[_tint setAlpha:0];
}
completion:^(BOOL finished)
{
[_editView removeFromSuperview];
[_tint removeFromSuperview];
}];
}];
}
[[[self editView] layer] addAnimation:animation forKey:@"position"];
[CATransaction commit];

然后,摇晃部分将首先发生,然后才开始按照您的意愿向上动画。

关于ios - CABasicAnimation 一直不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31979729/

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