YH_EndViewController.m 3.64 KB
//
//  YH_EndViewController.m
//  YohoLive
//
//  Created by 盖剑秋 on 16/8/31.
//  Copyright © 2016年 YOHO!. All rights reserved.
//

#import "YH_EndViewController.h"

@interface YH_EndViewController()

- (void)setRoomSecret:(NSString *)secret;

@end

@implementation YH_EndViewController
{
    void (^completionBlock)(NSDictionary *dic, BOOL success);
    UITextField *textField;
    UIButton *endButton;
    UILabel *secretLabel;
}

+ (void)showInController:(UIViewController *)aController secret:(NSString *)secret completionBlock:(void (^)(NSDictionary *, BOOL))block {
    YH_EndViewController *ctrler = [YH_EndViewController new];
    [ctrler setCompletionBlock:block];
    [aController.view addSubview:ctrler.view];
    [ctrler setRoomSecret:secret];
    [aController addChildViewController:ctrler];
}

- (instancetype)init {
    if (self = [super init]) {
    }
    return self;
}

- (void)setRoomSecret:(NSString *)secret {
    secretLabel.text = secret;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
    UIView *bg = [UIView new];
    [self.view addSubview:bg];
    bg.frame = CGRectMake(0, 0, 280, 250);
    bg.center = self.view.center;
    bg.backgroundColor = [UIColor whiteColor];
    CGRect frame = bg.frame;
    CGFloat  bgHeight = 170;
    if ([[UIScreen mainScreen] bounds].size.height < 667) {
        bgHeight = 100;
    }
    frame.origin.y = bgHeight;
    bg.frame = frame;
    bg.userInteractionEnabled = YES;
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 280, 19)];
    titleLabel.font = [UIFont systemFontOfSize:18];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"房间秘钥";
    [bg addSubview:titleLabel];

    secretLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(titleLabel.frame)+24, 250, 40)];
    secretLabel.font = [UIFont systemFontOfSize:14];
    secretLabel.textAlignment = NSTextAlignmentCenter;
    [bg addSubview:secretLabel];
    
    endButton = [UIButton buttonWithType:UIButtonTypeCustom];
    endButton.frame = CGRectMake(15, CGRectGetMaxY(secretLabel.frame)+ 40, 250, 40);
    endButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [endButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    endButton.backgroundColor = [UIColor blackColor];
    [bg addSubview:endButton];
    [endButton addTarget:self action:@selector(endButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [endButton setTitle:@"结束直播" forState:UIControlStateNormal];
    
    UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    closeButton.frame = CGRectMake(280-18-8, 8, 18, 18);
    [closeButton setImage:[UIImage imageNamed:@"home_btn_close"] forState:UIControlStateNormal];
    [bg addSubview:closeButton];
    [closeButton addTarget:self action:@selector(closeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
}

- (void)endButtonPressed {
    if (completionBlock) {
        completionBlock(nil,YES);
    }
    [self closeButtonPressed];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [UIView animateWithDuration:0.3 animations:^{
        self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    } completion:^(BOOL finished) {
        
    }];
}

- (void)closeButtonPressed {
    [UIView animateWithDuration:0.3 animations:^{
        self.view.alpha = 0;
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
    }];
}

- (void)setCompletionBlock:(void (^)(NSDictionary *, BOOL))block {
    completionBlock = [block copy];
}

@end