1

Is it possible to apply animation effect for the iOS launching scene since gif is not accepted?

nhgrif
  • 61,578
  • 25
  • 134
  • 173
James
  • 1,071
  • 1
  • 11
  • 16

3 Answers3

3

No. The launch scene is either an image or a LaunchScreen.xib. Both are static.

You can however present a gif similar to the launch image in your actual application which will animate if the application has finished loading.

If you use a launch image, create a UIImageView on top of all the other content in the initial viewController. Then you animate that image view. Same goes for the LaunchScreen.xib, rebuild the LaunchScreen.xib setup as the initial view controller and then build some custom animation upon that.

luk2302
  • 55,258
  • 23
  • 97
  • 137
2

Launch images are static, you configure them with xcode and you can't change them. But in a splash screen you can do whatever you like, it's just a viewController where you show an animation, a video, or any other thing. You show the splash screen after the launch image and before your "landing page". Then, in a splash screen you can create an animation frame by frame, or load a .mp4 video in a MPMoviePlayerController . thanks

Nitin
  • 451
  • 5
  • 17
0

I have one possible solution for you:

  1. Set the splash screen image as first frame on your gif animation
  2. On your appDelegate create method for displaying video, for example. NOTE: add splash screen image to window frame until video is prepared to play. so declare two properties
@property (nonatomic, strong) MPMoviePlayerController *playerCtrl;

@property (nonatomic, strong) UIImageView *previewImage;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self setupMovie];
    }

    -(void)setupMovie
    {
        NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"type_of_video"];
        NSURL *movieURL = [NSURL fileURLWithPath:moviePath];

        self.playerCtrl =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
        self.playerCtrl.scalingMode = MPMovieScalingModeAspectFill;
        self.playerCtrl.controlStyle = MPMovieControlStyleNone;
        self.playerCtrl.view.frame = self.window.frame;

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlayBackDidFinish:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification  object:nil];

        [self.window addSubview:self.playerCtrl.view];
        [self.playerCtrl prepareToPlay];

        self.previewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SplashScreen"]];
        self.previewImage.frame = self.window.frame;
        self.previewImage.contentMode = UIViewContentModeScaleAspectFill;
        [self.window addSubview:self.previewImage];


    }

    - (void)moviePlayBackDidFinish:(MPMoviePlayerController *)player
    {
        [self stopPlayingVideo];
    }

    - (void)moviePlayerPlaybackStateDidChange:(NSNotification*)notification
    {
        if (self.playerCtrl.isPreparedToPlay) {
            [self.previewImage removeFromSuperview];
            [self.playerCtrl play];
        }
    }

    - (void)stopPlayingVideo
    {
        @weakify(self)
        [UIView animateWithDuration:2.3 animations:^(void) {
            @strongify(self)
            [self.playerCtrl.view setAlpha:0.0];
        } completion:^(BOOL finished) {
            @strongify(self)
            [self.playerCtrl.view removeFromSuperview];

        }];

    }

the second solution, if you want to make all animation in code:

  1. Set the splash screen image as first frame on your gif animation 2.Create view controller with all needed animation and present it modally from your first viewcontroller in navigation hierarchy (if you do not want modal controller init your navigation controller with this vc as root) - this could be helpful when you use tabbar as root controller
  2. Show all your animation
  3. Simply dissmis controller after all stub was done
Avijit Nagare
  • 8,482
  • 7
  • 39
  • 68
Doro
  • 2,413
  • 2
  • 14
  • 26