JXLinksShareVC.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // JXLinksShareVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/3/11.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXLinksShareVC.h"
  9. #define SHARE_HEIGHT 30 // 每个图片的宽度
  10. #define SHARE_TEXT_WIDTH 60 // 每个文字的宽度
  11. #define SELECTIMAGE_HEIGHT (SHARE_HEIGHT+40) // 每个单格的高度
  12. #define TOP_INSET 25 // 间隔
  13. @interface JXLinksShareVC ()
  14. @property (nonatomic, strong) UIView *bigView;
  15. @property (nonatomic, assign) CGFloat bigH;
  16. @end
  17. @implementation JXLinksShareVC
  18. - (instancetype)init {
  19. if (self = [super init]) {
  20. }
  21. return self;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.bigH = SELECTIMAGE_HEIGHT*3+32+TOP_INSET*3 + (THE_DEVICE_HAVE_HEAD ? 50 : TOP_INSET);
  26. self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  27. self.bigView = [[UIView alloc] init];
  28. self.bigView.frame = CGRectMake(0, JX_SCREEN_HEIGHT, JX_SCREEN_WIDTH, self.bigH);
  29. self.bigView.backgroundColor = [UIColor whiteColor];
  30. [self.view addSubview:self.bigView];
  31. [self setPartRoundWithView:self.bigView corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:17.f];
  32. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didBigView)];
  33. [self.bigView addGestureRecognizer:tap];
  34. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didView)];
  35. [self.view addGestureRecognizer:tap1];
  36. [self setupViews];
  37. }
  38. - (void)didBigView {
  39. // 点击bigview,不做处理。 优化体验, 防止每次点击到bigview 都会隐藏bigview
  40. }
  41. - (void)didView {
  42. [self hideShareView];
  43. }
  44. - (void)viewDidAppear:(BOOL)animated {
  45. [super viewDidAppear:animated];
  46. [UIView animateWithDuration:.3f animations:^{
  47. self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
  48. self.bigView.frame = CGRectMake(0, JX_SCREEN_HEIGHT-self.bigH, JX_SCREEN_WIDTH, self.bigH);
  49. }];
  50. }
  51. // 画圆角
  52. - (void)setPartRoundWithView:(UIView *)view corners:(UIRectCorner)corners cornerRadius:(float)cornerRadius {
  53. CAShapeLayer *shapeLayer = [CAShapeLayer layer];
  54. shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)].CGPath;
  55. view.layer.mask = shapeLayer;
  56. }
  57. - (void)setupViews {
  58. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 18, JX_SCREEN_WIDTH, 14)];
  59. NSString *url = self.titleStr;
  60. if ([[NSURL URLWithString:self.titleStr] host] && [[NSURL URLWithString:self.titleStr] host].length > 0) {
  61. url = [[NSURL URLWithString:self.titleStr] host];
  62. }
  63. title.text = [NSString stringWithFormat:Localized(@"JX_ThisPageProvidedBy%@"),url];
  64. title.font = SYSFONT(13);
  65. title.textColor = [HEXCOLOR(0x333333) colorWithAlphaComponent:0.3];
  66. title.textAlignment = NSTextAlignmentCenter;
  67. [self.bigView addSubview:title];
  68. NSArray *images = @[self.isFloatWindow ? @"im_linksShare_un_float" : @"im_linksShare_float",@"im_linksShare_send_friend",@"im_linksShare_life",@"im_linksShare_safari",@"im_linksShare_send_friend_WX",@"im_linksShare_life_WX",@"im_linksShare_collection",@"im_linksShare_complaint",@"im_linksShare_link",@"im_linksShare_update",@"im_linksShare_search",@"im_linksShare_type"];
  69. NSArray *titles = @[self.isFloatWindow ? [NSString stringWithFormat:@"%@%@",Localized(@"JX_Close"),Localized(@"JX_FloatingWindow")] : Localized(@"JX_FloatingWindow"),Localized(@"JXSendToFriend"),Localized(@"JX_ShareLifeCircle"),Localized(@"JX_OpenInSafari"),Localized(@"JXSendToWXFriend"),Localized(@"JX_ShareLifeWXCircle"),@"收藏网址",Localized(@"UserInfoVC_Complaint"),[NSString stringWithFormat:@"%@%@",Localized(@"JX_Copy"),Localized(@"JXLink")],Localized(@"JX_Refresh"),Localized(@"JX_SearchPageContent"),Localized(@"JX_AdjustTheFont")];
  70. NSArray *sels = @[@"onFloatWindow",@"onSend",@"onShare",@"onSafari",@"onWXSend",@"onWXShare",@"onCollection",@"onReport",@"onPasteboard",@"onUpdate",@"onSearch",@"onTextType"];
  71. UIView *btn;
  72. int lineCount = 4; // 每行个数
  73. int inset = 15; // 左右间隔
  74. int lineInset = TOP_INSET; // 行间隔
  75. int topInset = CGRectGetMaxY(title.frame)+lineInset; // 顶部间隔
  76. CGFloat w = (JX_SCREEN_WIDTH-inset*(lineCount+1))/lineCount;// 每个宽度
  77. for (int i = 0; i < 12; i++) {
  78. CGFloat x = (w+inset)*(i % lineCount)+inset;
  79. int m = i / lineCount;
  80. CGFloat y = topInset+m*SELECTIMAGE_HEIGHT+(lineInset * m);
  81. SEL sle = NSSelectorFromString(sels[i]);
  82. btn = [self createButtonWithFrame:CGRectMake(x, y, w, SELECTIMAGE_HEIGHT) image:images[i] highlight:images[i] target:self.delegate selector:sle title:titles[i]];
  83. }
  84. }
  85. - (UIView *)createButtonWithFrame:(CGRect)frame
  86. image:(NSString *)normalImage
  87. highlight:(NSString *)clickIamge
  88. target:(id)target
  89. selector:(SEL)selector
  90. title:(NSString*)title
  91. {
  92. UIView* v = [[UIView alloc]initWithFrame:frame];
  93. [self.bigView addSubview:v];
  94. UIButton* btn = [UIFactory createButtonWithImage:normalImage highlight:clickIamge target:target selector:selector];
  95. btn.frame = CGRectMake((frame.size.width-SHARE_HEIGHT)/2, 0, SHARE_HEIGHT, SHARE_HEIGHT);
  96. [v addSubview:btn];
  97. CGSize size = [title boundingRectWithSize:CGSizeMake(frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(12)} context:nil].size;
  98. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame)+10, frame.size.width, size.height)];
  99. p.center = CGPointMake(btn.center.x, p.center.y);
  100. p.text = title;
  101. p.numberOfLines = 0;
  102. p.font = SYSFONT(11);
  103. p.textColor = HEXCOLOR(0x666666);
  104. p.textAlignment = NSTextAlignmentCenter;
  105. [v addSubview:p];
  106. CGRect frameV = v.frame;
  107. frameV.size.height = CGRectGetMaxY(p.frame);
  108. v.frame = frameV;
  109. return v;
  110. }
  111. - (void)hideShareView {
  112. [self hide];
  113. }
  114. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  115. }
  116. - (void)hide {
  117. [UIView animateWithDuration:.3f animations:^{
  118. self.bigView.frame = CGRectMake(0, JX_SCREEN_HEIGHT, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  119. self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  120. } completion:^(BOOL finished) {
  121. [self dismissViewControllerAnimated:YES completion:nil];
  122. if (self) {
  123. [self.view removeFromSuperview];
  124. }
  125. }];
  126. }
  127. @end