gpt4 book ai didi

ios - UIImageView 的动画在真实的 iOS 设备上效果不佳

转载 作者:行者123 更新时间:2023-11-28 22:38:06 24 4
gpt4 key购买 nike

我想在应用程序启动时添加一些动画。在 iPad 模拟器上一切正常。但是当它在真正的 iPad 上运行时,框架会静止一会儿,然后开始动画。在所有帧显示之前,动画完成。这是我的代码

    - (void)viewDidAppear:(BOOL)animated
{
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
[UIImage imageNamed:@"13.png"],
[UIImage imageNamed:@"14.png"],
[UIImage imageNamed:@"15.png"],
[UIImage imageNamed:@"16.png"],
[UIImage imageNamed:@"17.png"],
[UIImage imageNamed:@"18.png"],
[UIImage imageNamed:@"19.png"],
[UIImage imageNamed:@"20.png"],
[UIImage imageNamed:@"21.png"],
[UIImage imageNamed:@"22.png"],
[UIImage imageNamed:@"23.png"],
[UIImage imageNamed:@"24.png"],
[UIImage imageNamed:@"25.png"],
[UIImage imageNamed:@"26.png"],
[UIImage imageNamed:@"27.png"],
[UIImage imageNamed:@"28.png"],
[UIImage imageNamed:@"29.png"],
[UIImage imageNamed:@"30.png"],
[UIImage imageNamed:@"31.png"],
[UIImage imageNamed:@"32.png"],
[UIImage imageNamed:@"33.png"],
[UIImage imageNamed:@"34.png"],
[UIImage imageNamed:@"35.png"],
[UIImage imageNamed:@"36.png"],
[UIImage imageNamed:@"37.png"],
[UIImage imageNamed:@"38.png"],
nil];

//myAnimatedView is UIImageView outlet
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 3;
myAnimatedView.animationRepeatCount = 1;
[myAnimatedView startAnimating];

//trigger animationDone method when animation is finished
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, myAnimatedView.animationDuration * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self animationDone];
});

最佳答案

我认为问题在于您尝试检测动画是否已完成的方式。您的方法不正确,因为它只是基于对动画的估计。

手机的 cpu 功率比使用 Mac CPU 的模拟器少得多,因此它在执行周围的事情时会变慢。因此,当您假设动画已完成加载时,您的动画尚未完成。

此外,我不明白将 Grand Central Dispatch 用作简单计时器的背后逻辑,这基本上就是您正在做的事情。

我会将逻辑更改为一个简单的计时器,我将只检查 UIImageViewisAnimating 值。

所以,摆脱这个:

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, myAnimatedView.animationDuration * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self animationDone];
});

并替换为:

[self performSelector:@selector(checkAnimation) withObject:nil afterDelay:0.1];

这是我们的 checkAnimation 函数:

- (void)checkAnimation {
if (animationView.isAnimating) {
[self performSelector:@selector(checkAnimation) withObject:nil afterDelay:0.1];
}
else {
[self animationDone];
}
}

关于ios - UIImageView 的动画在真实的 iOS 设备上效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15379609/

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