Skip to content

Commit

Permalink
0827晚细节修改;
Browse files Browse the repository at this point in the history
  • Loading branch information
bestLiu committed Aug 27, 2015
1 parent 8b76820 commit ca7f240
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Binary file not shown.
6 changes: 0 additions & 6 deletions WeChat/WeChat/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@
<view key="view" contentMode="scaleToFill" id="g72-aq-ScK">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nyd-a5-Ef0">
<rect key="frame" x="0.0" y="550" width="600" height="50"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
Expand Down
40 changes: 22 additions & 18 deletions WeChat/WeChat/ChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ @implementation ChatViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
self.navigationItem.title = [NSString stringWithFormat:@"%@聊天中",self.friendJid.user];
[self setupView];


Expand All @@ -32,6 +34,7 @@ - (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

[self loadMsg];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ChatCell"];
}

- (void)setupView
Expand Down Expand Up @@ -67,7 +70,7 @@ - (void)setupView
[self.view addConstraints:inputViewHCons];

//垂直方向的约束
NSArray *VCons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-64-[tableView]-0-[inputView(50)]-0-|" options:0 metrics:nil views:views];
NSArray *VCons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[tableView]-0-[inputView(50)]-0-|" options:0 metrics:nil views:views];
[self.view addConstraints:VCons];
self.inputViewConstraint = [VCons lastObject];
self.inputViewHegihtCos = VCons[2];
Expand All @@ -90,7 +93,7 @@ - (void)loadMsg

//查询
_resultControl = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

_resultControl.delegate = self;
NSError *error = nil;
[_resultControl performFetch:&error];
if (error) {
Expand Down Expand Up @@ -119,16 +122,16 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

if([msg.outgoing boolValue])//自己发的消息
{
cell.textLabel.text = [NSString stringWithFormat:@"I Say:%@",msg.body];
cell.textLabel.text = [NSString stringWithFormat:@"我说:%@",msg.body];
}else//别人发送的消息
{
cell.textLabel.text = [NSString stringWithFormat:@"Other Say:%@",msg.body];
cell.textLabel.text = [NSString stringWithFormat:@"%@:%@",self.friendJid.user,msg.body];
}

return cell;
}

#pragma mark Resultcontroller代理
#pragma mark Resultcontroller代理 ,有数据改变就会调用此方法
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
//刷新数据
Expand Down Expand Up @@ -185,16 +188,6 @@ - (void)scrollToButtom

/*---------------------------------------------------分割线--------------------------------------------------------------*/
- (void)keyboardWillShow:(NSNotification *)noti
{
//隐藏键盘的方法,距离底部永远为0

self.inputViewConstraint.constant = 0;
[UIView animateWithDuration:0.25 animations:^{
[self.view layoutIfNeeded];
}];
}

- (void)keyboardWillHide:(NSNotification *)noti
{
CGRect kbEndFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

Expand All @@ -208,11 +201,22 @@ - (void)keyboardWillHide:(NSNotification *)noti
if ([[UIDevice currentDevice].systemVersion doubleValue] < 8.0 && UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
kbHeight = kbEndFrame.size.width;
}
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
[UIView animateWithDuration:0.25 animations:^{
[self.view layoutIfNeeded];
}];

[self scrollToButtom];

}

- (void)keyboardWillHide:(NSNotification *)noti
{
//隐藏键盘的方法,距离底部永远为0

self.inputViewConstraint.constant = 0;
[UIView animateWithDuration:0.25 animations:^{
[self.view layoutIfNeeded];
}];
}

//- (void)keyboardWillChange:(NSNotification *)noti
Expand Down

0 comments on commit ca7f240

Please sign in to comment.