中山大学数据科学与计算机学院本科生实验报告
课程名称 | 现代操作系统应用开发 | 任课老师 | 郑贵锋 |
---|---|---|---|
年级 | 17级 | 专业(方向) | 软件工程 |
学号 | 17343125 | 姓名 | 伍祥坤 |
电话 | 13411610063 | 1285149329@qq.com | |
开始日期 | 完成日期 | 2020/1/18 |
一、实验题目
期末项目——simple IM
二、实现内容
本人负责的应用的实现部分:
1.通讯录界面
2.好友信息界面
3.完成展示ppt的编写
三、实验结果
(1)实验截图
(2)实验步骤以及关键代码
- 从服务器读取好友信息,并给对应的参数赋值
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
self.Session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: (id)self delegateQueue: [NSOperationQueue mainQueue]];
NSInteger idnum=[_qid intValue];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat: @"http://172.18.62.99:6666/profile/%@",_qid]];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
NSURLSessionDataTask *seesiondatatask = [self.Session dataTaskWithRequest:urlrequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil){
self.dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
self->_qid=self->_dict[@"user"];
self->_sex=self->_dict[@"sex"];
self->_name=self->_dict[@"name"];
self->_sign=self->_dict[@"signature"];
UIView *imgaeview=[UIView new];
[self.view addSubview:imgaeview];
[imgaeview addSubview:self.imageview];
imgaeview.backgroundColor=[UIColor yellowColor];
imgaeview.layer.cornerRadius=50;
[imgaeview mas_makeConstraints:^(MASConstraintMaker *make){
make.top.equalTo(self.view).offset(self.view.frame.size.height*0.3);
make.left.equalTo(self.view).offset((self.view.frame.size.width-100)/2);
make.size.mas_equalTo(CGSizeMake(100, 100));
}];
}
- 使用自动布局给个人头像等布局
imgaeview.layer.cornerRadius=50;
[imgaeview mas_makeConstraints:^(MASConstraintMaker *make){
//make.width.mas_equalTo(150);
make.top.equalTo(self.view).offset(self.view.frame.size.height*0.3);
make.left.equalTo(self.view).offset((self.view.frame.size.width-100)/2);
//make.left.centerX.equalTo(self.view);
//make.center.equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(100, 100));
}];
UIView *nameLabelview1=[UIView new];
[self.view addSubview:nameLabelview1];
[nameLabelview1 addSubview:self.nameLabel];
nameLabelview1.backgroundColor=[UIColor redColor];
[nameLabelview1 mas_makeConstraints:^(MASConstraintMaker *make){
make.centerX.equalTo(imgaeview);
//make.center.equalTo(self.view);
make.top.equalTo(self.view).offset(self.view.frame.size.height*0.45);
make.size.mas_equalTo(CGSizeMake(100, 40));
}];
UIView *ageLabel1=[UIView new];
[self.view addSubview:ageLabel1];
[ageLabel1 addSubview:self.ageLabel];
[ageLabel1 addSubview:self.midLabel];
[ageLabel1 addSubview:self.leftLabel];
//ageLabel1.backgroundColor=[UIColor blueColor];
[ageLabel1 mas_makeConstraints:^(MASConstraintMaker *make){
make.top.equalTo(self.view).offset(self.view.frame.size.height*0.5);
//make.left.equalTo(self.view).offset((self.view.frame.size.width-70)/2);
make.centerX.equalTo(imgaeview.mas_centerX);
//make.center.equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(140, 50));
}];
UIView *qqnumberlabelview=[UIView new];
[self.view addSubview:qqnumberlabelview];
[qqnumberlabelview addSubview:self.QQnumberLabel];
qqnumberlabelview.backgroundColor=[UIColor whiteColor];
[qqnumberlabelview mas_makeConstraints:^(MASConstraintMaker *make){
make.centerX.equalTo(imgaeview.mas_centerX);
//make.center.equalTo(self.view);
make.top.equalTo(self.view).offset((self.view.frame.size.height+140)/2);
//make.left.equalTo(self.view).offset(35);
make.size.mas_equalTo(CGSizeMake((self.view.frame.size.width-140), 40));
}];
UIView *signview=[UIView new];
[self.view addSubview:signview];
[signview addSubview:self.signLabel];
signview.backgroundColor=[UIColor whiteColor];
[signview mas_makeConstraints:^(MASConstraintMaker *make){
make.centerX.equalTo(imgaeview.mas_centerX);
//make.center.equalTo(self.view);
make.top.equalTo(self.view).offset((self.view.frame.size.height+140)/2+40);
//make.left.equalTo(self.view).offset(35);
make.size.mas_equalTo(CGSizeMake((self.view.frame.size.width-140), 50));
}];
- 好友列表使用UICollectionViewCell实现
@implementation FriendCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 100, 50)];
_label.textAlignment = NSTextAlignmentCenter;
_label.textColor = [UIColor blackColor];
_label.font = [UIFont systemFontOfSize:20];
_label.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:_label];
_image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
_image.backgroundColor = [UIColor whiteColor];
_image.layer.masksToBounds=YES;
_image.layer.cornerRadius=25;
[self.contentView addSubview:_image];
}
return self;
}
@end
- 好友列表的字母header
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if(kind==UICollectionElementKindSectionHeader)
{
HeaderCRView *view=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
UILabel *label1;
label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
label1.textColor = [UIColor grayColor];
label1.font = [UIFont systemFontOfSize:20];
label1.text=_sectionlist[indexPath.section];
NSLog(@"%@",_sectionlist);
[view addSubview:label1];
view.backgroundColor=[UIColor whiteColor];
return view;
}
return nil;
}
- 好友列表点击动画
[UIView animateWithDuration:1.0
delay:0.1
options:(UIViewAnimationOptionBeginFromCurrentState)
animations:^{
friendcell.contentView.backgroundColor=[UIColor grayColor];
friendcell.label.backgroundColor=[UIColor grayColor];
}
completion:^(BOOL finished) {
friendcell.contentView.backgroundColor=[UIColor whiteColor];
friendcell.label.backgroundColor=[UIColor whiteColor];
}];
(3)实验遇到的困难以及解决思路
对之前使用过的一些知识还不是很熟悉,在遇到问题的时候翻看了之前写的代码,以及向组员求助,都有效的解决了问题。
四、实验思考及感想
这次期末作业让我懂得了团结协作的重要性,也让我明白了提前做好项目设计和分工的重要性。因为项目设计没有十分的完善,导致最后的成品风格不一,个别功能实现有偏差,这是我们要改进的部分。在巩固已有知识的同时,学习到了新的知识,提高了编码能力和debug能力,对ios开发又多了一些经验。