TCMessageManagerFaceView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // TCMessageManagerFaceView.m
  3. // QimoQM
  4. //
  5. // Created by TuChuan on 15/5/13.
  6. // Copyright (c) 2015年 七陌科技. All rights reserved.
  7. //
  8. #import "TCMessageManagerFaceView.h"
  9. #import "TCExpressionSectionBar.h"
  10. #define FaceSectionBarHeight 46 // 表情下面控件
  11. #define FacePageControlHeight 30 // 表情pagecontrol
  12. #define Pages 2
  13. @implementation TCMessageManagerFaceView
  14. {
  15. UIPageControl *pageControl;
  16. }
  17. - (id)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self setup];
  22. }
  23. return self;
  24. }
  25. - (void)setup{
  26. self.backgroundColor = [UIColor whiteColor];
  27. if (@available(iOS 11.0, *)) {
  28. UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0f,5.0f,CGRectGetWidth(self.bounds),CGRectGetHeight(self.bounds)-self.safeAreaInsets.bottom-FacePageControlHeight-FaceSectionBarHeight)];
  29. scrollView.delegate = self;
  30. [self addSubview:scrollView];
  31. [scrollView setPagingEnabled:YES];
  32. [scrollView setShowsHorizontalScrollIndicator:NO];
  33. [scrollView setContentSize:CGSizeMake(CGRectGetWidth(scrollView.frame)*Pages,CGRectGetHeight(scrollView.frame))];
  34. for (int i= 0;i<Pages;i++) {
  35. TCFaceView *faceView = [[TCFaceView alloc]initWithFrame:CGRectMake(i*CGRectGetWidth(self.bounds),0.0f,CGRectGetWidth(self.bounds),CGRectGetHeight(scrollView.bounds)) forIndexPath:i];
  36. [scrollView addSubview:faceView];
  37. faceView.delegate = self;
  38. }
  39. pageControl = [[UIPageControl alloc]init];
  40. [pageControl setFrame:CGRectMake(0,CGRectGetMaxY(scrollView.frame),CGRectGetWidth(self.bounds),FacePageControlHeight)];
  41. } else {
  42. UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0f,5.0f,CGRectGetWidth(self.bounds),CGRectGetHeight(self.bounds)-FacePageControlHeight-FaceSectionBarHeight)];
  43. scrollView.delegate = self;
  44. [self addSubview:scrollView];
  45. [scrollView setPagingEnabled:YES];
  46. [scrollView setShowsHorizontalScrollIndicator:NO];
  47. [scrollView setContentSize:CGSizeMake(CGRectGetWidth(scrollView.frame)*Pages,CGRectGetHeight(scrollView.frame))];
  48. for (int i= 0;i<Pages;i++) {
  49. TCFaceView *faceView = [[TCFaceView alloc]initWithFrame:CGRectMake(i*CGRectGetWidth(self.bounds),0.0f,CGRectGetWidth(self.bounds),CGRectGetHeight(scrollView.bounds)) forIndexPath:i];
  50. [scrollView addSubview:faceView];
  51. faceView.delegate = self;
  52. }
  53. pageControl = [[UIPageControl alloc]init];
  54. [pageControl setFrame:CGRectMake(0,CGRectGetMaxY(scrollView.frame),CGRectGetWidth(self.bounds),FacePageControlHeight)];
  55. }
  56. [self addSubview:pageControl];
  57. [pageControl setPageIndicatorTintColor:[UIColor lightGrayColor]];
  58. [pageControl setCurrentPageIndicatorTintColor:[UIColor grayColor]];
  59. pageControl.numberOfPages = Pages;
  60. pageControl.currentPage = 0;
  61. self.sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
  62. if (@available(iOS 11.0, *)) {
  63. self.sendButton.frame = CGRectMake(self.bounds.size.width-70, self.bounds.size.height-self.safeAreaInsets.bottom-30, 50, 30);
  64. } else {
  65. self.sendButton.frame = CGRectMake(self.bounds.size.width-70, self.bounds.size.height-30, 50, 30);
  66. }
  67. self.sendButton.backgroundColor = [UIColor colorWithRed:13/255.0 green:139/255.0 blue:249/255.0 alpha:1];
  68. [self.sendButton setTitle:NSLocalizedString(@"button.send", nil) forState:UIControlStateNormal];
  69. [self addSubview:self.sendButton];
  70. }
  71. #pragma mark scrollView Delegate
  72. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  73. {
  74. int page = scrollView.contentOffset.x/320;
  75. pageControl.currentPage = page;
  76. }
  77. #pragma mark ZBFaceView Delegate
  78. - (void)didSelecteFace:(NSString *)faceName andIsSelecteDelete:(BOOL)del{
  79. if ([self.delegate respondsToSelector:@selector(SendTheFaceStr:isDelete:) ]) {
  80. [self.delegate SendTheFaceStr:faceName isDelete:del];
  81. }
  82. }
  83. @end