// // GIGaMaskShareViewController.m // GIGA // // Created by lianxiang on 2018/9/21. // Copyright © 2018年 com.giga.ios. All rights reserved. // #import "GIGaMaskShareViewController.h" #import "MaskTimeEndViewImgaeCell.h" #import "MaskTimeTimeViewCell.h" #import "MaskTimeEndActionViewCell.h" #import "ShareViewController.h" #import "MaskTimeShareActionSheet.h" #import "GIGaUserFileHelper.h" #import @interface GIGaMaskShareViewController () @end @implementation GIGaMaskShareViewController - (void)viewDidLoad { [super viewDidLoad]; [self addNavTitile:@"面膜时间"]; [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.backgroundColor = [UIColor whiteColor]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; self.tableView.sectionFooterHeight = 0; self.tableView.estimatedSectionFooterHeight= 0; self.tableView.estimatedSectionHeaderHeight = 0; //self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 30)]; self.tableView.frame = CGRectMake(0,0,KMainW, self.view.frame.size.height); // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { MaskTimeEndViewImgaeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskTimeEndViewImgaeCell"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskTimeEndViewImgaeCell" owner:self options:nil] lastObject]; } return cell; }else if (indexPath.section == 1){ MaskTimeTimeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskTimeTimeViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskTimeTimeViewCell" owner:self options:nil] lastObject]; } return cell; }else if (indexPath.section == 2){ MaskTimeEndActionViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskTimeEndActionViewCell"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskTimeEndActionViewCell" owner:self options:nil] lastObject]; } [cell.changeBackBtn addTarget:self action:@selector(changeBackBtnAction) forControlEvents:UIControlEventTouchUpInside]; [cell.shareBtn addTarget:self action:@selector(shareBtnAction) forControlEvents:UIControlEventTouchUpInside]; return cell; } return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { return 285; }else if (indexPath.section == 1){ return 205; } return 90; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.1; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.1; } #pragma mark changeBackBtnAction -(void)changeBackBtnAction{ MaskTimeShareActionSheet * sheet = [[MaskTimeShareActionSheet alloc] initWithFrame:CGRectMake(0, 0, KMainW, KMainH)]; [sheet show:^(NSUInteger index) { switch (index) { case 0: {//手机 [self photosAlbum]; } break; case 1: { //系统 [GIGaUserFileHelper delectShareImage:kUSERSHAREA_IMAGENAME]; ShareViewController *share = [[ShareViewController alloc] init]; [self presentViewController:share animated:NO completion:nil]; } break; case 2: { //自拍 [self takePhoto]; } break; default: break; } }]; [self.view addSubview:sheet]; } #pragma mark share -(void)shareBtnAction{ ShareViewController *share = [[ShareViewController alloc] init]; [self presentViewController:share animated:NO completion:nil]; } #pragma mark 相册 -(void)photosAlbum{ UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; //相册 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { //权限 imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:imagePickerController animated:YES completion:nil]; }else{ NSString *errorStr = @"应用相权册限受限,请在设置中启用"; [self jxt_showAlertWithTitle:@"" message:errorStr appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { alertMaker.addActionCancelTitle(@"取消"); alertMaker.addActionDefaultTitle(@"去开启"); } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { if (buttonIndex == 1) { NSURL *url = [NSURL URLWithString:@"prefs:root=Photos"]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } } }]; } } -(void)takePhoto{ UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { //权限判断应用是否有使用相机的权限 NSString *mediaType = AVMediaTypeVideo;//读取媒体类型 AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];//读取设备授权状态 if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){ NSString *errorStr = @"应用相机权限受限,请在设置中启用"; [self jxt_showAlertWithTitle:@"" message:errorStr appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) { alertMaker.addActionCancelTitle(@"取消"); alertMaker.addActionDefaultTitle(@"去开启"); } actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) { if (buttonIndex == 1) { NSString *urlStr = @"App-Prefs:root=Photos"; if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:nil]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]]; // Fallback on earlier versions } } }]; return; } // 设置数据源 imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:imagePickerController animated:YES completion:nil]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { GILog(@"info:%@",info); [picker dismissViewControllerAnimated:YES completion:nil] ; UIImage*img=[info objectForKey:UIImagePickerControllerEditedImage]; UIImage *small = [GIGaUserFileHelper zipScaleWithImage:img]; [GIGaUserFileHelper savaShareImange:kUSERSHAREA_IMAGENAME image:small]; ShareViewController *share = [[ShareViewController alloc] init]; [self presentViewController:share animated:NO completion:nil]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [picker dismissViewControllerAnimated:YES completion:nil]; } @end