效果图
使用视频当做背景.gif介绍
背景图使用视频循环播放而不是使用gif图片, 这里使用MPMoviePlayerController进行无缝循环
具体代码
#import "LTLoginViewController.h"
@interface LTLoginViewController ()
/** url */
@property (nonatomic, strong) NSURL *url;
/** 视频播放器 */
@property (nonatomic, strong) MPMoviePlayerController *player;
@end
@implementation LTLoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setupVideoPlayer];
}
/**
设置视频播放
*/
- (void)setupVideoPlayer
{
// 创建url
self.url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"qidong" ofType:@"mp4"]];
// 创建播放器
self.player = [[MPMoviePlayerController alloc] initWithContentURL:self.url];
// 添加到根视图
[self.view addSubview:self.player.view];
// 应该自动播放
self.player.shouldAutoplay = YES;
// 播放控制 : 不控制
[self.player setControlStyle:(MPMovieControlStyleNone)];
// 循环播放
self.player.repeatMode = MPMovieRepeatModeOne;
// 大小
[self.player.view setFrame:self.view.bounds];
// 缩放模式, 宽度或高度最小的那个等于屏幕宽或高
self.player.scalingMode = MPMovieScalingModeAspectFill;
// 透明
self.player.view.alpha = 0;
[UIView animateWithDuration:3 animations:^{
self.player.view.alpha = 1;
[self.player prepareToPlay];
}];
// 设置登录View
[self setupLoginView];
}
/**
设置登录View
*/
- (void)setupLoginView
{
//进入按钮
UIButton *enterButton = [[UIButton alloc] init];
enterButton.frame = CGRectMake(24, [UIScreen mainScreen].bounds.size.height - 32 - 80, [UIScreen mainScreen].bounds.size.width - 48, 48);
enterButton.layer.borderWidth = 1;
enterButton.layer.cornerRadius = 24;
enterButton.layer.borderColor = [UIColor whiteColor].CGColor;
[enterButton setTitle:@"进入应用" forState:UIControlStateNormal];
enterButton.alpha = 0;
[self.player.view addSubview:enterButton];
[enterButton addTarget:self action:@selector(enterButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[UIView animateWithDuration:3.0 animations:^{
enterButton.alpha = 1.0;
}];
}
/**
进入应用按钮点击事件
*/
- (void)enterButtonClick:(UIButton *)sender
{
NSLog(@"进入应用处理事件");
}
@end
网友评论