我有一个客户想要一个常规的图片启动屏幕,然后是一个视频启动屏幕,然后进入应用程序本身。他从他看到的另一个应用程序中得到了这个想法。我在下面的链接中记录了该应用程序的介绍及其。
它有一个图片启动屏幕,然后是一个没有控件且没有用户与视频交互的视频,完成后关闭视频并进入应用程序本身。
http://www.jportdev.com/MISC/Sample.mov
图像启动画面我没有问题,但在完成后加载视频是我遇到问题的地方。
我作为 POC 这样做,然后在实际的应用程序中实现它。我认为所有这些都必须在 appDelegate 中完成......所以这就是我到目前为止所拥有的。
#import "AppDelegate.h"
#import <MediaPlayer/MediaPlayer.h>
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
//original code generated by xcode
//self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//self.window.rootViewController = self.viewController;
[self showIntro];
return YES;
}
-(void)showIntro{
UIImage *splashImage = [UIImage imageNamed:@"splash.jpg"];
UIImageView *splashImageView = [[UIImageView alloc] initWithImage:splashImage];
splashImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.window.rootViewController.view addSubview:splashImageView];
[self.window.rootViewController.view bringSubviewToFront:splashImageView];
[UIView animateWithDuration:1.5f
delay:2.0f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
splashImageView.alpha = .0f;
CGFloat x = -60.0f;
CGFloat y = -120.0f;
splashImageView.frame = CGRectMake(x,
y,
splashImageView.frame.size.width-2*x,
splashImageView.frame.size.height-2*y);
} completion:^(BOOL finished){
if (finished) {
[splashImageView removeFromSuperview];
//calling the movie after dismissing image splash
[self showMovieIntro];
}
}];
}
-(void)showMovieIntro{
MPMoviePlayerViewController *playerVC=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Test" ofType:@"mp4"]]];
MPMoviePlayerController *player = [playerVC moviePlayer];
player.controlStyle = MPMovieControlStyleNone; //hide the controls
//this doesnt work, returns a erros passing mpmovieplayerVC as oppose to a uiview
//[self presentModalViewController:playerViewController animated:YES];
//[self.window.rootViewController.view addSubview:playerVC];
//[self.window.rootViewController.view bringSubviewToFront:playerVC.view];
//this part right here makes the app crash
[[playerVC view] setFrame:_window.bounds];
[_window addSubview: [playerVC view]];
[_window bringSubviewToFront:[playerVC view]];
[player play];
//try using animation with duration on the movie but that was a no no...
// [UIView animateWithDuration:1.5f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:nil completion:^(BOOL finished) {
// if(finished){
// [playerVC removeFromSuperView];
// }
// }];
}