JXShareListVC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // JXShareSelectView.m
  3. // shiku_im
  4. //
  5. // Created by MacZ on 15/8/26.
  6. // Copyright (c) 2015年 Reese. All rights reserved.
  7. //
  8. #import "JXShareListVC.h"
  9. #import "JXMyTools.h"
  10. @implementation JXShareListVC
  11. - (instancetype)init{
  12. self = [super init];
  13. if (self) {
  14. self.view.frame = [UIScreen mainScreen].bounds;
  15. self.title = nil;
  16. _pSelf = self;
  17. }
  18. return self;
  19. }
  20. - (void)viewWillAppear:(BOOL)animated{
  21. [super viewWillAppear:animated];
  22. [self customView];
  23. [self showShareList];
  24. }
  25. - (void)customView{
  26. self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5];
  27. self.view.alpha = 0;
  28. UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideShareList)];
  29. [self.view addGestureRecognizer:tapGes];
  30. //底部选择项
  31. _listView = [[UIView alloc] initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT, JX_SCREEN_WIDTH, 0)];
  32. _listView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.9];
  33. [self.view addSubview:_listView];
  34. // [_listView release];
  35. // _listView.backgroundColor = [UIColor cyanColor];
  36. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _listView.frame.size.width, LINE_WH)];
  37. topLine.backgroundColor = THE_LINE_COLOR;
  38. [_listView addSubview:topLine];
  39. // [topLine release];
  40. //分享按钮
  41. NSArray *imgArray = @[@"ic_share_wechat",@"ic_share_moment"/*,@"ic_share_weibo",@"facebook",@"twitter",@"whatsapp",@"ic_share_sms",@"ic_share_line"*/];
  42. NSArray *titleArray = @[Localized(@"WeChatFriend"),Localized(@"WeChatMoment")/*,Localized(@"SinaWeibo"),Localized(@"FaceBook"),Localized(@"Twitter"),Localized(@"WhatsApp"),Localized(@"SMS"),Localized(@"Line")*/];
  43. CGFloat btnWidth = _listView.frame.size.width/4;
  44. CGFloat btnHeight = 90;
  45. for (int i=0; i<imgArray.count; i++) {
  46. UIButton *shareItemBtn = [[UIButton alloc] initWithFrame:CGRectMake(i%4*btnWidth, i/4*btnHeight, btnWidth, btnHeight)];
  47. shareItemBtn.tag = i;
  48. [shareItemBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  49. [_listView addSubview:shareItemBtn];
  50. // [shareItemBtn release];
  51. // shareItemBtn.backgroundColor = [UIColor cyanColor];
  52. UIImageView *itemImg = [[UIImageView alloc] initWithFrame:CGRectMake((shareItemBtn.frame.size.width-50)/2, 15, 50, 50)];
  53. //itemImg.center = CGPointMake(shareItemBtn.center.x, itemImg.center.y);
  54. itemImg.image = [UIImage imageNamed:imgArray[i]];
  55. [shareItemBtn addSubview:itemImg];
  56. // [itemImg release];
  57. // itemImg.backgroundColor = [UIColor magentaColor];
  58. UILabel *itemLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, itemImg.frame.origin.y+itemImg.frame.size.height+10, shareItemBtn.frame.size.width, 15)];
  59. itemLabel.text = titleArray[i];
  60. itemLabel.font = SYSFONT(13);
  61. itemLabel.textAlignment = NSTextAlignmentCenter;
  62. [shareItemBtn addSubview:itemLabel];
  63. // [itemLabel release];
  64. // itemLabel.backgroundColor = [UIColor purpleColor];
  65. }
  66. CGRect frame = _listView.frame;
  67. frame.size.height = ((imgArray.count - 1)/4 + 1)*btnHeight;
  68. _listView.frame = frame;
  69. //取消
  70. UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, _listView.frame.size.height + 10, _listView.frame.size.width, 50)];
  71. [cancelBtn setTitle:Localized(@"JX_Cencal") forState:UIControlStateNormal];
  72. [cancelBtn setTitleColor:[UIColor colorWithRed:15/255.0 green:-97/255.0 blue:-94/255.0 alpha:1] forState:UIControlStateNormal];
  73. cancelBtn.titleLabel.font = SYSFONT(16);
  74. [cancelBtn addTarget:self action:@selector(hideShareList) forControlEvents:UIControlEventTouchUpInside];
  75. [_listView addSubview:cancelBtn];
  76. // [cancelBtn release];
  77. UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cancelBtn.frame.size.width, LINE_WH)];
  78. bottomLine.backgroundColor = THE_LINE_COLOR;
  79. [cancelBtn addSubview:bottomLine];
  80. // [bottomLine release];
  81. frame.size.height = cancelBtn.frame.origin.y + cancelBtn.frame.size.height;
  82. if (THE_DEVICE_HAVE_HEAD) {
  83. frame.size.height += 35;
  84. }
  85. _listView.frame = frame;
  86. }
  87. //分享按钮点击事件
  88. - (void)shareBtnClick:(UIButton *)shareBtn{
  89. if ([self.shareListDelegate respondsToSelector:@selector(didShareBtnClick:)]) {
  90. [self.shareListDelegate didShareBtnClick:shareBtn];
  91. }
  92. [self hideShareList];
  93. }
  94. //显示分享列表
  95. - (void)showShareList{
  96. [UIView animateWithDuration:0.2 animations:^{
  97. self.view.alpha = 1;
  98. CGRect frame = _listView.frame;
  99. frame.origin.y = JX_SCREEN_HEIGHT - frame.size.height;
  100. _listView.frame = frame;
  101. }];
  102. }
  103. //隐藏分享列表
  104. - (void)hideShareList{
  105. [UIView animateWithDuration:0.2 animations:^{
  106. self.view.alpha = 0;
  107. CGRect frame = _listView.frame;
  108. frame.origin.y = JX_SCREEN_HEIGHT;
  109. _listView.frame = frame;
  110. }completion:^(BOOL finished) {
  111. [self.view removeFromSuperview];
  112. _pSelf = nil;
  113. }];
  114. }
  115. - (void)dealloc {
  116. NSLog(@"JXShareListVC -- dealloc");
  117. }
  118. /*
  119. // Only override drawRect: if you perform custom drawing.
  120. // An empty implementation adversely affects performance during animation.
  121. - (void)drawRect:(CGRect)rect {
  122. // Drawing code
  123. }
  124. */
  125. @end