仿Uber注册页背景视屏效果

来源:互联网 发布:淘宝别人盗用我的品牌 编辑:程序博客网 时间:2024/06/07 02:51
//  Created by qpc on 15/12/24.
//  Copyright © 2015年 qpc. All rights reserved.
//


#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>

#define  screenW  [UIScreen mainScreen].bounds.size.width
#define  screenH  [UIScreen mainScreen].bounds.size.height
#define  btnW      ((screenW - 3 * 20)/2)

@interface ViewController ()

//播放器视图控制器
@property (nonatomic,strong) MPMoviePlayerViewController *moviePlayerViewController;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self playMovie];

    //延时操作,保证视屏和文字同时启动
    dispatch_after(1.3, dispatch_get_main_queue(), ^{
    [self setupTitleLabel];
    
    [self setupButton];
});

}


//创建视频控制器
- (void) playMovie
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"8" ofType:@"mp4"];
    self.moviePlayerViewController = [[MPMoviePlayerViewController alloc]
                                      initWithContentURL:[NSURL fileURLWithPath:path]];
    self.moviePlayerViewController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
    self.moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
    self.moviePlayerViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    
    //    self.moviePlayerViewController.moviePlayer.fullscreen = NO;
    //    //在当前view上添加视频的视图
    [self.view addSubview:self.moviePlayerViewController.view];
    NSLog(@"-------");
    
}


//创建主题文字,可优化

- (void)setupTitleLabel
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(screenW * 0.5 -50, screenH * 0.5 - 100, 120, 40)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text = @"我是测试数据";
    titleLabel.font = [UIFont systemFontOfSize:30.0];
    titleLabel.textColor = [UIColor whiteColor];
    [self.moviePlayerViewController.view addSubview:titleLabel];
     
    float detailY = CGRectGetMaxY(titleLabel.frame);
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(screenW * 0.5 -90, detailY - 10, 200, 40)];
    detailLabel.backgroundColor = [UIColor clearColor];
    detailLabel.textAlignment = NSTextAlignmentLeft;
    detailLabel.text = @"程序猿帅气";
    detailLabel.font = [UIFont systemFontOfSize:20.0];
    detailLabel.textColor = [UIColor grayColor];
    [self.moviePlayerViewController.view addSubview:detailLabel];
    
}

//创建登陆和注册按钮
- (void)setupButton
{
    [self createBtnWithFrame:CGRectMake(20, screenH - 20 - 40 , btnW, 40) backColor:[UIColor colorWithRed:209/255.0 green:210/255.0 blue:211/255.0 alpha:1.0] title:@"登录" titleColor:[UIColor blackColor]  action:@selector(login)];

    [self createBtnWithFrame:CGRectMake(btnW + 40, screenH - 20 - 40 , btnW, 40) backColor:[UIColor colorWithRed:57/255.0 green:185/255.0 blue:186/255.0 alpha:1.0] title:@"注册" titleColor:[UIColor whiteColor] action:@selector(regist)];
    
}

- (void)createBtnWithFrame:(CGRect)frame backColor:(UIColor *)backcolor title:(NSString *)title titleColor:(UIColor *)titleColor action:(SEL)action
{
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    btn.layer.cornerRadius = 5;
    btn.layer.masksToBounds = YES;
    btn.backgroundColor = backcolor;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    [_moviePlayerViewController.view addSubview:btn];
}


- (void)login
{
    NSLog(@"login");
    UIViewController *loginVC = [[UIViewController alloc] init];
    loginVC.view.backgroundColor = [UIColor whiteColor];
    [self presentViewController:loginVC animated:YES completion:nil];
}


- (void)regist
{
    NSLog(@"regist");
    UIViewController *registVC = [[UIViewController alloc] init];
    registVC.view.backgroundColor = [UIColor whiteColor];
    [self presentViewController:registVC animated:YES completion:nil];
}

@end



效果图:

0 0
原创粉丝点击