【问题标题】:how to add .gif in splash screen in ios?如何在 ios 的启动画面中添加 .gif?
【发布时间】:2016-07-15 06:28:06
【问题描述】:

是否可以在 iOS 应用中添加 .gif file 作为启动画面? 如何创建动态启动画面?知道如何在启动画面中添加 gif

【问题讨论】:

  • 您可以为此使用 SDImageCache
  • @Birendra SDImageCache 在启动画面中使用动画? :/ 怎么会?
  • [imgViewVid sd_setImageWithURL:[NSURL URLWithString:[arrVideo valueForKey:@"photo_path"]] placeholderImage:[UIImage sd_animatedGIFNamed:@"loading1"]];
  • @Birendra 是的,你打算在启动屏幕的哪里调用该代码?为什么要使用该扩展名?您可以使用 UIImageView 本身启动动画。

标签: ios objective-c iphone


【解决方案1】:

这可以帮助你:

NSMutableArray *images = [[NSMutableArray alloc] init];
NSInteger animationImageCount = 38;
for (int i = 0; i < animationImageCount; i++) {
    // Images are numbered IndexedImagesInMyAnimation0, 1, 2, etc...
    [images addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"IndexedImagesInMyAnimation%d", i]].CGImage];
}

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.calculationMode = kCAAnimationDiscrete;
animation.duration = animationImageCount / 24.0; // 24 frames per second
animation.values = images;
animation.repeatCount = 1;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[self.animationImageView.layer addAnimation:animation forKey:@"animation"];

你也知道单循环动画的repeatCount和duration,你可以很容易地计算出总动画时间:

totalAnimationTime = repeatCount * 持续时间

现在,您可以在计时器中使用此 totalAnimationTime 并切换您的视图控制器。

【讨论】:

  • 我正在尝试相同的代码,但首先显示白色闪屏然后显示动画
  • 我相信你在本地有图片。如果是的话,你可以使用第一张图片作为 UIImageView 中的默认图片。
【解决方案2】:

您必须像闪屏一样查看控制器,它会停留 3-4 秒。无法启动图像 gif。

1) 您可以通过一张一张地播放图像序列来做到这一点。 UIImageView 类中有方法可以播放图像数组。

2) 您可以播放 5 秒的视频。

编辑

NSArray *animationArray=[NSArray arrayWithObjects:
                                      [UIImage imageNamed:@"images.jpg"],
                                          [UIImage imageNamed:@"images1.jpg"],
                                          [UIImage imageNamed:@"images5.jpg"],
                                       [UIImage imageNamed:@"index3.jpg"],
                        nil];
    UIImageView *animationView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
        animationView.backgroundColor=[UIColor purpleColor];
        animationView.animationImages=animationArray;
        animationView.animationDuration=1.5;
    animationView.animationRepeatCount=0;
        [animationView startAnimating]; 
        [self.view addSubview:animationView]; 

【讨论】:

  • 最好的方法是播放 3-4 秒的视频,一旦视频播放完成,移动到下一个视图控制器。所以你必须在你的 rootview 控制器中播放视频。
  • 我尝试相同的代码,但先显示白色闪屏,然后显示动画
  • 你设置了启动图片吗?
  • 是否可以使用 appdelget.m 文件。添加self.window
  • 我没有得到你。你想说什么?
【解决方案3】:

根据苹果的指导方针,不能使用gif 作为启动画面或启动图像。

如果您使用故事板作为启动屏幕(> ios 7),那么您可以使用jpg,但低于或等于 ios 7 的版本,您只能选择png

您可以通过使您的第一个视图控制器动画并使其作为启动屏幕来实现动画类型的启动。在这种情况下,您不应该设置启动屏幕故事板的任何启动图像(或设置黑色背景颜色),因此当应用程序启动时它将显示黑屏一秒钟,然后您的第一个视图控制器将动画化并且您的应用程序将获得启动动画或gif

希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 2018-02-16
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    相关资源
    最近更新 更多