This commit is contained in:
lianxiang
2018-09-23 01:30:29 +08:00
parent db1740e72b
commit 3508cab25e
80 changed files with 3687 additions and 127 deletions
@@ -11,8 +11,10 @@
#import "MaskTimeTimeViewCell.h"
#import "MaskTimeEndActionViewCell.h"
#import "ShareViewController.h"
@interface GIGaMaskShareViewController ()
#import "MaskTimeShareActionSheet.h"
#import "GIGaUserFileHelper.h"
#import <AVFoundation/AVFoundation.h>
@interface GIGaMaskShareViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@end
@@ -99,7 +101,36 @@
#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
@@ -110,4 +141,91 @@
}
#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<NSString *,id> *)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
@@ -122,13 +122,15 @@
-(void)connetction{
NSURL* url = [[NSURL alloc] initWithString:@"http://wsyts.s1.natapp.cc"];
//@"connectParams":@{@"token":@""}
NSString *token = [GiGaUserDefault getCurentToken];
if (!token) {
token = @"";
}
SocketManager *manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @NO, @"forcePolling": @YES,@"extraHeaders":@{@"device":@"ios"},@"token":token}];
NSString *urlstr = [NSString stringWithFormat:@"http://wsyts.s1.natapp.cc"];
NSURL* url = [[NSURL alloc] initWithString:urlstr];
SocketManager *manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @NO, @"forcePolling": @YES,@"extraHeaders":@{@"device":@"ios"},@"connectParams":@{@"token":token}}];
_manager = manager;
_client = manager.defaultSocket;
@@ -502,9 +502,9 @@
// resultVC.model = model;
// [self.navigationController pushViewController:resultVC animated:YES];
[self showAlertGoShareMaskTime];
//[self showAlertGoShareMaskTime];
return;
GiGaQuestionVC *questionVC = [[GiGaQuestionVC alloc] init];
[self.navigationController pushViewController:questionVC animated:YES];
@@ -667,6 +667,7 @@
- (void)progressDidFish{
NSLog(@"结束");
[self maskTimeEnd];
[self showAlertGoShareMaskTime];
}
- (void)didReceiveMemoryWarning {
@@ -10,9 +10,10 @@
#import "MaskTimeShareViewCell.h"
#import "MaskShareTimeMidViewCell.h"
#import "MaskShareBoootomViewCell.h"
@interface ShareViewController ()<UITableViewDelegate,UITableViewDataSource>
#import "MaskTimeShareActionSheet.h"
#import "GIGaUserFileHelper.h"
#import <AVFoundation/AVFoundation.h>
@interface ShareViewController ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property(nonatomic,strong) UITableView *tab;
@property(nonatomic,strong) UIImageView *backimageview ;
@property(nonatomic) int curentImageIndex ;
@@ -27,9 +28,11 @@
_curentImageIndex = 0;
UIImageView *backimageview = [[UIImageView alloc] init];
backimageview.contentMode = UIViewContentModeScaleAspectFill;
backimageview.frame = CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height);
backimageview.userInteractionEnabled = YES;
backimageview.image = [UIImage imageNamed:@"sharebg_1"];
backimageview.image = [GIGaUserFileHelper getUserShareImage:kUSERSHAREA_IMAGENAME];
// self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sharebg_1"]];
self.backimageview = backimageview;
[self.view addSubview:backimageview];
@@ -37,7 +40,7 @@
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(20,44, 40, 40);
[backBtn setImage:[UIImage imageNamed:@"btn_moment_back"] forState:UIControlStateNormal];
backBtn.backgroundColor = [UIColor redColor];
[backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backBtn];
[self.view insertSubview:backimageview atIndex:0];
@@ -145,19 +148,132 @@
-(void)changeAction{
_curentImageIndex ++;
if (_curentImageIndex == 4) {
_curentImageIndex = 0;
MaskTimeShareActionSheet * sheet = [[MaskTimeShareActionSheet alloc] initWithFrame:CGRectMake(0, 0, KMainW, KMainH)];
[sheet show:^(NSUInteger index) {
switch (index) {
case 0:
{//手机
[self photosAlbum];
}
break;
case 1:
{
//系统
self->_curentImageIndex ++;
if (self->_curentImageIndex == 4) {
self->_curentImageIndex = 0;
}
NSArray *images = @[@"sharebg_2",@"sharebg_3",@"sharebg_4",@"sharebg_5",@"sharebg_1"];
[self.backimageview setImage:[UIImage imageNamed: images[self->_curentImageIndex]]];
}
break;
case 2:
{
//自拍
[self takePhoto];
}
break;
default:
break;
}
}];
[self.view addSubview:sheet];
}
#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];
}
}
}];
}
NSArray *images = @[@"sharebg_2",@"sharebg_3",@"sharebg_4",@"sharebg_5",@"sharebg_1"];
[self.backimageview setImage:[UIImage imageNamed: images[_curentImageIndex]]];
}
-(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<NSString *,id> *)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];
}
-(void)shareBtnAction{
}
@end
@@ -356,6 +356,7 @@
}
-(void)submitAnswer{
NSDictionary *params = @{@"singleChoiceList":self.answerArray};
@@ -375,8 +376,19 @@
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
if (isUserLogin) {
//展示结果
MaskTestResultVC *reusltVC = [[MaskTestResultVC alloc] init];
[self.navigationController pushViewController:reusltVC animated:YES];
NSDictionary *dic = @{
@"dryness":@"0.41",
@"drynessPercent":@"41%",
@"mask":@"",
@"minute":@"19",
@"oiliness":@"0.59",
@"oilinessPercent":@"59%"
};
MaskTestResult *model =[[MaskTestResult alloc] initWithDictionary:dic error:nil];
MaskTestResultVC *resultVC = [[MaskTestResultVC alloc] init];
resultVC.model = model;
[self.navigationController pushViewController:resultVC animated:YES];
}else{
[self jxt_showAlertWithTitle:@"对不起您还没有登录" message:@"请登录后查看肤质测试结果" appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
alertMaker.addActionCancelTitle(@"返回首页");
@@ -10,7 +10,7 @@
#import "MaskResultMinViewCell.h"
#import "MaskResultPercentCell.h"
#import "MaskResultShareViewCell.h"
#import "SHareTestImageVC.h"
#import "GiGaFileNanager.h"
@@ -130,7 +130,7 @@
table.frame = savedFrame;
UIGraphicsEndImageContext();
[[GiGaFileNanager shareInstance] saveImaeToAlBum:image];
[[GiGaFileNanager shareInstance] saveImaeToAlBum:image];
return image;
@@ -1,14 +0,0 @@
//
// SHareTestImageVC.h
// GIGA
//
// Created by lianxiang on 2018/9/21.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GiGaBaseViewController.h"
@interface SHareTestImageVC : GiGaBaseViewController
@property (nonatomic,strong) UIImage *image ;
@end
@@ -1,43 +0,0 @@
//
// SHareTestImageVC.m
// GIGA
//
// Created by lianxiang on 2018/9/21.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "SHareTestImageVC.h"
@interface SHareTestImageVC ()
@end
@implementation SHareTestImageVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIImageView *ima = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
ima.contentMode = UIViewContentModeScaleAspectFit;
ima.image = self.image;
[self.view addSubview:ima];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SHareTestImageVC">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="Q5M-cg-NOt"/>
</view>
</objects>
</document>
@@ -0,0 +1,15 @@
//
// MaskActionSheetViewCell.h
// GIGA
//
// Created by lianxiang on 2018/9/22.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MaskActionSheetViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *sheetTitle;
-(void)comfirmTitles:(NSIndexPath *)indepath;
@end
@@ -0,0 +1,29 @@
//
// MaskActionSheetViewCell.m
// GIGA
//
// Created by lianxiang on 2018/9/22.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "MaskActionSheetViewCell.h"
@implementation MaskActionSheetViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
-(void)comfirmTitles:(NSIndexPath *)indepath
{
NSArray *titles = @[@"手机相册",@"系统相册",@"自拍"];
self.sheetTitle.text = titles[indepath.row];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="MaskActionSheetViewCell" id="KGk-i7-Jjw" customClass="MaskActionSheetViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="40V-PX-LhN">
<rect key="frame" x="137" y="8" width="47" height="26"/>
<fontDescription key="fontDescription" name="PingFangSC-Medium" family="PingFang SC" pointSize="18"/>
<color key="textColor" red="0.51372549019607838" green="0.039215686274509803" blue="0.039215686274509803" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ngI-qP-hKZ">
<rect key="frame" x="0.0" y="43.5" width="320" height="0.5"/>
<color key="backgroundColor" red="0.87058823529411766" green="0.87058823529411766" blue="0.87058823529411766" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="0.5" id="cs5-Qf-Vk6"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="40V-PX-LhN" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Fgn-aW-scP"/>
<constraint firstAttribute="trailing" secondItem="ngI-qP-hKZ" secondAttribute="trailing" id="Hx7-pI-vWZ"/>
<constraint firstItem="ngI-qP-hKZ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="UY4-gg-DTG"/>
<constraint firstItem="40V-PX-LhN" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" id="WWw-Zh-jsa"/>
<constraint firstAttribute="bottom" secondItem="ngI-qP-hKZ" secondAttribute="bottom" constant="-0.5" id="yOL-n1-moT"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<connections>
<outlet property="sheetTitle" destination="40V-PX-LhN" id="jzf-mX-x9L"/>
</connections>
</tableViewCell>
</objects>
</document>
@@ -0,0 +1,15 @@
//
// MaskTimeShareActionSheet.h
// GIGA
//
// Created by lianxiang on 2018/9/22.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void (^actionSheetAction)(NSUInteger index);
@interface MaskTimeShareActionSheet : UIView
@property(nonatomic,copy) actionSheetAction action;
-(void)show:(actionSheetAction)action;
@end
@@ -0,0 +1,116 @@
//
// MaskTimeShareActionSheet.m
// GIGA
//
// Created by lianxiang on 2018/9/22.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "MaskTimeShareActionSheet.h"
#import "MaskActionSheetViewCell.h"
@interface MaskTimeShareActionSheet()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView *tabview;
@end
@implementation MaskTimeShareActionSheet
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3]; ;
[self creatUI];
}
return self;
}
-(void)creatUI{
UIView *holdview =[[UIView alloc] init];
holdview.frame =CGRectMake(0,KMainH - 216 - 60 -20 , KMainW, 216 + 60 +20);
holdview.backgroundColor = [UIColor whiteColor];
// CGRect backRect= holdview.frame;
//
// UIBezierPath *maskPath=[UIBezierPath bezierPathWithRoundedRect:backRect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
// CAShapeLayer *maskLayer =[[CAShapeLayer alloc] init];
// maskLayer.frame = backRect;
// maskLayer.path = maskPath.CGPath;
// holdview.layer.mask = maskLayer;
holdview.layer.masksToBounds = YES;
holdview.layer.cornerRadius = 10;
[self addSubview:holdview];
self.tabview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KMainW, 216 + 60) style:UITableViewStylePlain];
self.tabview.backgroundColor = [UIColor whiteColor];
self.tabview.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tabview.delegate = self;
self.tabview.scrollEnabled = NO;
self.tabview.dataSource = self;
UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
[cancleBtn setTitleColor:GIGARGB(165,165, 165, 1) forState:UIControlStateNormal];
[cancleBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
cancleBtn.frame = CGRectMake(0,1, KMainW,60);
self.tabview.tableFooterView = cancleBtn;
[holdview addSubview:self.tabview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MaskActionSheetViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MaskActionSheetViewCell"];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"MaskActionSheetViewCell" owner:self options:nil] lastObject];
}
[cell comfirmTitles:indexPath];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 54;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.action) {
self.action(indexPath.row);
[self cancleDissmiss];
}
}
-(void)show:(actionSheetAction)action{
self.action = action;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([touches anyObject].view != self.tabview) {
[self cancleDissmiss];
}
}
-(void)cancelAction{
[self cancleDissmiss];
}
-(void)cancleDissmiss{
[UIView animateWithDuration:1.0 animations:^{
self.tabview.frame = CGRectMake(0, KMainH - 216, KMainW, 0);
}];
[self removeFromSuperview];
}
@end