YH_RoomSecretViewController.m
4.94 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// YH_RoomSecretViewController.m
// YohoLive
//
// Created by 盖剑秋 on 16/8/29.
// Copyright © 2016年 YOHO!. All rights reserved.
//
#import "YH_RoomSecretViewController.h"
#import "YH_NetworkAdapter+Live.h"
#import "YH_Tool.h"
@interface YH_RoomSecretViewController()
@end
@implementation YH_RoomSecretViewController
{
void (^completionBlock)(NSDictionary *dic, BOOL success);
UITextField *textField;
UIButton *startButton;
}
+ (void)showInController:(UIViewController *)aController completionBlock:(void (^)(NSDictionary *, BOOL))block {
YH_RoomSecretViewController *ctrler = [YH_RoomSecretViewController new];
[ctrler setCompletionBlock:block];
[aController.view addSubview:ctrler.view];
[aController addChildViewController:ctrler];
}
- (instancetype)init {
if (self = [super init]) {
}
return self;
}
- (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];
UIView *secretBg = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(titleLabel.frame)+44, 250, 40)];
secretBg.backgroundColor = [UIColor groupTableViewBackgroundColor];
[bg addSubview:secretBg];
UIImageView *keyImage = [[UIImageView alloc] initWithFrame:CGRectMake(8, 12, 15, 16)];
keyImage.image = [UIImage imageNamed:@"home_icon_roomkey"];
[secretBg addSubview:keyImage];
UIView *bar = [[UIView alloc] initWithFrame:CGRectMake(31, 12, 0.5, 16)];
bar.backgroundColor = [UIColor lightGrayColor];
[secretBg addSubview:bar];
textField = [[UITextField alloc] initWithFrame:CGRectMake(35, 0, 210, 40)];
textField.font = [UIFont systemFontOfSize:14];
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.keyboardAppearance = UIKeyboardAppearanceDark;
[secretBg addSubview:textField];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
startButton = [UIButton buttonWithType:UIButtonTypeCustom];
startButton.frame = CGRectMake(15, CGRectGetMaxY(secretBg.frame)+20, 250, 40);
startButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
[startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
startButton.backgroundColor = [UIColor lightGrayColor];
[bg addSubview:startButton];
[startButton addTarget:self action:@selector(startButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[startButton 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)textDidChange:(NSNotification *)sender {
UITextField *txtFild = sender.object;
if (txtFild.text.length) {
startButton.backgroundColor = [UIColor blackColor];
}else {
startButton.backgroundColor = [UIColor lightGrayColor];
}
}
- (void)startButtonPressed {
if (!textField.text.length) {
return;
}
[[YH_NetworkAdapter adapter] getRoomWithSecret:textField.text completion:^(NSMutableDictionary *infoDict, NSError *error) {
if (error) {
[YH_Tool alertMessage:@"密码无效,请重输"];
textField.text = @"";
} else {
if (completionBlock) {
completionBlock(infoDict, 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