TFSheetView.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // TFSheetView.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/3/30.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "TFSheetView.h"
  9. #import "SheetViewCell.h"
  10. @interface TFSheetView()
  11. {
  12. UIView *_contentView;
  13. }
  14. @end
  15. @implementation TFSheetView
  16. - (id)initWithFrame:(CGRect)frame
  17. {
  18. if (self == [super initWithFrame:frame])
  19. {
  20. [self initContent];
  21. }
  22. return self;
  23. }
  24. - (void)initContent
  25. {
  26. self.frame = CGRectMake(0, 0,Screen_Width, Screen_Height);
  27. //alpha 0.0 白色 alpha 1 :黑色 alpha 0~1 :遮罩颜色,逐渐
  28. self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  29. self.userInteractionEnabled = YES;
  30. [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMissView)]];
  31. if (_contentView == nil)
  32. {
  33. _contentView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_Height - 300, Screen_Width, 300)];
  34. _contentView.backgroundColor = [UIColor whiteColor];
  35. [self addSubview:_contentView];
  36. _invoiceStyleTableView = [[UITableView alloc]
  37. initWithFrame:CGRectMake(0,
  38. 10,
  39. Screen_Width,
  40. 200)];
  41. _invoiceStyleTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  42. _invoiceStyleTableView.backgroundColor = [UIColor whiteColor];
  43. _invoiceStyleTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  44. _invoiceStyleTableView.delegate = self;
  45. _invoiceStyleTableView.dataSource=self;
  46. [_contentView addSubview:_invoiceStyleTableView];
  47. }}
  48. - (void)loadMaskView
  49. {
  50. }
  51. //展示从底部向上弹出的UIView(包含遮罩)
  52. - (void)showInView:(UIView *)view dataArry:(NSMutableArray*)dataList position:(NSInteger)pos
  53. {
  54. if (!view)
  55. {
  56. return;
  57. }
  58. [view addSubview:self];
  59. [view addSubview:_contentView];
  60. _position=pos;
  61. _dataArray=dataList;
  62. [_invoiceStyleTableView reloadData];
  63. [_contentView setFrame:CGRectMake(0, Screen_Height, Screen_Width, 300)];
  64. [UIView animateWithDuration:0.3 animations:^{
  65. self.alpha = 1.0;
  66. [_contentView setFrame:CGRectMake(0, Screen_Height - 300, Screen_Width, 300)];
  67. } completion:nil];
  68. }
  69. //移除从上向底部弹下去的UIView(包含遮罩)
  70. - (void)disMissView
  71. {
  72. [_contentView setFrame:CGRectMake(0, Screen_Height - 300, Screen_Width, 300)];
  73. [UIView animateWithDuration:0.3f
  74. animations:^{
  75. self.alpha = 0.0;
  76. [_contentView setFrame:CGRectMake(0, Screen_Height, Screen_Width, 300)];
  77. }
  78. completion:^(BOOL finished){
  79. [self removeFromSuperview];
  80. [_contentView removeFromSuperview];
  81. }];
  82. }
  83. #pragma mark - 委托回调函数
  84. #pragma mark - tableView回调
  85. /**
  86. 单元格cell个数
  87. @param tableView <#tableView description#>
  88. @param section <#section description#>
  89. @return <#return value description#>
  90. */
  91. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  92. {
  93. return [_dataArray count];
  94. }
  95. /**
  96. <#Description#>
  97. @param tableView <#tableView description#>
  98. @return <#return value description#>
  99. */
  100. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  101. return 1;
  102. }
  103. /**
  104. 每个单元格cell
  105. @param tableView <#tableView description#>
  106. @param indexPath <#indexPath description#>
  107. @return <#return value description#>
  108. */
  109. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. static NSString *cellIdentifier = @"InvoiceStyleCell";
  112. SheetViewCell *cell;
  113. cell=[[SheetViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  114. //为单元格的label设置数据
  115. InvoiceStyle *invoiceStyle = [_dataArray objectAtIndex:indexPath.row];
  116. [cell setInvoiceStyle:invoiceStyle];
  117. return cell;
  118. }
  119. //行高
  120. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  121. return 40;
  122. }
  123. /**
  124. 点击单元格事件
  125. @param tableView tableView description
  126. @param indexPath indexPath description
  127. */
  128. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  129. {
  130. InvoiceStyle *invoiceStyle = [_dataArray objectAtIndex:indexPath.row];
  131. __weak typeof(self) weakself=self;
  132. if ([weakself.delegate respondsToSelector:@selector(goElectronicInvoice:position:)]){
  133. [weakself.delegate goElectronicInvoice:invoiceStyle position:_position];
  134. }
  135. [self disMissView];
  136. }
  137. @end