PopMenuCenter.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. //
  2. // PopMenuCenter.m
  3. // BuguLive
  4. //
  5. // Created by 岳克奎 on 17/3/10.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "PopMenuCenter.h"
  9. #import<AssetsLibrary/AssetsLibrary.h>
  10. #import "PublishLivestViewController.h"
  11. #import "AgreementViewController.h"
  12. //#import "TCVideoRecordViewController.h"
  13. @implementation PopMenuCenter
  14. #pragma mark ----------------------- life cycle生命周期管控区域 -------------------
  15. /**
  16. * @brief: 单利
  17. *
  18. * @discussion:我的想法是,用单例管理,这样能够通过的player对应的控制器来控制。播放,暂停。如果不这样,需要频繁的
  19. */
  20. static PopMenuCenter *signleton = nil;
  21. + (instancetype)allocWithZone:(struct _NSZone *)zone
  22. {
  23. static dispatch_once_t onceToken;
  24. dispatch_once(&onceToken, ^{
  25. signleton = [super allocWithZone:zone];
  26. });
  27. return signleton;
  28. }
  29. +(PopMenuCenter *)sharePopMenuCenter
  30. {
  31. static dispatch_once_t onceToken;
  32. dispatch_once(&onceToken, ^{
  33. signleton = [[self alloc] init];
  34. });
  35. return signleton;
  36. }
  37. + (id)copyWithZone:(struct _NSZone *)zone
  38. {
  39. return signleton;
  40. }
  41. + (id)mutableCopyWithZone:(struct _NSZone *)zone
  42. {
  43. return signleton;
  44. }
  45. #pragma mark ********************************** Delegate 协议区域**************************
  46. #pragma mark ----------- <STPop的menu菜单delegate>
  47. /**
  48. * @brief: 根据点击索引,加载对应模块
  49. * @prama: popMenuView 动态菜单底层管理层
  50. * @prama: index 点击索引
  51. */
  52. -(void)popMenuView:(HyPopMenuView *)popMenuView didSelectItemAtIndex:(NSUInteger)index{
  53. //开直播
  54. if (index == 0)
  55. {
  56. IMALoginParam *loginParam = [IMALoginParam loadFromLocal];
  57. if (loginParam.isAgree ==1)
  58. {
  59. if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) {
  60. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")];
  61. return;
  62. }
  63. PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init];
  64. [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{
  65. }];
  66. }
  67. else
  68. {
  69. AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES];
  70. [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{
  71. }];
  72. }
  73. }
  74. //小视频
  75. else if (index== 1)
  76. {
  77. [self showVideoDynamicViewC];
  78. }
  79. }
  80. #pragma mark **************************** Private methods 私有方法区域*********************
  81. #pragma mark -加载前PopView权限与判断
  82. -(void)showPopView
  83. {
  84. ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];//获取权限状态
  85. if(author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied)//无权限
  86. {
  87. //无权限
  88. }
  89. // iOS 8 后,全部都要授权
  90. AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  91. switch (status)
  92. {
  93. case AVAuthorizationStatusNotDetermined:
  94. {
  95. // 许可对话没有出现,发起授权许可
  96. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  97. if (granted)
  98. {
  99. //第一次用户接
  100. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  101. [self showMenu];
  102. });
  103. }else
  104. {
  105. //用户拒绝
  106. }
  107. }];
  108. break;
  109. }
  110. case AVAuthorizationStatusAuthorized:
  111. {
  112. [self showMenu];// 已经开启授权,可继续
  113. break;
  114. }
  115. case AVAuthorizationStatusDenied:
  116. case AVAuthorizationStatusRestricted:
  117. // 用户明确地拒绝授权,或者相机设备无法访问
  118. if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusDenied || AVAuthorizationStatusRestricted)
  119. {
  120. UIAlertController *alertC = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"相册权限")message:ASLocalizedString(@"无法访问相册,请在系统设置中允许访问")preferredStyle:UIAlertControllerStyleAlert];
  121. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  122. }];
  123. [alertC addAction:cancelAction];
  124. UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"设置")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  125. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  126. [[UIApplication sharedApplication] openURL:url];
  127. }];
  128. [alertC addAction:confirmAction];
  129. [[AppDelegate sharedAppDelegate] presentViewController:alertC
  130. animated:YES
  131. completion:nil];
  132. }
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. #pragma mark- 加载PopView
  139. -(void)showMenu
  140. {
  141. if (!_menu)
  142. {
  143. [self menu];
  144. }
  145. NSMutableArray *tempDSMArray = @[].mutableCopy;
  146. NSMutableArray *picStrMArray = @[@"st_play_live",
  147. @"st_vedio_goods",
  148. ].mutableCopy;
  149. NSMutableArray *titleStrMArray = @[ASLocalizedString(@"发起直播"),
  150. ASLocalizedString(@"发布短视频"),
  151. ].mutableCopy;
  152. if (picStrMArray.count == titleStrMArray.count)
  153. {
  154. for (int i = 0;i<picStrMArray.count;i++)
  155. {
  156. [tempDSMArray addObject: [PopMenuModel
  157. allocPopMenuModelWithImageNameString:picStrMArray[i]
  158. AtTitleString:titleStrMArray[i]
  159. AtTextColor:kAppGrayColor1
  160. AtTransitionType:PopMenuTransitionTypeSystemApi
  161. AtTransitionRenderingColor:nil]];
  162. }
  163. }
  164. _menu.dataSource = tempDSMArray.copy;
  165. [_menu openMenu];
  166. }
  167. #pragma mark - 5 - 视频动态页面
  168. -(void)showVideoDynamicViewC
  169. {
  170. self.videoDynamicViewC = (VideoDynamicViewC *)[VideoDynamicViewC showSTBaseViewCOnSuperViewC:_tabBarC.selectedViewController
  171. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  172. andSTViewCTransitionType:STViewCTransitionTypeOfModal
  173. andComplete:^(BOOL finished,
  174. STBaseViewC *stBaseViewC) {
  175. }];
  176. self.videoDynamicViewC.recordTabBarC = _tabBarC;
  177. [self.videoDynamicViewC videoDynamicView];
  178. // 开启IQ
  179. self.videoDynamicViewC.isOpenIQKeyboardManager = YES;
  180. // 加载View层
  181. //[videoDynamicViewC graphicDynamicView];
  182. //跳转
  183. //找到当前ViewC
  184. UIViewController *currentViewC = _tabBarC.selectedViewController.childViewControllers[0];
  185. //TabBarc隐藏
  186. currentViewC.hidesBottomBarWhenPushed=YES;
  187. currentViewC.navigationController.navigationBar.tintColor = kAppGrayColor1;
  188. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  189. self.videoDynamicViewC.title = ASLocalizedString(@"发布短视频");
  190. self.videoDynamicViewC.navigationController.navigationBar.tintColor =kAppGrayColor1;
  191. //改变颜色 必须跳转后
  192. self.videoDynamicViewC.navigationController.navigationBar.hidden = NO;
  193. [self.videoDynamicViewC.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:kAppGrayColor1}];
  194. currentViewC.hidesBottomBarWhenPushed=NO;
  195. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  196. [headImgSheet addButtonWithTitle:ASLocalizedString(@"拍摄视频")];
  197. [headImgSheet addButtonWithTitle:ASLocalizedString(@"相册中获取视频")];
  198. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  199. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  200. headImgSheet.delegate = self;
  201. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  202. }
  203. //VideoDynamicViewC
  204. #pragma mark ****************************** Setter ******************************
  205. // 外部控制菜单弹出
  206. -(void)setStPopMenuShowState:(STPopMenuShowState)stPopMenuShowState
  207. {
  208. if (!_menu)
  209. {
  210. [self menu];
  211. }
  212. switch (stPopMenuShowState)
  213. {
  214. case STPopMenuHidden:
  215. [_menu closeMenu];
  216. break;
  217. case STPopMenuShow:
  218. [self showPopView];
  219. break;
  220. default:
  221. break;
  222. }
  223. _stPopMenuShowState = stPopMenuShowState;
  224. }
  225. #pragma mark ***************************** Getter ****************************
  226. #pragma mark - pop menu 控制菜单View
  227. -(HyPopMenuView *)menu
  228. {
  229. if (!_menu)
  230. {
  231. _menu = [HyPopMenuView sharedPopMenuManager];
  232. _menu.delegate = self;
  233. _menu.popMenuSpeed = 12.0f;
  234. //自动填充颜色
  235. _menu.automaticIdentificationColor = false;
  236. //pop动画类型
  237. _menu.animationType = HyPopMenuViewAnimationTypeSina;
  238. _menu.backgroundType = HyPopMenuViewBackgroundTypeLightTranslucent;
  239. }
  240. return _menu;
  241. }
  242. #pragma mark ************************** Plublic 公有方法 **************************
  243. // 认证状态判断+未读动态数
  244. -(void)showCheckAuthentication:(void(^)(BOOL haveAuthentication,NSString *dynamicCountStr))block
  245. {
  246. [[NetHttpsManager manager]POSTWithParameters:@{@"ctl":@"publish",@"act":@"check_type",@"itype":@"xr"}.mutableCopy
  247. SuccessBlock:^(NSDictionary *responseJson) {
  248. if ([[responseJson allKeys]containsObject:@"status"]
  249. &&[responseJson[@"status"] integerValue] == 1
  250. &&[[responseJson allKeys]containsObject:@"info"]
  251. &&[responseJson[@"info"][@"is_authentication"] integerValue]==2)
  252. {
  253. if (block)
  254. {
  255. block(YES,responseJson[@"info"][@"weibo_count"]);
  256. }
  257. }else
  258. {
  259. if (block)
  260. {
  261. block(NO,responseJson[@"info"][@"weibo_count"]);
  262. }
  263. }
  264. } FailureBlock:^(NSError *error){
  265. if (block)
  266. {
  267. block(NO,@"0");
  268. }
  269. }];
  270. }
  271. #pragma mark UIActionSheet的代理
  272. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
  273. {
  274. // if (buttonIndex == 0) {
  275. // TCVideoRecordViewController *vc = [[TCVideoRecordViewController alloc] init];
  276. // vc.savePath = YES;
  277. // [[AppDelegate sharedAppDelegate] pushViewController:vc];
  278. // return;
  279. // }
  280. [[AppDelegate sharedAppDelegate]pushViewController:self.videoDynamicViewC animated:YES];
  281. [self.videoDynamicViewC ceartVideoViewWithType:(int)buttonIndex];
  282. }
  283. @end