gpt4 book ai didi

ios - 带有关键帧的动画出错

转载 作者:行者123 更新时间:2023-11-29 03:07:33 25 4
gpt4 key购买 nike

我正在玩一些动画。

我有一个 UIlabel,我想在单击按钮后从左侧“飞”到中心。标签的初始字符串将位于中心。

我得到的是标签在 3 秒内移动到“原点”,然后在该位置“弹出”。

我希望 UILabel 在这 3 秒内顺利地“滑动”/动画到目标点。 alpha 属性似乎也不能使动画流畅。希望我说清楚了。谢谢。

    - (IBAction)showQuestionButtonPressed:(UIButton *)sender
{
// Step to the next question
self.currentQuestionIndex++;

// Am I pas the last question?
if (self.currentQuestionIndex == [self.questions count]) {

// Go back to the first question
self.currentQuestionIndex = 0;
}

// Get the string at the index in the questions array
NSString *question = self.questions[self.currentQuestionIndex];

// Display the string in the question label
self.questionLabel.text = question;

// Reset the answer label
self.answerLabel.text = @"???";
self.questionLabel.alpha = 1.0;
// the animation animated a little bit after this point:
CGPoint origin = CGPointMake(0 - (self.questionLabel.frame.size.width/2.0), self.questionLabel.frame.origin.y);
self.questionLabel.center = origin;


[UIView animateKeyframesWithDuration:3.0 delay:0.0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:3.0 animations:^{
self.questionLabel.alpha = 1.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:3.0 animations:^{
self.questionLabel.center = CGPointMake(self.view.center.x, self.questionLabel.frame.origin.y) ;
}];
} completion:^(BOOL finished) {
NSLog(@"finished animation");
}];
}

最佳答案

relativeDuration 应该是 0 到 1 之间的数字。来自文档:

The length of time over which to animate to the specified value. This value must be in the range 0 to 1 and indicates the amount of time relative to the overall animation length. If you specify a value of 0, any properties you set in the animations block update immediately at the specified start time. If you specify a nonzero value, the properties animate over that amount of time. For example, for an animation that is two seconds in duration, specifying a duration of 0.5 results in an animation duration of one second.

此外,如果您使用自动布局,则不能简单地设置标签的 center 属性。你必须调整你的约束。

关于ios - 带有关键帧的动画出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22594638/

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