TimeSelectView.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // TimeSelectView.m
  3. // TXLiteAVDemo_Enterprise
  4. //
  5. // Created by xiang zhang on 2017/10/27.
  6. // Copyright © 2017年 Tencent. All rights reserved.
  7. //
  8. #import "TimeSelectView.h"
  9. //#import "UIView+AdditionsX12.h"
  10. #import "ColorMacro.h"
  11. #define EFFCT_COUNT 4
  12. #define EFFCT_IMAGE_WIDTH 60 * kScaleY
  13. #define EFFCT_IMAGE_SPACE 20
  14. @implementation TimeSelectView
  15. {
  16. UIView *_allSub;
  17. UILabel *_titleL;
  18. UIScrollView *_effectSelectView;
  19. }
  20. - (instancetype)initWithFrame:(CGRect)frame
  21. {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. _allSub = [[UIView alloc]initWithFrame:CGRectMake(0, (self.height-55-EFFCT_IMAGE_WIDTH)/2, self.width, 30+5+EFFCT_IMAGE_WIDTH+20)];
  25. _allSub.backgroundColor = [UIColor clearColor];
  26. [self addSubview:_allSub];
  27. _titleL = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, self.width-30, 30)];
  28. _titleL.text = YZMsg(@"点击选择特效");
  29. _titleL.font = SYS_Font(16);
  30. _titleL.textColor = [UIColor whiteColor];
  31. [_allSub addSubview:_titleL];
  32. //按钮左右空隙
  33. CGFloat space = (self.width - EFFCT_IMAGE_WIDTH * EFFCT_COUNT) / (EFFCT_COUNT + 1);
  34. _effectSelectView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,_titleL.bottom+5, self.width,EFFCT_IMAGE_WIDTH+20)];//动图高度(EFFCT_IMAGE_WIDTH)+标题高度(20)
  35. _effectSelectView.backgroundColor = [UIColor clearColor];
  36. [_allSub addSubview:_effectSelectView];
  37. /** 测试记录
  38. * 1017 只是相册视频 时光倒流不能使用
  39. * 1018 时光倒流 功能旧版SDK已经不再支持了
  40. * 腾讯建议升级sdk “倒放功能吃内存厉害,我们在最近的几个版本已经更新(5.2)”
  41. * 19-2-15 更新收费版时光倒流可以使用
  42. */
  43. NSArray *effectNameS = @[YZMsg(@"无"),YZMsg(@"时光倒流"),YZMsg(@"反复"),YZMsg(@"慢动作")];
  44. // NSArray *effectNameS = @[@"无",@"反复",@"慢动作"];
  45. //无-倒放-反复-慢动作
  46. UIImage *noImg = [UIImage sd_imageWithGIFData:[PublicObj gifConvertDataWithName:@"时间特效-无"]];
  47. UIImage *dlImg = [UIImage sd_imageWithGIFData:[PublicObj gifConvertDataWithName:@"时间特效-时光倒流"]];
  48. UIImage *ffImg = [UIImage sd_imageWithGIFData:[PublicObj gifConvertDataWithName:@"时间特效-反复"]];
  49. UIImage *mdzImg = [UIImage sd_imageWithGIFData:[PublicObj gifConvertDataWithName:@"时间特效-慢动作"]];
  50. NSArray *gifImgs = @[noImg,dlImg,ffImg,mdzImg];
  51. // NSArray *gifImgs = @[noImg,ffImg,mdzImg];
  52. for (int i = 0 ; i < EFFCT_COUNT ; i ++){
  53. UIImageView *selImg = [[UIImageView alloc]initWithFrame:CGRectMake(space + (space + EFFCT_IMAGE_WIDTH) * i, 0, EFFCT_IMAGE_WIDTH, EFFCT_IMAGE_WIDTH)];
  54. [selImg setImage:gifImgs[i]];
  55. //gif有白边做个线圈遮挡毛边
  56. UIImageView *selbg = [[UIImageView alloc]initWithFrame:CGRectMake(space + (space + EFFCT_IMAGE_WIDTH) * i+3.5, 0+3.5, EFFCT_IMAGE_WIDTH-7, EFFCT_IMAGE_WIDTH-7)];
  57. selbg.layer.masksToBounds = YES;
  58. selbg.layer.cornerRadius = EFFCT_IMAGE_WIDTH/2-3.5;
  59. selbg.layer.borderColor = [UIColor whiteColor].CGColor;
  60. selbg.layer.borderWidth = 1.5;
  61. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  62. btn.frame = CGRectMake(space + (space + EFFCT_IMAGE_WIDTH) * i+0.5, 0+0.5, EFFCT_IMAGE_WIDTH-1, EFFCT_IMAGE_WIDTH-1);
  63. [btn setImage:[UIImage imageNamed:@"时间特效-选中"] forState:0];
  64. btn.tag = i+180705;
  65. [btn addTarget:self action:@selector(onBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  66. UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(btn.left, btn.bottom-2, btn.width, 20)];
  67. title.text = effectNameS[i];
  68. title.font = SYS_Font(14);
  69. if (IS_IPHONE_5) {
  70. title.font = SYS_Font(12);
  71. }
  72. title.textAlignment = NSTextAlignmentCenter;
  73. title.textColor = [UIColor whiteColor];
  74. [_effectSelectView addSubview:selImg];
  75. [_effectSelectView addSubview:selbg];
  76. [_effectSelectView addSubview:btn];
  77. [_effectSelectView addSubview:title];
  78. }
  79. UIButton *selBtn = (UIButton *)[self viewWithTag:180705];
  80. [self resetBtnColor:selBtn];
  81. }
  82. return self;
  83. }
  84. - (void)onBtnClick:(UIButton *)btn {
  85. //1017只是相册视频 时光倒流不能使用
  86. // if(_isAlbum && btn.tag == 180706){
  87. // [MBProgressHUD showPop:@"本地视频不支持时光倒流"];
  88. // return;
  89. // }
  90. if (btn.tag == 180705) {
  91. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTimeEffectsSpeed)]) {
  92. [_delegate onVideoTimeEffectsClear];
  93. }
  94. }
  95. else if (btn.tag == 180707){
  96. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTimeEffectsBackPlay)]) {
  97. [_delegate onVideoTimeEffectsRepeat];
  98. }
  99. }
  100. else if (btn.tag == 180708){
  101. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTimeEffectsRepeat)]) {
  102. [_delegate onVideoTimeEffectsSpeed];
  103. }
  104. }
  105. /** 测试记录
  106. * 1017 只是相册视频 时光倒流不能使用
  107. * 1018 时光倒流 功能旧版SDK已经不再支持了
  108. * 腾讯建议升级sdk “倒放功能吃内存厉害,我们在最近的几个版本已经更新(5.2)”
  109. * 19-2-15 更新收费版时光倒流可以使用
  110. */
  111. else if (btn.tag == 180706) {
  112. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTimeEffectsSpeed)]) {
  113. [_delegate onVideoTimeEffectsBackPlay];
  114. }
  115. }
  116. [self resetBtnColor:btn];
  117. }
  118. - (void)resetBtnColor:(UIButton *)btn {
  119. for (UIButton * subBtn in _effectSelectView.subviews) {
  120. if ([subBtn isKindOfClass:[UIButton class]]) {
  121. [subBtn setImage:[UIImage imageNamed:@"1"] forState:0];
  122. }
  123. }
  124. [btn setImage:[UIImage imageNamed:@"时间特效-选中"] forState:0];
  125. }
  126. @end