InputView.m 5.1 KB

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