InputView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // InputView.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/1/7.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "InputView.h"
  9. @implementation InputView
  10. -(id)initWithTitle:(NSString*)title{
  11. self = [super initWithFrame:kFrame];
  12. [self setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.6]];
  13. if (self)
  14. {
  15. CGFloat x,y,w,h,bd;
  16. w = 280;
  17. x = (kSize.width - w)/2.0;
  18. y=0;
  19. h = 120;
  20. UIView* cv = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  21. [cv setBackgroundColor:backGroundColor];
  22. // [self addSubview:cv];
  23. cv.center = CGPointMake(kSize.width/2.0, kSize.height/2.0-kNavOffSet);
  24. cv.layer.cornerRadius = 10;
  25. cv.layer.masksToBounds = YES;
  26. [cv setClipsToBounds:YES];
  27. contentVi = cv;
  28. UILabel* label;
  29. int num = 4;
  30. int cnt = 10;
  31. bd = 15;
  32. h = (contentVi.width - (num+1)*bd)/num;
  33. x=0;
  34. y=0;
  35. // w=w;
  36. // h=30;
  37. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  38. [label setBackgroundColor:RQ_MAIN_COLOR];
  39. [label setTextColor:[UIColor whiteColor]];
  40. [label setText:title];
  41. [label setTextAlignment:NSTextAlignmentCenter];
  42. [cv addSubview:label];
  43. UIButton* btn;
  44. NSInteger tag=0;
  45. bd = 10;
  46. w = h;
  47. x = cv.width - bd - w;
  48. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  49. [btn setTitle:@"×" textColor:[UIColor whiteColor] Font:30 fotState:UIControlStateNormal];
  50. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  51. [cv addSubview:btn];
  52. [btn setTag:tag++];
  53. //port 1 -10
  54. num = 4;
  55. cnt = 10;
  56. bd = 15;
  57. w = (contentVi.width - (num+1)*bd)/num;
  58. y+= h + bd;
  59. h = w;
  60. for (int i = 0; i<cnt; i++)
  61. {
  62. x = (bd+w)*(i%num)+bd;
  63. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  64. NSString* path = [NSString stringWithFormat:@"portrait%d.png",i+1];
  65. [btn setImage:[UIImage imageNamed:path] forState:UIControlStateNormal];
  66. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  67. [btn setBackgroundColor:RQ_MAIN_COLOR];
  68. [contentVi addSubview:btn];
  69. btn.layer.cornerRadius = 5;
  70. btn.layer.masksToBounds = YES;
  71. [btn setTag:tag++];
  72. if ( 0 == (i+1)%num)
  73. {
  74. y += h + bd ;
  75. }
  76. }
  77. x = 0;
  78. w = contentVi.width*.5;
  79. if ( 0 != cnt%num)
  80. {
  81. y += h + bd ;
  82. }
  83. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  84. [btn setTitle:@"相册" textColor:RQ_MAIN_COLOR Font:20 fotState:UIControlStateNormal];
  85. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  86. [contentVi addSubview:btn];
  87. [btn setTag:tag++];
  88. x += w;
  89. btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  90. [btn setTitle:@"拍照" textColor:RQ_MAIN_COLOR Font:20 fotState:UIControlStateNormal];
  91. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  92. [contentVi addSubview:btn];
  93. [btn setTag:tag++];
  94. contentVi.height = y+ h;
  95. }
  96. return self;
  97. }
  98. -(void)btnClick:(UIButton*)sender
  99. {
  100. // NSLog(@"btn%d",(int)sender.tag);
  101. if (sender.tag < 1) {
  102. [self cancelAction];
  103. return;
  104. }else if (sender.tag < 11){
  105. NSString* path = [NSString stringWithFormat:@"portrait%d.png",(int)sender.tag];
  106. if (_delegate && [_delegate respondsToSelector:@selector(InputView:didGetImage:)]) {
  107. [_delegate InputView:self didGetImage:[UIImage imageNamed:path]];
  108. [self cancelAction];
  109. }
  110. return;
  111. }
  112. if (11 == sender.tag) {
  113. self.type = 1;
  114. }if (12 == sender.tag) {
  115. self.type = 0;
  116. }
  117. if (_delegate && [_delegate respondsToSelector:@selector(InputViewWillPickImage:)]) {
  118. [_delegate InputViewWillPickImage:self];
  119. //如果调相机相册 也要移除视图
  120. [self removeFromSuperview];
  121. }
  122. }
  123. -(void)show
  124. {
  125. [[UIApplication sharedApplication].keyWindow addSubview:self];
  126. CGFloat cor = contentVi.layer.cornerRadius;
  127. contentVi.layer.cornerRadius = cor;
  128. contentVi.frame = contentVi.frame;
  129. [UIView animateWithDuration:.5 animations:^{
  130. [self addSubview:contentVi];
  131. } completion:^(BOOL finished) {
  132. }];
  133. }
  134. - (void)cancelAction {
  135. //这句话防止取消过程中 被用户点击
  136. self.userInteractionEnabled = NO;
  137. [UIView animateWithDuration:.5 animations:^{
  138. // contentVi.frame = CGRectMake(contentVi.center.x, contentVi.center.y, 0, 0);
  139. [self removeFromSuperview];
  140. } completion:^(BOOL finished) {
  141. [self removeFromSuperview];
  142. }];
  143. }
  144. @end