Launch diagram _ios for IOS to achieve video animation effects

Source: Internet
Author: User

First on the effect chart

Realize the idea

The main idea is to use a controller to play the video carrier, and then let the controller as a root view, after the video playback is done then what to do.

If you don't say more, let's put the code right here.

First create a new controller AnimationViewController in the controller to create a new attribute moviePlayer , remember to first introduce system library<MediaPlayer/MediaPlayer.h>

@property (nonatomic, strong) MPMoviePlayerController *movieplayer;

Setting moviePlayer I was set directly in lazy loading

-(MPMoviePlayerController *) movieplayer{
  if (!_movieplayer) {
    _movieplayer = [[MPMoviePlayerController alloc ]init];
    [_movieplayer.view setFrame:self.view.bounds];
    Set AutoPlay
    [_movieplayer setshouldautoplay:no];
    Set source type because the new feature is generally playing local small video, set the source type to file
    _movieplayer.moviesourcetype = mpmoviesourcetypefile;
    Cancel control view such as: Play pause etc
    _movieplayer.controlstyle = mpmoviecontrolstylenone;
    [Self.view Addsubview:_movieplayer.view];
    Listener playback Complete
    [[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (playfinsihed) Name: Mpmovieplayerplaybackdidfinishnotification Object:nil];
  }
  return _movieplayer;
}

The .h path to the video is then exposed in, and moviePath an end playback is blockplayFinished required.

AnimationViewControllerIn the same way, after all, there is nothing, and then we go to AppDelegate declare a AnimationViewController property

-(Animationviewcontroller *) animationviewcontroller{
  if (!_animationviewcontroller) {
    _ Animationviewcontroller = [[Animationviewcontroller alloc]init];
    Set local video path
    _animationviewcontroller.moviepath = [[NSBundle mainbundle] pathforresource:@ "V" oftype:@ "mp4"];
    _animationviewcontroller.playfinished = ^{
      Uinavigationcontroller *rootnav = [[Uinavigationcontroller alloc] Initwithrootviewcontroller:[[viewcontroller alloc] init];
      [UIApplication Sharedapplication].keywindow.rootviewcontroller = Rootnav;}
    ;
  }
  return _animationviewcontroller;
}

And then in AppDelegate the startup method to set this controller as the root view

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
  Self.window = [[UIWindow alloc]initwithframe:[uiscreen mainscreen].bounds];
  Self.window.rootViewController = Self.animationviewcontroller;
  [Self.window makekeyandvisible];
  Return YES
}

Summarize

Here to say, at first I use this path but has been empty, and then I added a name for the resource folder put the MP4 into the good, the above is the entire content of this article, the need for friends can refer to reference.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.