sách gpt4 ai đã đi

Lật UILabel - Stack Overflow

In lại 作者:塔克拉玛干 更新时间:2023-11-02 20:09:32 31 4
mua khóa gpt4 Nike

我想使用 CABasicAnimation 翻转 UILabel。动画将永远重复,并将在两个不同值之间更改 UILabel 的文本。

- (void)animateLabel
{
[self.myLabel.layer addAdnimation:[self labelAnimation] forKey:@"flip"];
}

- (CAAnimation*)labelAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
[animation setRepeatCount:NSIntegerMax];
[animation setAutoreverses:YES];
[animation setDuration:2.0];
[animation setDelegate:self];
CATransform3D transform = CATransform3DMakeRotation(M_PI_2, 1, 0, 0);
[animation setToValue:[NSValue valueWithCATransform3D:transform]];
return animation;
}

现在,我尝试使用委托(delegate),但委托(delegate)方法仅在动画首次开始时有效。相反,我需要能够知道标签完成一个周期。有没有一些方便的方法或方式来使用 CALayer 或我必须使用 CADisplay 链接或计时器?在此先感谢您对我的帮助。

1 Câu trả lời

要在每个周期都收到通知,请将 RepeatsCount 设置为 1。然后您将在委托(delegate) animationDidStop:finished 中收到通知。然后您只需再次添加相同的动画。

 - (void)animateLabel
{
[self.myLabel.layer addAdnimation:[self labelAnimation] forKey:@"flip"];
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
[self animateLabel];
// do other stuff
}

- (CAAnimation*)labelAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
[animation setRepeatCount:1];
[animation setAutoreverses:YES];
[animation setDuration:2.0];
[animation setDelegate:self];
CATransform3D transform = CATransform3DMakeRotation(M_PI_2, 1, 0, 0);
[animation setToValue:[NSValue valueWithCATransform3D:transform]];
return animation;
}

关于ios - 翻转 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20045805/

31 4 0
Bài viết được đề xuất: iOS bundle 大小增加了添加的启动图像大小的两倍
Bài viết được đề xuất: java - 如何忽略Web服务中的空参数?
Bài viết được đề xuất: java - 用子类替换 Spring Bean 时出错
Bài viết được đề xuất: ios - GTMNSString+HTML 在结构中使用对象
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com