UGCKitPhotoTransitionToolbar.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2019 Tencent. All rights reserved.
  2. #import "UGCKitPhotoTransitionToolbar.h"
  3. #import "UGCKit_UIViewAdditions.h"
  4. #import "UGCKitColorMacro.h"
  5. #import "UGCKitVerticalButton.h"
  6. #define TRANSITIN_IMAGE_WIDTH 50 * kScaleY
  7. #define TRANSITIN_IMAGE_SPACE 10
  8. @implementation UGCKitPhotoTransitionToolbar
  9. {
  10. UIScrollView *_transitionView;
  11. }
  12. - (instancetype)initWithFrame:(CGRect)frame theme:(UGCKitTheme *)theme
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. _theme = theme;
  17. NSArray *transitionNames = @[[_theme localizedString:@"UGCKit.PhotoTransition.Horizontal"],
  18. [_theme localizedString:@"UGCKit.PhotoTransition.Vertical"],
  19. [_theme localizedString:@"UGCKit.PhotoTransition.ZoomIn"],
  20. [_theme localizedString:@"UGCKit.PhotoTransition.ZoomOut"],
  21. [_theme localizedString:@"UGCKit.PhotoTransition.Rotation"],
  22. [_theme localizedString:@"UGCKit.PhotoTransition.FadeInFadeOut"]];
  23. NSArray<UIImage *> *images = @[theme.transitionLeftRightIcon,
  24. theme.transitionUpDownIcon,
  25. theme.transitionZoomInIcon,
  26. theme.transitionZoomOutIcon,
  27. theme.transitionRotateIcon,
  28. theme.transitionFadeInOutIcon
  29. ];
  30. NSAssert(transitionNames.count == images.count, @"Count mismatch, please check");
  31. _transitionView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.ugckit_width,TRANSITIN_IMAGE_WIDTH)];
  32. _transitionView.showsVerticalScrollIndicator = NO;
  33. _transitionView.showsHorizontalScrollIndicator = NO;
  34. CGFloat itemWidth = floor(frame.size.width / images.count);
  35. CGFloat halfSpace = 2;
  36. for (int i = 0 ; i < transitionNames.count ; i ++){
  37. UIButton *btn = [[UGCKitVerticalButton alloc] initWithTitle:transitionNames[i]];
  38. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  39. btn.titleLabel.adjustsFontSizeToFitWidth = YES;
  40. [btn setImage:images[i] forState:UIControlStateNormal];
  41. [btn setTitleColor:theme.titleColor forState:UIControlStateSelected];
  42. btn.tag = i;
  43. [btn setFrame:CGRectMake(itemWidth * i + halfSpace, 0, itemWidth - halfSpace * 2, TRANSITIN_IMAGE_WIDTH)];
  44. [btn addTarget:self action:@selector(onBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  45. [_transitionView addSubview:btn];
  46. if (i == 0) {
  47. [self resetBtnColor:btn];
  48. }
  49. }
  50. [self addSubview:_transitionView];
  51. }
  52. return self;
  53. }
  54. - (void)onBtnClick:(UIButton *)btn
  55. {
  56. if (btn.tag == 0) {
  57. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionUpDownSlipping)]) {
  58. [_delegate onVideoTransitionLefRightSlipping];
  59. }
  60. }
  61. else if (btn.tag == 1) {
  62. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionUpDownSlipping)]) {
  63. [_delegate onVideoTransitionUpDownSlipping];
  64. }
  65. }
  66. else if (btn.tag == 2){
  67. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionEnlarge)]) {
  68. [_delegate onVideoTransitionEnlarge];
  69. }
  70. }
  71. else if (btn.tag == 3){
  72. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionNarrow)]) {
  73. [_delegate onVideoTransitionNarrow];
  74. }
  75. }
  76. else if (btn.tag == 4){
  77. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionNarrow)]) {
  78. [_delegate onVideoTransitionRotationalScaling];
  79. }
  80. }
  81. else if (btn.tag == 5){
  82. if (_delegate && [_delegate respondsToSelector:@selector(onVideoTransitionNarrow)]) {
  83. [_delegate onVideoTransitionFadeinFadeout];
  84. }
  85. }
  86. [self resetBtnColor:btn];
  87. }
  88. - (void)resetBtnColor:(UIButton *)btn
  89. {
  90. for (UIButton * btn in _transitionView.subviews) {
  91. btn.selected = NO;
  92. }
  93. btn.selected = YES;
  94. }
  95. @end