MHSpecificAssembleView.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // MHSpecificAssembleView.m
  3. //特效合集
  4. #import "MHSpecificAssembleView.h"
  5. #import "MHBeautyParams.h"
  6. #import "MHPrintView.h"
  7. #import "MHSpecificEffectView.h"
  8. #import "WNSegmentControl.h"
  9. #import "MHBeautiesModel.h"
  10. #import "MHMagnifiedView.h"
  11. ///修改MHUI
  12. #import "MHBottomView.h"
  13. #import "MHActionView.h"
  14. #import <MHBeautySDK/MHSDK.h>
  15. @interface MHSpecificAssembleView ()<MHSpecificEffectViewDelegate,MHPrintViewDelegate,MHActionViewDelegate,MHMagnifiedViewDelegate>
  16. @property (nonatomic, strong) MHSpecificEffectView *specificView;//特效
  17. @property (nonatomic, strong) MHPrintView *printView;//水印
  18. @property (nonatomic, strong) MHMagnifiedView *magnifiedView;//哈哈镜
  19. @property (nonatomic, strong) UIView *lineView;
  20. @property (nonatomic, strong) NSMutableArray * viewsArray;
  21. @property (nonatomic, strong) UIView *lastView;
  22. @property (nonatomic, strong) WNSegmentControl *segmentControl;
  23. ///修改MHUI
  24. @property (nonatomic, strong) MHBottomView * bottomView;
  25. @property (nonatomic, strong) MHActionView * stickerView;//动作
  26. @property (nonatomic, assign) int sdkLevelTYpe;///<sdk类型
  27. @end
  28. @implementation MHSpecificAssembleView
  29. - (instancetype)initWithFrame:(CGRect)frame {
  30. if (self = [super initWithFrame:frame]) {
  31. self.backgroundColor = [UIColor clearColor];
  32. self.alpha = 1;
  33. [self addSubview:self.segmentControl];
  34. [self addSubview:self.lineView];
  35. ///修改MHUI
  36. if (isNeedBottom) {
  37. [self addSubview:self.bottomView];
  38. }
  39. [self addSubview:self.viewsArray[0]];
  40. }
  41. return self;
  42. }
  43. - (void)getActionSource{
  44. [self.stickerView getSticks];
  45. }
  46. - (void)clearAllActionEffects{
  47. [self.stickerView clearAllActionEffects];
  48. }
  49. #pragma mark - Action
  50. - (void)switchList:(WNSegmentControl *)segmentControl {
  51. UIView *currentView = self.viewsArray[segmentControl.selectedSegmentIndex];
  52. if (![currentView isEqual:self.lastView]) {
  53. [self.lastView removeFromSuperview];
  54. }
  55. [self addSubview:currentView];
  56. self.lastView = currentView;
  57. }
  58. ///修改MHUI
  59. #pragma mark - 底部按钮响应
  60. - (void)cameraAction:(BOOL)isTakePhoto{
  61. NSLog(@"点击了拍照");
  62. if (isTakePhoto) {
  63. if ([self.delegate respondsToSelector:@selector(takePhoto)]) {
  64. [self.delegate takePhoto];
  65. }
  66. }else{
  67. if ([self.delegate respondsToSelector:@selector(clickPackUp)]) {
  68. [self.delegate clickPackUp];
  69. }
  70. }
  71. }
  72. #pragma mark - delegate
  73. //水印
  74. - (void)handlePrint:(MHBeautiesModel *)model {
  75. if ([self.delegate respondsToSelector:@selector(handleWatermarkWithModel:)]) {
  76. [self.delegate handleWatermarkWithModel:model];
  77. }
  78. }
  79. //特效
  80. - (void)handleSpecific:(NSInteger)type {
  81. if ([self.delegate respondsToSelector:@selector(handleSpecificWithType:)]) {
  82. [self.delegate handleSpecificWithType:type];
  83. }
  84. }
  85. //哈哈镜
  86. - (void)handleMagnify:(NSInteger)type withIsMenu:(BOOL)isMenu{
  87. if ([self.delegate respondsToSelector:@selector(handleMagnityWithType:)]) {
  88. [self.delegate handleMagnityWithType:type];
  89. }
  90. }
  91. #pragma mark - delegate
  92. - (void)handleStickerActionEffect:(NSString *)stickerContent sticker:(StickerDataListModel *)model action:(int)action{
  93. //NSLog(@"sss---%@",stickerContent);
  94. if (!IsStringWithAnyText(model.name) && !IsStringWithAnyText(model.resource) ) {
  95. if ([self.delegate respondsToSelector:@selector(handleSpecificStickerActionEffect: sticker:action:)]) {
  96. [self.delegate handleSpecificStickerActionEffect:@"" sticker:nil action:0];
  97. }
  98. } else {
  99. if ([self.delegate respondsToSelector:@selector(handleSpecificStickerActionEffect: sticker:action:)]) {
  100. [self.delegate handleSpecificStickerActionEffect:stickerContent sticker:model action:action];
  101. }
  102. }
  103. if (action==0) {
  104. if ([self.delegate respondsToSelector:@selector(handleSpecificStickerActionEffect: sticker:action:)]) {
  105. [self.delegate handleSpecificStickerActionEffect:@"" sticker:nil action:0];
  106. }
  107. }
  108. }
  109. #pragma mark - lazy
  110. //- (NSArray *)viewsArray {
  111. // if (!_viewsArray) {
  112. // _viewsArray = [NSMutableArray arrayWithArray: self.sdkLevelTYpe==1?@[self.specificView,self.printView,self.stickerView,self.magnifiedView]:@[self.specificView,self.printView]];
  113. // }
  114. // return _viewsArray;
  115. //}
  116. - (MHActionView*)stickerView{
  117. if (!_stickerView) {
  118. CGFloat bottom = _lineView.frame.origin.y + _lineView.frame.size.height;
  119. _stickerView = [[MHActionView alloc] initWithFrame:CGRectMake(0, bottom, window_width, MHSpecificAssembleViewHeight-bottom - MHBottomViewHeight)];
  120. _stickerView.delegate = self;
  121. }
  122. return _stickerView;
  123. }
  124. - (MHSpecificEffectView *)specificView {
  125. if (!_specificView) {
  126. ///修改MHUI
  127. CGFloat bottom = self.lineView.frame.origin.y + self.lineView.frame.size.height;
  128. _specificView = [[MHSpecificEffectView alloc] initWithFrame:CGRectMake(0, bottom, window_width, MHSpecificAssembleViewHeight-bottom - MHBottomViewHeight)];
  129. _specificView.delegate = self;
  130. }
  131. return _specificView;
  132. }
  133. - (MHPrintView *)printView {
  134. if (!_printView) {
  135. CGFloat bottom = _lineView.frame.origin.y + _lineView.frame.size.height;
  136. _printView = [[MHPrintView alloc] initWithFrame:CGRectMake(0, bottom, window_width, MHSpecificAssembleViewHeight-bottom - MHBottomViewHeight)];
  137. _printView.delegate = self;
  138. }
  139. return _printView;
  140. }
  141. - (MHMagnifiedView *)magnifiedView {
  142. if (!_magnifiedView) {
  143. CGFloat bottom = _lineView.frame.origin.y + _lineView.frame.size.height;
  144. _magnifiedView = [[MHMagnifiedView alloc] initWithFrame:CGRectMake(0, bottom, window_width, MHSpecificAssembleViewHeight-bottom - MHBottomViewHeight)];
  145. _magnifiedView.delegate = self;
  146. _magnifiedView.isHiddenHead = YES;
  147. }
  148. return _magnifiedView;
  149. }
  150. - (WNSegmentControl *)segmentControl {
  151. if (!_segmentControl) {
  152. _viewsArray = [NSMutableArray array];
  153. NSMutableArray * selectedItem = [MHSDK shareInstance].effectMenuArray;
  154. NSMutableArray * nameArr = [NSMutableArray array];
  155. for (int i = 0; i < selectedItem.count; i ++) {
  156. NSDictionary * itemDic = selectedItem[i];
  157. NSString * itemName = itemDic[@"name"];
  158. [nameArr addObject:itemName];
  159. }
  160. _segmentControl = [[WNSegmentControl alloc] initWithTitles:nameArr];
  161. _segmentControl.frame = CGRectMake(0, 0, window_width, MHStickerSectionHeight);
  162. ///修改MHUI
  163. _segmentControl.backgroundColor = [UIColor clearColor];
  164. [_segmentControl setTextAttributes:@{NSFontAttributeName: Font_12, NSForegroundColorAttributeName: FontColorBlackNormal}
  165. forState:UIControlStateNormal];
  166. [_segmentControl setTextAttributes:@{NSFontAttributeName: Font_12, NSForegroundColorAttributeName: FontColorSelected}
  167. forState:UIControlStateSelected];
  168. _segmentControl.selectedSegmentIndex = 0;
  169. _segmentControl.widthStyle = WNSegmentedControlWidthStyleFixed;
  170. [_segmentControl addTarget:self action:@selector(switchList:) forControlEvents:UIControlEventValueChanged];
  171. NSArray * items = @[@{@"特效":self.specificView},@{@"水印":self.printView},@{@"动作":self.stickerView},@{@"哈哈镜":self.magnifiedView}];
  172. for (int i = 0; i < selectedItem.count; i ++) {
  173. NSDictionary * itemDic = selectedItem[i];
  174. NSString * itemName = itemDic[@"name"];
  175. for (int j = 0; j < items.count; j ++) {
  176. NSDictionary * itemDic = items[j];
  177. if ([itemDic.allKeys[0] isEqual:itemName]) {
  178. [_viewsArray addObject:itemDic.allValues[0]];
  179. }
  180. }
  181. }
  182. self.lastView = self.viewsArray[0];
  183. }
  184. return _segmentControl;
  185. }
  186. - (UIView *)lineView {
  187. if (!_lineView) {
  188. CGFloat bottom = _segmentControl.frame.origin.y + _segmentControl.frame.size.height;
  189. _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, bottom, window_width, 0.5)];
  190. _lineView.backgroundColor = LineColor;
  191. }
  192. return _lineView;
  193. }
  194. ///修改MHUI
  195. - (MHBottomView*)bottomView{
  196. if (!_bottomView) {
  197. __weak typeof(self) weakSelf = self;
  198. CGFloat bottom = _specificView.frame.origin.y + _specificView.frame.size.height;
  199. _bottomView = [[MHBottomView alloc] initWithFrame:CGRectMake(0, bottom, window_width, MHBottomViewHeight)];
  200. _bottomView.clickBtn = ^(BOOL isTakePhoto) {
  201. [weakSelf cameraAction:isTakePhoto];
  202. };
  203. }
  204. return _bottomView;
  205. }
  206. - (int)sdkLevelTYpe{
  207. return [[MHSDK shareInstance] getSDKLevel];
  208. }
  209. @end