YH_EndViewController.m
3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// 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;
frame.origin.y = 170;
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