123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // InputView.m
- // jiaPei
- //
- // Created by apple on 16/1/7.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "InputView.h"
- @implementation InputView
- -(id)initWithTitle:(NSString*)title{
- self = [super initWithFrame:kFrame];
- [self setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.6]];
-
- if (self)
- {
- CGFloat x,y,w,h,bd;
- w = 280;
- x = (kSize.width - w)/2.0;
- y=0;
- h = 120;
- UIView* cv = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [cv setBackgroundColor:backGroundColor];
- // [self addSubview:cv];
- cv.center = CGPointMake(kSize.width/2.0, kSize.height/2.0-kNavOffSet);
- cv.layer.cornerRadius = 10;
- cv.layer.masksToBounds = YES;
- [cv setClipsToBounds:YES];
- contentVi = cv;
-
- UILabel* label;
- int num = 4;
- int cnt = 10;
- bd = 15;
- h = (contentVi.width - (num+1)*bd)/num;
-
-
- x=0;
- y=0;
- // w=w;
- // h=30;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setBackgroundColor:RQ_MAIN_COLOR];
- [label setTextColor:[UIColor whiteColor]];
- [label setText:title];
- [label setTextAlignment:NSTextAlignmentCenter];
- [cv addSubview:label];
-
- UIButton* btn;
- NSInteger tag=0;
-
- bd = 10;
- w = h;
- x = cv.width - bd - w;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [btn setTitle:@"×" textColor:[UIColor whiteColor] Font:30 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [cv addSubview:btn];
- [btn setTag:tag++];
-
- //port 1 -10
- num = 4;
- cnt = 10;
- bd = 15;
- w = (contentVi.width - (num+1)*bd)/num;
-
- y+= h + bd;
- h = w;
- for (int i = 0; i<cnt; i++)
- {
- x = (bd+w)*(i%num)+bd;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- NSString* path = [NSString stringWithFormat:@"portrait%d.png",i+1];
- [btn setImage:[UIImage imageNamed:path] forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [btn setBackgroundColor:RQ_MAIN_COLOR];
- [contentVi addSubview:btn];
- btn.layer.cornerRadius = 5;
- btn.layer.masksToBounds = YES;
-
- [btn setTag:tag++];
- if ( 0 == (i+1)%num)
- {
- y += h + bd ;
- }
- }
- x = 0;
- w = contentVi.width*.5;
- if ( 0 != cnt%num)
- {
- y += h + bd ;
- }
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [btn setTitle:@"相册" textColor:RQ_MAIN_COLOR Font:20 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [contentVi addSubview:btn];
- [btn setTag:tag++];
-
- x += w;
- btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [btn setTitle:@"拍照" textColor:RQ_MAIN_COLOR Font:20 fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
- [contentVi addSubview:btn];
- [btn setTag:tag++];
-
- contentVi.height = y+ h;
- }
- return self;
- }
- -(void)btnClick:(UIButton*)sender
- {
- // NSLog(@"btn%d",(int)sender.tag);
- if (sender.tag < 1) {
- [self cancelAction];
- return;
- }else if (sender.tag < 11){
- NSString* path = [NSString stringWithFormat:@"portrait%d.png",(int)sender.tag];
- if (_delegate && [_delegate respondsToSelector:@selector(InputView:didGetImage:)]) {
- [_delegate InputView:self didGetImage:[UIImage imageNamed:path]];
- [self cancelAction];
- }
- return;
- }
-
- if (11 == sender.tag) {
- self.type = 1;
- }if (12 == sender.tag) {
- self.type = 0;
- }
- if (_delegate && [_delegate respondsToSelector:@selector(InputViewWillPickImage:)]) {
- [_delegate InputViewWillPickImage:self];
- //如果调相机相册 也要移除视图
- [self removeFromSuperview];
- }
-
- }
- -(void)show
- {
- [[UIApplication sharedApplication].keyWindow addSubview:self];
- CGFloat cor = contentVi.layer.cornerRadius;
- contentVi.layer.cornerRadius = cor;
- contentVi.frame = contentVi.frame;
- [UIView animateWithDuration:.5 animations:^{
- [self addSubview:contentVi];
- } completion:^(BOOL finished) {
-
- }];
- }
- - (void)cancelAction {
- //这句话防止取消过程中 被用户点击
- self.userInteractionEnabled = NO;
- [UIView animateWithDuration:.5 animations:^{
- // contentVi.frame = CGRectMake(contentVi.center.x, contentVi.center.y, 0, 0);
- [self removeFromSuperview];
- } completion:^(BOOL finished) {
- [self removeFromSuperview];
- }];
- }
- @end
|