Most effective method for video as background in iOS

前端 未结 5 1658
不知归路
不知归路 2020-12-24 03:30

Perhaps you have noticed one of the latest trend in iOS-apps: Using videos as backgrounds - mainly at login- or \"first launch\" screens. Yesterday I attempted to mimic this

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 03:46

    I found this code on GitHub that worked for me in iOS8/9

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        // Load the video from the app bundle.
        NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"video" withExtension:@"mov"];
    
        // Create and configure the movie player.
        self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    
        self.moviePlayer.controlStyle = MPMovieControlStyleNone;
        self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    
        self.moviePlayer.view.frame = self.view.frame;
        [self.view insertSubview:self.moviePlayer.view atIndex:0];
    
        [self.moviePlayer play];
    
        // Loop video.
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loopVideo) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
    }
    
    - (void)loopVideo {
        [self.moviePlayer play];
    }
    

提交回复
热议问题