From 4010d578fda8df5a4069d969285b87d20b82f9ec Mon Sep 17 00:00:00 2001 From: coderZsq Date: Wed, 25 Sep 2019 11:15:50 +0800 Subject: [PATCH] add --- .../SQManagement/Coms/SQProfileHeaderView.h | 2 + .../SQManagement/Coms/SQProfileHeaderView.m | 6 ++ .../SQManagement/Coms/SQProfileHeaderView.xib | 9 ++- SQManagement/SQManagement/Info.plist | 6 +- .../UI/SQAddConnectionViewController.m | 70 +++++++++++++------ 5 files changed, 67 insertions(+), 26 deletions(-) diff --git a/SQManagement/SQManagement/Coms/SQProfileHeaderView.h b/SQManagement/SQManagement/Coms/SQProfileHeaderView.h index a069c7cb..4142d6c9 100644 --- a/SQManagement/SQManagement/Coms/SQProfileHeaderView.h +++ b/SQManagement/SQManagement/Coms/SQProfileHeaderView.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SQProfileHeaderView : UIView +@property (weak, nonatomic) IBOutlet UIImageView *profileImageView; + + (instancetype)headerView; @end diff --git a/SQManagement/SQManagement/Coms/SQProfileHeaderView.m b/SQManagement/SQManagement/Coms/SQProfileHeaderView.m index de746e93..abb31d91 100644 --- a/SQManagement/SQManagement/Coms/SQProfileHeaderView.m +++ b/SQManagement/SQManagement/Coms/SQProfileHeaderView.m @@ -12,6 +12,12 @@ @implementation SQProfileHeaderView + (instancetype)headerView { SQProfileHeaderView *headerView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:nil options:nil].firstObject; + headerView.profileImageView.layer.cornerRadius = 10; + headerView.profileImageView.layer.masksToBounds = YES; + headerView.profileImageView.layer.shadowColor = [UIColor lightGrayColor].CGColor; + headerView.profileImageView.layer.shadowOffset = CGSizeMake(5, 5); + headerView.profileImageView.layer.shadowOpacity = 0.8; + headerView.profileImageView.layer.shadowRadius = 4; return headerView; } diff --git a/SQManagement/SQManagement/Coms/SQProfileHeaderView.xib b/SQManagement/SQManagement/Coms/SQProfileHeaderView.xib index 851e181e..0ffdbca2 100644 --- a/SQManagement/SQManagement/Coms/SQProfileHeaderView.xib +++ b/SQManagement/SQManagement/Coms/SQProfileHeaderView.xib @@ -10,13 +10,13 @@ - + - + - + @@ -30,6 +30,9 @@ + + + diff --git a/SQManagement/SQManagement/Info.plist b/SQManagement/SQManagement/Info.plist index ab6c3155..9dbb0cf3 100644 --- a/SQManagement/SQManagement/Info.plist +++ b/SQManagement/SQManagement/Info.plist @@ -3,7 +3,11 @@ NSContactsUsageDescription - 12345678 + + NSPhotoLibraryUsageDescription + + NSCameraUsageDescription + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable diff --git a/SQManagement/SQManagement/UI/SQAddConnectionViewController.m b/SQManagement/SQManagement/UI/SQAddConnectionViewController.m index a2ddab93..06e00665 100644 --- a/SQManagement/SQManagement/UI/SQAddConnectionViewController.m +++ b/SQManagement/SQManagement/UI/SQAddConnectionViewController.m @@ -10,35 +10,56 @@ #import "SQProfileHeaderView.h" #import "SQConnectionPropertyCell.h" #import "UIColor+SQExtension.h" +#import "UIView+SQExtension.h" -@interface SQAddConnectionViewController () +@interface SQAddConnectionViewController () @property (nonatomic, strong) NSArray *dataSource; +@property (nonatomic, strong) SQProfileHeaderView *headerView; @end @implementation SQAddConnectionViewController - (void)viewDidLoad { [super viewDidLoad]; - self.title = @"新增人脉"; - self.tableView.backgroundColor = [UIColor colorWithHexString:@"f8f8f8"]; - self.dataSource = @[ - @[@"姓名", - @"角色", - @"职业", - @"地区", - @"行业", - @"影响力", - @"亲密程度", - @"黄金人脉圈"], - @[@"联系方式", - @"社交记录"], - @[@"特征", - @"工作", - @"爱好", - @"特殊细节", - @"给我的启发"], - ]; - [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SQConnectionPropertyCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([SQConnectionPropertyCell class])]; + { + self.title = @"新增人脉"; + self.dataSource = @[ + @[@"姓名", @"角色", @"职业", @"地区", @"行业", @"影响力", @"亲密程度", @"黄金人脉圈"], + @[@"联系方式", @"社交记录"], + @[@"特征", @"工作", @"爱好", @"特殊细节", @"给我的启发"], + ]; + } + + { + self.tableView.backgroundColor = [UIColor colorWithHexString:@"f8f8f8"]; + [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SQConnectionPropertyCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([SQConnectionPropertyCell class])]; + } + + { + self.headerView = [SQProfileHeaderView headerView]; + __weak typeof(self) weakSelf = self; + [self.headerView whenTapped:^{ + UIImagePickerController *imagePickerVc = [[UIImagePickerController alloc] init]; + imagePickerVc.delegate = self; + imagePickerVc.allowsEditing = YES; + UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)]; + [alertVc addAction:[UIAlertAction actionWithTitle:@"立即拍摄照片" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { + if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ + imagePickerVc.sourceType = UIImagePickerControllerSourceTypeCamera; + imagePickerVc.cameraDevice = UIImagePickerControllerCameraDeviceRear; + [self presentViewController:imagePickerVc animated:YES completion:nil]; + } + }]]; + [alertVc addAction:[UIAlertAction actionWithTitle:@"从相册中获取" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { + if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){ + imagePickerVc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; + [self presentViewController:imagePickerVc animated:YES completion:nil]; + } + }]]; + [alertVc addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]]; + [weakSelf presentViewController:alertVc animated:YES completion:nil]; + }]; + } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { @@ -66,7 +87,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { - if (section == 0) return [SQProfileHeaderView headerView]; + if (section == 0) return self.headerView; return nil; } @@ -75,6 +96,11 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege return 1; } +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { + [picker dismissViewControllerAnimated:YES completion:nil]; + self.headerView.profileImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; +} + - (IBAction)doneButtonClick:(UIBarButtonItem *)sender { [self dismiss]; }