Commit cc5787df0a40231833048a5a99d2be2aeee4fae8

Authored by 雷浩杰
1 parent 3f01bc31

更新Demo UI

CNLiveXMPPManagerDemo/CNLiveXMPPManagerDemo/Base.lproj/Main.storyboard
1 -<?xml version="1.0" encoding="UTF-8" standalone="no"?>  
2 -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> 1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="06n-aH-okM">
  3 + <device id="retina4_7" orientation="portrait">
  4 + <adaptation id="fullscreen"/>
  5 + </device>
3 <dependencies> 6 <dependencies>
4 - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/> 7 + <deployment identifier="iOS"/>
  8 + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
5 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> 9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6 </dependencies> 10 </dependencies>
7 <scenes> 11 <scenes>
8 <!--View Controller--> 12 <!--View Controller-->
9 <scene sceneID="tne-QT-ifu"> 13 <scene sceneID="tne-QT-ifu">
10 <objects> 14 <objects>
11 - <viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController"> 15 + <viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
12 <layoutGuides> 16 <layoutGuides>
13 <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> 17 <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14 <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> 18 <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
@@ -18,9 +22,29 @@ @@ -18,9 +22,29 @@
18 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 22 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> 23 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
20 </view> 24 </view>
  25 + <navigationItem key="navigationItem" id="BWk-fb-LQT"/>
21 </viewController> 26 </viewController>
22 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> 27 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
23 </objects> 28 </objects>
  29 + <point key="canvasLocation" x="964" y="36.431784107946029"/>
  30 + </scene>
  31 + <!--Navigation Controller-->
  32 + <scene sceneID="AHB-iF-bKU">
  33 + <objects>
  34 + <navigationController automaticallyAdjustsScrollViewInsets="NO" id="06n-aH-okM" sceneMemberID="viewController">
  35 + <toolbarItems/>
  36 + <navigationBar key="navigationBar" contentMode="scaleToFill" id="ZOL-0v-2oc">
  37 + <rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
  38 + <autoresizingMask key="autoresizingMask"/>
  39 + </navigationBar>
  40 + <nil name="viewControllers"/>
  41 + <connections>
  42 + <segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="fMx-a7-zk6"/>
  43 + </connections>
  44 + </navigationController>
  45 + <placeholder placeholderIdentifier="IBFirstResponder" id="AKz-aK-FZ7" userLabel="First Responder" sceneMemberID="firstResponder"/>
  46 + </objects>
  47 + <point key="canvasLocation" x="116" y="-646.32683658170924"/>
24 </scene> 48 </scene>
25 </scenes> 49 </scenes>
26 </document> 50 </document>
CNLiveXMPPManagerDemo/CNLiveXMPPManagerDemo/ViewController.m
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 #import <CNLiveXMPPSDK/CNLiveXMPPManager.h> 11 #import <CNLiveXMPPSDK/CNLiveXMPPManager.h>
12 12
13 #define ScreenWidth ([UIScreen mainScreen].bounds.size.width) 13 #define ScreenWidth ([UIScreen mainScreen].bounds.size.width)
  14 +#define ScreenHeight ([UIScreen mainScreen].bounds.size.height)
14 #define ButtonWidth (ScreenWidth / 4) 15 #define ButtonWidth (ScreenWidth / 4)
15 16
16 #define KAppId @"60_irn9cdak77" 17 #define KAppId @"60_irn9cdak77"
@@ -37,7 +38,9 @@ @@ -37,7 +38,9 @@
37 38
38 - (void)viewDidLoad { 39 - (void)viewDidLoad {
39 [super viewDidLoad]; 40 [super viewDidLoad];
40 - self.view.backgroundColor = [UIColor cyanColor]; 41 +
  42 + self.title = @"视讯云 聊天室SDK Demo";
  43 +
41 // Do any additional setup after loading the view, typically from a nib. 44 // Do any additional setup after loading the view, typically from a nib.
42 [self.view addSubview:self.button]; 45 [self.view addSubview:self.button];
43 [self.view addSubview:self.leaveRoomBtn]; 46 [self.view addSubview:self.leaveRoomBtn];
@@ -47,16 +50,24 @@ @@ -47,16 +50,24 @@
47 [self.view addSubview:self.changeNickBtn]; 50 [self.view addSubview:self.changeNickBtn];
48 [self.view addSubview:self.textField]; 51 [self.view addSubview:self.textField];
49 [self.view addSubview:self.textView]; 52 [self.view addSubview:self.textView];
50 - self.nickStr = @"王小帅"; 53 + self.nickStr = @"CNLiveChatTest1";
51 [self.manager joinRoomWithNickName:self.nickStr]; 54 [self.manager joinRoomWithNickName:self.nickStr];
52 55
  56 + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textFieldResignFirstResponder)];
  57 + [self.view addGestureRecognizer:tap];
  58 +
  59 + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight([UIScreen mainScreen].bounds)-40, CGRectGetWidth(self.view.frame), 30)];
  60 + label.text = @"北京中投视讯文化传媒股份有限公司";
  61 + [self.view addSubview:label];
  62 + label.font = [UIFont systemFontOfSize:12];
  63 + label.textAlignment = NSTextAlignmentCenter;
53 } 64 }
54 65
55 - (UITextField *)textField 66 - (UITextField *)textField
56 { 67 {
57 if (!_textField) { 68 if (!_textField) {
58 - _textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 70, ScreenWidth, 30)];  
59 - _textField.backgroundColor = [UIColor redColor]; 69 + _textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 154, ScreenWidth, 40)];
  70 + _textField.borderStyle = UITextBorderStyleLine;
60 } 71 }
61 return _textField; 72 return _textField;
62 } 73 }
@@ -65,12 +76,12 @@ @@ -65,12 +76,12 @@
65 { 76 {
66 if (!_button) { 77 if (!_button) {
67 _button = [UIButton buttonWithType:UIButtonTypeCustom]; 78 _button = [UIButton buttonWithType:UIButtonTypeCustom];
68 - [_button setFrame:CGRectMake(ButtonWidth / 2, 100, ButtonWidth, 30)];  
69 - [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
70 - [_button setBackgroundColor:[UIColor yellowColor]]; 79 + [_button setFrame:CGRectMake(40, 204, 100, 30)];
  80 + [_button setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
71 [_button setTitle:@"发送" forState:UIControlStateNormal]; 81 [_button setTitle:@"发送" forState:UIControlStateNormal];
72 _button.tag = 10001; 82 _button.tag = 10001;
73 [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 83 [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  84 + [self setButtonBorder:_button];
74 } 85 }
75 return _button; 86 return _button;
76 } 87 }
@@ -79,11 +90,12 @@ @@ -79,11 +90,12 @@
79 { 90 {
80 if (!_changeNickBtn) { 91 if (!_changeNickBtn) {
81 _changeNickBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 92 _changeNickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
82 - [_changeNickBtn setFrame:CGRectMake(ButtonWidth * 2.5, 100, ButtonWidth, 30)]; 93 + [_changeNickBtn setFrame:CGRectMake(ScreenWidth-140, 204, 100, 30)];
83 [_changeNickBtn setTitle:@"更改昵称" forState:UIControlStateNormal]; 94 [_changeNickBtn setTitle:@"更改昵称" forState:UIControlStateNormal];
84 - [_changeNickBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 95 + [_changeNickBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
85 _changeNickBtn.tag = 10002; 96 _changeNickBtn.tag = 10002;
86 [_changeNickBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 97 [_changeNickBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  98 + [self setButtonBorder:_changeNickBtn];
87 } 99 }
88 return _changeNickBtn; 100 return _changeNickBtn;
89 } 101 }
@@ -92,12 +104,13 @@ @@ -92,12 +104,13 @@
92 { 104 {
93 if (!_leaveRoomBtn) { 105 if (!_leaveRoomBtn) {
94 _leaveRoomBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 106 _leaveRoomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
95 - [_leaveRoomBtn setFrame:CGRectMake(ButtonWidth * 2, 40, ButtonWidth, 30)]; 107 + [_leaveRoomBtn setFrame:CGRectMake(ScreenWidth-150, 74, 120, 30)];
96 [_leaveRoomBtn setTitle:@"离开聊天室" forState:UIControlStateNormal]; 108 [_leaveRoomBtn setTitle:@"离开聊天室" forState:UIControlStateNormal];
97 - [_leaveRoomBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 109 + [_leaveRoomBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
98 [_leaveRoomBtn.titleLabel setAdjustsFontSizeToFitWidth:YES]; 110 [_leaveRoomBtn.titleLabel setAdjustsFontSizeToFitWidth:YES];
99 _leaveRoomBtn.tag = 10003; 111 _leaveRoomBtn.tag = 10003;
100 [_leaveRoomBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 112 [_leaveRoomBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  113 + [self setButtonBorder:_leaveRoomBtn];
101 } 114 }
102 return _leaveRoomBtn; 115 return _leaveRoomBtn;
103 } 116 }
@@ -106,12 +119,13 @@ @@ -106,12 +119,13 @@
106 { 119 {
107 if (!_disconnectXmppBtn) { 120 if (!_disconnectXmppBtn) {
108 _disconnectXmppBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 121 _disconnectXmppBtn = [UIButton buttonWithType:UIButtonTypeCustom];
109 - [_disconnectXmppBtn setFrame:CGRectMake(0, 40, ButtonWidth, 30)]; 122 + [_disconnectXmppBtn setFrame:CGRectMake(30, 74, 120, 30)];
110 [_disconnectXmppBtn setTitle:@"断开XMPP" forState:UIControlStateNormal]; 123 [_disconnectXmppBtn setTitle:@"断开XMPP" forState:UIControlStateNormal];
111 - [_disconnectXmppBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 124 + [_disconnectXmppBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
112 [_disconnectXmppBtn.titleLabel setAdjustsFontSizeToFitWidth:YES]; 125 [_disconnectXmppBtn.titleLabel setAdjustsFontSizeToFitWidth:YES];
113 _disconnectXmppBtn.tag = 10004; 126 _disconnectXmppBtn.tag = 10004;
114 [_disconnectXmppBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 127 [_disconnectXmppBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  128 + [self setButtonBorder:_disconnectXmppBtn];
115 } 129 }
116 return _disconnectXmppBtn; 130 return _disconnectXmppBtn;
117 } 131 }
@@ -120,12 +134,13 @@ @@ -120,12 +134,13 @@
120 { 134 {
121 if (!_reconnectBtn) { 135 if (!_reconnectBtn) {
122 _reconnectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 136 _reconnectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
123 - [_reconnectBtn setFrame:CGRectMake(ButtonWidth, 40, ButtonWidth, 30)]; 137 + [_reconnectBtn setFrame:CGRectMake(30, 114, 120, 30)];
124 [_reconnectBtn setTitle:@"重连XMPP" forState:UIControlStateNormal]; 138 [_reconnectBtn setTitle:@"重连XMPP" forState:UIControlStateNormal];
125 - [_reconnectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 139 + [_reconnectBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
126 [_reconnectBtn.titleLabel setAdjustsFontSizeToFitWidth:YES]; 140 [_reconnectBtn.titleLabel setAdjustsFontSizeToFitWidth:YES];
127 _reconnectBtn.tag = 10005; 141 _reconnectBtn.tag = 10005;
128 [_reconnectBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 142 [_reconnectBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  143 + [self setButtonBorder:_reconnectBtn];
129 } 144 }
130 return _reconnectBtn; 145 return _reconnectBtn;
131 } 146 }
@@ -134,22 +149,32 @@ @@ -134,22 +149,32 @@
134 { 149 {
135 if (!_rejoinChatroomBtn) { 150 if (!_rejoinChatroomBtn) {
136 _rejoinChatroomBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 151 _rejoinChatroomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
137 - [_rejoinChatroomBtn setFrame:CGRectMake(ButtonWidth * 3, 40, ButtonWidth, 30)]; 152 + [_rejoinChatroomBtn setFrame:CGRectMake(ScreenWidth-150, 114, 120, 30)];
138 [_rejoinChatroomBtn setTitle:@"重连聊天室" forState:UIControlStateNormal]; 153 [_rejoinChatroomBtn setTitle:@"重连聊天室" forState:UIControlStateNormal];
139 - [_rejoinChatroomBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 154 + [_rejoinChatroomBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
140 [_rejoinChatroomBtn.titleLabel setAdjustsFontSizeToFitWidth:YES]; 155 [_rejoinChatroomBtn.titleLabel setAdjustsFontSizeToFitWidth:YES];
141 _rejoinChatroomBtn.tag = 10006; 156 _rejoinChatroomBtn.tag = 10006;
142 [_rejoinChatroomBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 157 [_rejoinChatroomBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  158 + [self setButtonBorder:_rejoinChatroomBtn];
143 } 159 }
144 return _rejoinChatroomBtn; 160 return _rejoinChatroomBtn;
145 } 161 }
146 162
  163 +- (void)setButtonBorder:(UIButton *)button
  164 +{
  165 + button.layer.borderWidth = 1;
  166 + button.layer.borderColor = [UIColor blackColor].CGColor;
  167 + button.layer.cornerRadius = 15;
  168 + button.layer.masksToBounds = YES;
  169 +}
  170 +
147 - (UITextView *)textView 171 - (UITextView *)textView
148 { 172 {
149 if (!_textView) { 173 if (!_textView) {
150 - _textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 140, ScreenWidth, 170)]; 174 + _textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 244, ScreenWidth, ScreenHeight-294)];
151 _textView.editable = NO; 175 _textView.editable = NO;
152 - _textView.backgroundColor = [UIColor cyanColor]; 176 + _textView.layer.borderWidth = 1;
  177 + _textView.layer.borderColor = [UIColor blackColor].CGColor;
153 } 178 }
154 return _textView; 179 return _textView;
155 } 180 }
@@ -162,6 +187,11 @@ @@ -162,6 +187,11 @@
162 return _mutableStr; 187 return _mutableStr;
163 } 188 }
164 189
  190 +- (void)textFieldResignFirstResponder
  191 +{
  192 + [self.textField resignFirstResponder];
  193 +}
  194 +
165 - (void)buttonAction:(UIButton *)button 195 - (void)buttonAction:(UIButton *)button
166 { 196 {
167 switch (button.tag) { 197 switch (button.tag) {
@@ -169,6 +199,8 @@ @@ -169,6 +199,8 @@
169 { 199 {
170 NSDictionary *dic = @{@"name":self.nickStr,@"content":self.textField.text}; 200 NSDictionary *dic = @{@"name":self.nickStr,@"content":self.textField.text};
171 [self.manager sendMessage:[self dictionaryToJson:dic]]; 201 [self.manager sendMessage:[self dictionaryToJson:dic]];
  202 + self.textField.text = @"";
  203 + [self.textField resignFirstResponder];
172 } 204 }
173 break; 205 break;
174 case 10002: 206 case 10002:
@@ -176,6 +208,7 @@ @@ -176,6 +208,7 @@
176 self.nickStr = self.textField.text; 208 self.nickStr = self.textField.text;
177 [self.manager changeNickname:self.textField.text]; 209 [self.manager changeNickname:self.textField.text];
178 self.textField.text = @""; 210 self.textField.text = @"";
  211 + [self.textField resignFirstResponder];
179 } 212 }
180 break; 213 break;
181 case 10003: 214 case 10003:
@@ -277,7 +310,9 @@ @@ -277,7 +310,9 @@
277 { 310 {
278 [self.mutableStr appendString:[NSString stringWithFormat:@"%@\n",msg]]; 311 [self.mutableStr appendString:[NSString stringWithFormat:@"%@\n",msg]];
279 self.textView.text = self.mutableStr; 312 self.textView.text = self.mutableStr;
280 - self.textField.text = @""; 313 + [self.textView scrollRangeToVisible:NSMakeRange(self.textView.text.length, 1)];
  314 +
  315 +// [self.textView sc]
281 } 316 }
282 317
283 318