|
|
@@ -7,20 +7,20 @@
|
|
|
// 发布技能
|
|
|
|
|
|
#import "PostSkillsController.h"
|
|
|
+#import "Masonry.h"
|
|
|
|
|
|
-@interface PostSkillsController ()<UITextFieldDelegate, UIImagePickerControllerDelegate,UINavigationControllerDelegate>
|
|
|
-{
|
|
|
+@interface PostSkillsController () <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
|
|
|
NSString *skillPk;
|
|
|
}
|
|
|
-@property (nonatomic, strong) UIScrollView *bgScrollView;
|
|
|
-@property (nonatomic, strong) UITextField *workTypeTF; //工作类型
|
|
|
-@property (nonatomic, strong) UIImageView *workPicView; //工作照片
|
|
|
-@property (nonatomic, strong) UITextField *priceTF; //价格
|
|
|
-@property (nonatomic, strong) UIButton *selectedWorkTypeBtn; //选中支付方式按钮
|
|
|
+@property(nonatomic, strong) UIScrollView *bgScrollView;
|
|
|
+@property(nonatomic, strong) UITextField *workTypeTF; //工作类型
|
|
|
+@property(nonatomic, strong) UIImageView *workPicView; //工作照片
|
|
|
+@property(nonatomic, strong) UITextField *priceTF; //价格
|
|
|
+@property(nonatomic, strong) UIButton *selectedWorkTypeBtn; //选中支付方式按钮
|
|
|
//
|
|
|
-@property (nonatomic, copy) NSString *imageStr; //图片url
|
|
|
-@property (nonatomic, strong) UIView *bgSkillView;//技能标签背景
|
|
|
-@property (strong, nonatomic) NSMutableArray *skillArray;
|
|
|
+@property(nonatomic, copy) NSString *imageStr; //图片url
|
|
|
+@property(nonatomic, strong) UIView *bgSkillView;//技能标签背景
|
|
|
+@property(strong, nonatomic) NSMutableArray *skillArray;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@@ -41,29 +41,39 @@
|
|
|
[self getSkillFromNetworking];
|
|
|
}
|
|
|
|
|
|
-#pragma mark -- 收起键盘
|
|
|
--(void)keyboardHide:(UITapGestureRecognizer*)tap{
|
|
|
- [self.view endEditing:YES];
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithHexString:@"#F2F4F5"]];
|
|
|
+ [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithHexString:@"#F2F4F5"]];
|
|
|
+
|
|
|
+ [self.navigationController.navigationBar setShadowImage:[UIImage new]];
|
|
|
}
|
|
|
|
|
|
-- (void)didReceiveMemoryWarning {
|
|
|
- [super didReceiveMemoryWarning];
|
|
|
- // Dispose of any resources that can be recreated.
|
|
|
+- (void)viewWillDisappear:(BOOL)animated {
|
|
|
+ [super viewWillDisappear:animated];
|
|
|
+ [self.navigationController.navigationBar setBarTintColor:nil];
|
|
|
+ [self.navigationController.navigationBar setShadowImage:nil];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark -- 收起键盘
|
|
|
+
|
|
|
+- (void)keyboardHide:(UITapGestureRecognizer *)tap {
|
|
|
+ [self.view endEditing:YES];
|
|
|
}
|
|
|
|
|
|
- (void)creatNavBar {
|
|
|
self.title = @"发布技能";
|
|
|
- //
|
|
|
- UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
btn.frame = CGRectMake(0, 0, 40, 40);
|
|
|
[btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
|
|
|
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
|
|
|
+ btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
|
|
|
[btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
|
|
|
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
|
|
|
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
|
-
|
|
|
- // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
|
|
|
+ UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
|
+
|
|
|
self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
|
|
|
+
|
|
|
+ self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F4F5"];
|
|
|
}
|
|
|
|
|
|
- (void)backClick {
|
|
|
@@ -75,19 +85,19 @@
|
|
|
UIScrollView *scrollView = [[UIScrollView alloc] init];
|
|
|
scrollView.frame = self.view.bounds;
|
|
|
scrollView.showsVerticalScrollIndicator = NO;
|
|
|
- scrollView.backgroundColor = [UIColor whiteColor];
|
|
|
- CGFloat height = ScreenHeight < 667 ? 697 : ScreenHeight;
|
|
|
+ scrollView.backgroundColor = [UIColor clearColor];
|
|
|
+ CGFloat height = 945;
|
|
|
scrollView.contentSize = CGSizeMake(ScreenWidth, height);
|
|
|
[self.view addSubview:scrollView];
|
|
|
self.bgScrollView = scrollView;
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
UILabel *workTypeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 80, 15)];
|
|
|
workTypeTitleLabel.text = @"工作类型:";
|
|
|
workTypeTitleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
workTypeTitleLabel.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
[scrollView addSubview:workTypeTitleLabel];
|
|
|
-
|
|
|
+
|
|
|
UITextField *workTypeTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(workTypeTitleLabel.frame), 20, ScreenWidth / 2, 15)];
|
|
|
workTypeTF.placeholder = @"选择您的工作类型";
|
|
|
workTypeTF.userInteractionEnabled = NO;
|
|
|
@@ -95,19 +105,19 @@
|
|
|
workTypeTF.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
[scrollView addSubview:workTypeTF];
|
|
|
self.workTypeTF = workTypeTF;
|
|
|
-
|
|
|
- self.bgSkillView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(workTypeTitleLabel.frame) + 20, ScreenWidth, ((self.skillArray.count-1)/3+1)*50)];
|
|
|
- self.bgSkillView.backgroundColor = [UIColor whiteColor];
|
|
|
+
|
|
|
+ self.bgSkillView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(workTypeTitleLabel.frame) + 20, ScreenWidth, ((self.skillArray.count - 1) / 3 + 1) * 54)];
|
|
|
+ self.bgSkillView.backgroundColor = [UIColor clearColor];
|
|
|
[scrollView addSubview:self.bgSkillView];
|
|
|
-
|
|
|
- int width = (ScreenWidth-120)/3;
|
|
|
-
|
|
|
- for (int i=0; i<self.skillArray.count; i++) {
|
|
|
-
|
|
|
+
|
|
|
+ int width = (ScreenWidth - 70) / 3;
|
|
|
+
|
|
|
+ for (int i = 0; i < self.skillArray.count; i++) {
|
|
|
+
|
|
|
int m = i % 3;
|
|
|
int n = i / 3;
|
|
|
-
|
|
|
- UIButton *skillButton = [[UIButton alloc]initWithFrame:CGRectMake(20+(width+40)*m, 50*n, width, 35)];
|
|
|
+
|
|
|
+ UIButton *skillButton = [[UIButton alloc] initWithFrame:CGRectMake(20 + (width + 15) * m, 54 * n, width, 44)];
|
|
|
skillButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
[skillButton setTitle:[self.skillArray[i] objectForKey:@"name"] forState:UIControlStateNormal];
|
|
|
[skillButton setTitleColor:RGB(50, 50, 50) forState:UIControlStateNormal];
|
|
|
@@ -120,87 +130,98 @@
|
|
|
[skillButton addTarget:self action:@selector(selectedAmountBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[self.bgSkillView addSubview:skillButton];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
scrollView.contentSize = CGSizeMake(ScreenWidth, self.bgSkillView.frame.size.height + 400);
|
|
|
-
|
|
|
- //
|
|
|
- UIView *upLineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.bgSkillView.frame), ScreenWidth, 0.5)];
|
|
|
- upLineView.backgroundColor = RGBValueColor(0xdfdfdf, 1.0);
|
|
|
- [scrollView addSubview:upLineView];
|
|
|
-
|
|
|
- UILabel *workPicTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(upLineView.frame) + 20, 80, 15)];
|
|
|
+
|
|
|
+ UILabel *workPicTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.bgSkillView.frame) + 20, 80, 15)];
|
|
|
workPicTitleLabel.text = @"工作照片:";
|
|
|
- workPicTitleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
- workPicTitleLabel.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
+ workPicTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
|
+ workPicTitleLabel.textColor = [UIColor blackColor];
|
|
|
[scrollView addSubview:workPicTitleLabel];
|
|
|
-
|
|
|
- self.workPicView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(workPicTitleLabel.frame), CGRectGetMaxY(upLineView.frame) + 20, 80, 80)];
|
|
|
+
|
|
|
+ self.workPicView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(workPicTitleLabel.frame), CGRectGetMaxY(self.bgSkillView.frame) + 20, 80, 80)];
|
|
|
self.workPicView.image = [UIImage imageNamed:@"tianjiajineng"];
|
|
|
[scrollView addSubview:self.workPicView];
|
|
|
-
|
|
|
- UIButton *addPicBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(workPicTitleLabel.frame), CGRectGetMaxY(upLineView.frame) + 20, 80, 80)];
|
|
|
+
|
|
|
+ UIButton *addPicBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(workPicTitleLabel.frame), CGRectGetMaxY(self.bgSkillView.frame) + 20, 80, 80)];
|
|
|
addPicBtn.backgroundColor = [UIColor clearColor];
|
|
|
[addPicBtn addTarget:self action:@selector(addPicBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[scrollView addSubview:addPicBtn];
|
|
|
-
|
|
|
- UIView *downLineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.workPicView.frame) + 20, ScreenWidth, 0.5)];
|
|
|
- downLineView.backgroundColor = RGBValueColor(0xdfdfdf, 1.0);
|
|
|
- [scrollView addSubview:downLineView];
|
|
|
-
|
|
|
- //
|
|
|
- UILabel *priceTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(downLineView.frame) + 20, 50, 15)];
|
|
|
- priceTitleLabel.text = @"价格:";
|
|
|
- priceTitleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
- priceTitleLabel.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
- [scrollView addSubview:priceTitleLabel];
|
|
|
-
|
|
|
- UITextField *priceTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(priceTitleLabel.frame), CGRectGetMaxY(downLineView.frame) + 20, 100, 15)];
|
|
|
+
|
|
|
+
|
|
|
+ UIView *priceContainer = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.workPicView.frame) + 20, ScreenWidth - 40, 60)];
|
|
|
+ priceContainer.layer.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1].CGColor;
|
|
|
+ priceContainer.layer.cornerRadius = 8;
|
|
|
+ [scrollView addSubview:priceContainer];
|
|
|
+
|
|
|
+
|
|
|
+ UITextField *priceTF = [[UITextField alloc] init];
|
|
|
priceTF.textAlignment = NSTextAlignmentLeft;
|
|
|
priceTF.keyboardType = UIKeyboardTypeDecimalPad;
|
|
|
- priceTF.font = [UIFont systemFontOfSize:15];
|
|
|
- priceTF.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
- priceTF.placeholder = @"请填写价格";
|
|
|
+ priceTF.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
|
+ priceTF.textColor = [UIColor blackColor];
|
|
|
+
|
|
|
+ NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"请输入占位文字"
|
|
|
+ attributes:@{NSForegroundColorAttributeName: [UIColor colorWithHexString:@"#999999"], NSFontAttributeName: [UIFont systemFontOfSize:14]}];
|
|
|
+ priceTF.attributedPlaceholder = attrString;
|
|
|
priceTF.tag = 700;
|
|
|
priceTF.delegate = self;
|
|
|
- [scrollView addSubview:priceTF];
|
|
|
+ [priceContainer addSubview:priceTF];
|
|
|
+ [priceTF mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.equalTo(priceContainer).offset(20);
|
|
|
+ make.right.equalTo(priceContainer).offset(-120);
|
|
|
+ make.centerY.equalTo(priceContainer);
|
|
|
+ make.height.equalTo(priceContainer);
|
|
|
+ }];
|
|
|
self.priceTF = priceTF;
|
|
|
-
|
|
|
- UILabel *unitLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.priceTF.frame), CGRectGetMaxY(downLineView.frame) + 20, 100, 15)];
|
|
|
- unitLabel.textAlignment = NSTextAlignmentLeft;
|
|
|
+
|
|
|
+ UILabel *unitLabel = [[UILabel alloc] init];
|
|
|
+ unitLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
unitLabel.text = @"元/小时";
|
|
|
- unitLabel.font = [UIFont systemFontOfSize:15];
|
|
|
- unitLabel.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
- [scrollView addSubview:unitLabel];
|
|
|
-
|
|
|
- //
|
|
|
- UIButton *postBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
- postBtn.frame = CGRectMake(20, CGRectGetMaxY(priceTitleLabel.frame) + 70, ScreenWidth - 40, 45);
|
|
|
- [postBtn setBackgroundImage:[UIImage imageNamed:@"anniu"] forState:UIControlStateNormal];
|
|
|
+ unitLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
|
+ unitLabel.textColor = [UIColor blackColor];
|
|
|
+ [priceContainer addSubview:unitLabel];
|
|
|
+ [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.right.equalTo(priceContainer);
|
|
|
+ make.centerY.equalTo(priceContainer);
|
|
|
+ make.width.mas_equalTo(100);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UILabel *remark = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(priceContainer.frame) + 20, ScreenWidth - 40, 184)];
|
|
|
+ remark.numberOfLines = 0;
|
|
|
+ remark.font = [UIFont systemFontOfSize:13];
|
|
|
+ remark.textColor = [UIColor colorWithHexString:@"#808080"];
|
|
|
+ remark.text = @"说明:\n模特技能价格自行定价,可通过与顾客视频面试协商后及时修改;\n商演结束,模特提取定价金额的70%;\n模特接单后,如用户出现临时取消或修改等,模特可得到订单金额的20%作为补偿。\n如出现商演迟到、未达到用户要求等争议问题,接受协商解决。";
|
|
|
+ [scrollView addSubview:remark];
|
|
|
+
|
|
|
+ UIButton *postBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(remark.frame) + 70, ScreenWidth - 40, 44)];
|
|
|
+ postBtn.layer.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1].CGColor;
|
|
|
+ postBtn.layer.cornerRadius = 22;
|
|
|
+ postBtn.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor;
|
|
|
+ postBtn.layer.shadowOffset = CGSizeMake(0, 8);
|
|
|
+ postBtn.layer.shadowOpacity = 1;
|
|
|
+ postBtn.layer.shadowRadius = 10;
|
|
|
+ postBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
|
|
[postBtn setTitle:@"确认发布" forState:UIControlStateNormal];
|
|
|
[postBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal];
|
|
|
[postBtn addTarget:self action:@selector(postBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[scrollView addSubview:postBtn];
|
|
|
-
|
|
|
- //
|
|
|
- UILabel *instructionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(postBtn.frame) + 16, ScreenWidth - 40, 12)];
|
|
|
- instructionsLabel.text = @"说明:请勿发布违反国家法规的内容";
|
|
|
- instructionsLabel.font = [UIFont systemFontOfSize:12];
|
|
|
- instructionsLabel.textColor = RGBValueColor(0x333333, 1.0);
|
|
|
- [scrollView addSubview:instructionsLabel];
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 选中的工作方式
|
|
|
+
|
|
|
- (void)selectedAmountBtnAction:(UIButton *)sender {
|
|
|
-
|
|
|
+
|
|
|
skillPk = [self.skillArray[sender.tag] objectForKey:@"pk"];
|
|
|
self.workTypeTF.text = sender.currentTitle;
|
|
|
-
|
|
|
+
|
|
|
self.selectedWorkTypeBtn.selected = NO;
|
|
|
sender.selected = !sender.selected;
|
|
|
self.selectedWorkTypeBtn = sender;
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 确认发布
|
|
|
+
|
|
|
- (void)postBtnAction {
|
|
|
NSLog(@"确认发布");
|
|
|
if (self.workTypeTF.text.length == 0) {
|
|
|
@@ -219,13 +240,14 @@
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 获取技能标签
|
|
|
--(void)getSkillFromNetworking{
|
|
|
+
|
|
|
+- (void)getSkillFromNetworking {
|
|
|
// 获取技能标签
|
|
|
[YanCNetWorkManager requestGETWithURLStr:Url_getSkill(PublicUrl) parameters:nil finish:^(id dataDic) {
|
|
|
-
|
|
|
+
|
|
|
NSString *issuccess = dataDic[@"msg"];
|
|
|
if ([issuccess isEqualToString:@"success"]) {
|
|
|
-
|
|
|
+
|
|
|
self.skillArray = dataDic[@"data"];
|
|
|
//设置子试图
|
|
|
[self creatSubViews];
|
|
|
@@ -233,14 +255,15 @@
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
[MBProgressHUD showInfo:@"请求失败!"];
|
|
|
}
|
|
|
- } enError:^(NSError *error) {
|
|
|
+ } enError:^(NSError *error) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 发布技能
|
|
|
+
|
|
|
- (void)postDataFromNetworking {
|
|
|
-
|
|
|
+
|
|
|
ModelUser *modelUser = [ModelUser user];
|
|
|
NSString *price = [NSString stringWithFormat:@"%@", self.priceTF.text];
|
|
|
NSMutableDictionary *parameterDic = [NSMutableDictionary dictionaryWithCapacity:0];
|
|
|
@@ -249,7 +272,7 @@
|
|
|
[parameterDic setObject:skillPk forKey:@"skillpk"];
|
|
|
[parameterDic setObject:price forKey:@"price"];
|
|
|
[parameterDic setObject:@"元/小时" forKey:@"unit"];
|
|
|
-
|
|
|
+
|
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
[YanCNetWorkManager requestPostWithURLStr:Url_addskill(PublicUrl) parameters:parameterDic finish:^(id dataDic) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
@@ -257,18 +280,19 @@
|
|
|
NSString *issuccess = dataDic[@"msg"];
|
|
|
if ([issuccess isEqualToString:@"success"]) {
|
|
|
[MBProgressHUD showInfo:@"发布成功!"];
|
|
|
-
|
|
|
+
|
|
|
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(backClick) userInfo:nil repeats:NO];
|
|
|
} else {
|
|
|
[MBProgressHUD showInfo:@"请求失败!"];
|
|
|
}
|
|
|
- } enError:^(NSError *error) {
|
|
|
+ } enError:^(NSError *error) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
NSLog(@"error = %@", error);
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 添加工作照
|
|
|
+
|
|
|
- (void)addPicBtnAction {
|
|
|
NSLog(@"添加工作照");
|
|
|
[self changeHeaderPicture];
|
|
|
@@ -276,20 +300,21 @@
|
|
|
|
|
|
#pragma mark -- 获取图片
|
|
|
#pragma mark - 更换头像的方法
|
|
|
+
|
|
|
- (void)changeHeaderPicture {
|
|
|
-
|
|
|
+
|
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
|
|
|
// 设置按钮
|
|
|
- UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"从相册中选择" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"从相册中选择" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *_Nonnull action) {
|
|
|
NSLog(@"选择相册");
|
|
|
[self pickerPictureFromPhotoLibrary];
|
|
|
}];
|
|
|
-
|
|
|
- UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"使用相机拍摄" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+
|
|
|
+ UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"使用相机拍摄" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *_Nonnull action) {
|
|
|
NSLog(@"请选择相机");
|
|
|
[self pickerPictureFromCamera];
|
|
|
}];
|
|
|
-
|
|
|
+
|
|
|
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
|
|
|
[alertController addAction:action1];
|
|
|
[alertController addAction:action2];
|
|
|
@@ -307,7 +332,7 @@
|
|
|
pickerVC.allowsEditing = YES;
|
|
|
// 设置代理
|
|
|
pickerVC.delegate = self;
|
|
|
-
|
|
|
+
|
|
|
[self presentViewController:pickerVC animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
@@ -327,18 +352,19 @@
|
|
|
pickerVC.allowsEditing = YES;
|
|
|
// 设置代理
|
|
|
pickerVC.delegate = self;
|
|
|
-
|
|
|
+
|
|
|
[self presentViewController:pickerVC animated:YES completion:nil];
|
|
|
}
|
|
|
|
|
|
#pragma mark - UIImagePickerControllerDelegate的代理方法
|
|
|
-- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
|
|
|
+
|
|
|
+- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info {
|
|
|
// // info存储的是我们要的图片, 而图片是编辑后要得到的, 所以使用UIImagePickerControllerEditedImage
|
|
|
//先要把头像上传,若上传成功了,就把这个图片给显示出来
|
|
|
-
|
|
|
+
|
|
|
//先要把头像上传,若上传成功了,就把这个图片给显示出来
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
|
|
-
|
|
|
+
|
|
|
NSString *mediaType = info[UIImagePickerControllerMediaType];
|
|
|
if ([mediaType isEqualToString:@"public.image"]) {
|
|
|
NSLog(@"image...");
|
|
|
@@ -350,14 +376,14 @@
|
|
|
imagesize.height = 100;
|
|
|
//对图片大小进行压缩
|
|
|
UIImage *newImg = [self imageWithImage:original scaledToSize:imagesize];
|
|
|
- NSData *imageData = UIImageJPEGRepresentation(newImg,1);
|
|
|
-
|
|
|
+ NSData *imageData = UIImageJPEGRepresentation(newImg, 1);
|
|
|
+
|
|
|
|
|
|
// UIImage *selectImg = [[UIImage alloc] init];
|
|
|
UIImage *selectImg = [UIImage imageWithData:imageData];
|
|
|
// NSLog(@"selectImg:%@",selectImg);
|
|
|
self.workPicView.image = selectImg;
|
|
|
-
|
|
|
+
|
|
|
[self postPicDataWithNetworkingWith:newImg];
|
|
|
}
|
|
|
}];
|
|
|
@@ -366,9 +392,9 @@
|
|
|
//用户取消退出picker时候调用
|
|
|
|
|
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
|
|
- NSLog(@"picker = %@",picker);
|
|
|
+ NSLog(@"picker = %@", picker);
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
|
|
-
|
|
|
+
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
@@ -376,36 +402,37 @@
|
|
|
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
|
|
|
// Create a graphics image context
|
|
|
UIGraphicsBeginImageContext(newSize);
|
|
|
-
|
|
|
+
|
|
|
// Tell the old image to draw in this new context, with the desired
|
|
|
// new size
|
|
|
- [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
|
|
|
-
|
|
|
+ [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
|
|
|
+
|
|
|
// Get the new image from the context
|
|
|
- UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
-
|
|
|
+ UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
+
|
|
|
// End the context
|
|
|
UIGraphicsEndImageContext();
|
|
|
-
|
|
|
+
|
|
|
// Return the new image.
|
|
|
return newImage;
|
|
|
}
|
|
|
|
|
|
#pragma mark -- 上传图片
|
|
|
+
|
|
|
- (void)postPicDataWithNetworkingWith:(UIImage *)image {
|
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
-
|
|
|
+
|
|
|
[YanCNetWorkManager requestPostWithURLStr:Url_skillphoto(PublicUrl) fileData:image name:@"skillImage" fileName:@"111.png" mimeType:@"image/jpg/png" parameters:nil finish:^(id dataDic) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
|
|
NSString *issuccess = dataDic[@"msg"];
|
|
|
if ([issuccess isEqualToString:@"success"]) {
|
|
|
self.imageStr = [NSString stringWithFormat:@"%@", dataDic[@"img"]];
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
[MBProgressHUD showInfo:@"请求失败!"];
|
|
|
}
|
|
|
- } enError:^(NSError *error) {
|
|
|
+ } enError:^(NSError *error) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
}];
|
|
|
}
|
|
|
@@ -417,14 +444,15 @@
|
|
|
}
|
|
|
*/
|
|
|
#pragma mark ----- UITextFieldDelegate
|
|
|
+
|
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
|
|
NSLog(@"textField.text = %@", textField.text);
|
|
|
}
|
|
|
|
|
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
|
|
if (textField.tag == 700) {
|
|
|
- if(![self isValidAboutInputText:textField shouldChangeCharactersInRange:range replacementString:string decimalNumber:2]) {
|
|
|
-
|
|
|
+ if (![self isValidAboutInputText:textField shouldChangeCharactersInRange:range replacementString:string decimalNumber:2]) {
|
|
|
+
|
|
|
return NO;
|
|
|
}
|
|
|
}
|
|
|
@@ -434,46 +462,46 @@
|
|
|
//输入框中只能输入数字和小数点,且小数点只能输入一位,参数number 可以设置小数的位数,该函数在-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string调用;
|
|
|
|
|
|
- (BOOL)isValidAboutInputText:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string decimalNumber:(NSInteger)number {
|
|
|
-
|
|
|
- NSScanner *scanner = [NSScanner scannerWithString:string];
|
|
|
+
|
|
|
+ NSScanner *scanner = [NSScanner scannerWithString:string];
|
|
|
NSCharacterSet *numbers;
|
|
|
- NSRange pointRange = [textField.text rangeOfString:@"."];
|
|
|
- if ( (pointRange.length > 0) && (pointRange.location < range.location || pointRange.location > range.location + range.length) ){
|
|
|
+ NSRange pointRange = [textField.text rangeOfString:@"."];
|
|
|
+ if ((pointRange.length > 0) && (pointRange.location < range.location || pointRange.location > range.location + range.length)) {
|
|
|
numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
|
|
|
}
|
|
|
- if ( [textField.text isEqualToString:@""] && [string isEqualToString:@"."] ){
|
|
|
+ if ([textField.text isEqualToString:@""] && [string isEqualToString:@"."]) {
|
|
|
return NO;
|
|
|
}
|
|
|
short remain = number; //保留 number位小数
|
|
|
NSString *tempStr = [textField.text stringByAppendingString:string];
|
|
|
NSUInteger strlen = [tempStr length];
|
|
|
- if(pointRange.length > 0 && pointRange.location > 0){ //判断输入框内是否含有“.”。
|
|
|
- if([string isEqualToString:@"."]){ //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
|
|
|
+ if (pointRange.length > 0 && pointRange.location > 0) { //判断输入框内是否含有“.”。
|
|
|
+ if ([string isEqualToString:@"."]) { //当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
|
|
|
return NO;
|
|
|
}
|
|
|
- if(strlen > 0 && (strlen - pointRange.location) > remain+1){ //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
|
|
|
+ if (strlen > 0 && (strlen - pointRange.location) > remain + 1) { //当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
|
|
|
return NO;
|
|
|
}
|
|
|
}
|
|
|
NSRange zeroRange = [textField.text rangeOfString:@"0"];
|
|
|
- if(zeroRange.length == 1 && zeroRange.location == 0){ //判断输入框第一个字符是否为“0”
|
|
|
- if(![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1){ //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
|
|
|
+ if (zeroRange.length == 1 && zeroRange.location == 0) { //判断输入框第一个字符是否为“0”
|
|
|
+ if (![string isEqualToString:@"0"] && ![string isEqualToString:@"."] && [textField.text length] == 1) { //当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
|
|
|
textField.text = string;
|
|
|
return NO;
|
|
|
- }else{
|
|
|
- if(pointRange.length == 0 && pointRange.location > 0){ //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
|
|
|
- if([string isEqualToString:@"0"]){
|
|
|
+ } else {
|
|
|
+ if (pointRange.length == 0 && pointRange.location > 0) { //当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
|
|
|
+ if ([string isEqualToString:@"0"]) {
|
|
|
return NO;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
NSString *buffer;
|
|
|
- if ( ![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0) ){
|
|
|
+ if (![scanner scanCharactersFromSet:numbers intoString:&buffer] && ([string length] != 0)) {
|
|
|
return NO;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return YES;
|
|
|
}
|
|
|
}
|