123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- //
- // YOUPAILZStartLiveView.m
- // TIANYAN
- //
- // Created by CY on 2021/5/20.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZStartLiveView.h"
- #import "LZAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILZLiveProtocolWindow.h"
- #import "YOUPAILZLiveManagerListUtils.h"
- @interface YOUPAILZStartLiveView ()<TZImagePickerControllerDelegate>
- @property (nonatomic, weak) UIButton *youpaipcloseBtn; // 退出按钮
- @property (nonatomic, weak) UIButton *youpaipaddressBtn; // 位置按钮
- @property (nonatomic, weak) UIButton *youpaipchangeCameraBtn; // 切换摄像头按钮
- @property (nonatomic, weak) UIButton *youpaipbeautyBtn; // 美颜按钮
- @property (nonatomic, weak) UIButton *youpaipcoverBtn; //封面承载btn
- @property (nonatomic, strong) UIImage *coverImage;
- @property (nonatomic, strong) NSString *youpaipcover; // 封面地址
- @property (nonatomic, weak) UITextField *youpaipliveTitleTF; // 直播间标题
- @property (nonatomic, weak) UIButton *youpaipstartBtn; // 开始直播按钮
- @property (nonatomic, strong) YOUPAILZLiveShareModel *youpaipmodelshareModel; //分享Model
- @property (nonatomic, strong) NSString *youpaipgpsCity; // 所在城市
- @property (nonatomic, strong) UILabel *youpaipcountDownL; // 倒计时
- @property (nonatomic, strong) YOUPAILZLiveModel *youpaipliveModel;// 直播间Model
- @property (nonatomic, weak) UIButton *youpaipagreeProtocolBtn; // 是否同意直播
- @end
- @implementation YOUPAILZStartLiveView
- - (instancetype)initWithFrame:(CGRect)frame shareModel:(nonnull YOUPAILZLiveShareModel *)shareModel youpaipcover:(NSString *)youpaipcover{
- if (self = [super initWithFrame:frame]) {
- _youpaipcover = youpaipcover;
- _youpaipmodelshareModel = shareModel;
- [self youpaifupdateGpsCity];
- [self youpaifinitUI];
- [self youpaifsetupAuthority];
- }
- return self;
- }
- /// 权限
- - (void)youpaifsetupAuthority{
- [UCAuthorityManager cameraAuthority:^{
- } denied:^{
- [self youpaifshowAlertVCWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。"];
- }];
- [UCAuthorityManager microPhoneAuthority:^{
-
- } denied:^{
- [self youpaifshowAlertVCWithTitle:@"请在iphone的“设置-隐私-麦克风”选项中,允许APP访问您的麦克风。"];
- }];
- }
- - (void)youpaifshowAlertVCWithTitle:(NSString *)title{
- UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
- {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
-
- }
- else
- {
- // 去系统设置页面
- if (@available(iOS 10.0, *)) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- } else {
- // Fallback on earlier versions
- }
- }
- }];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- [[LCTools getCurrentVC].navigationController popViewControllerAnimated:YES];
- }];
- [systemAlert addAction:cancelAction];
- [systemAlert addAction:action];
- dispatch_async(dispatch_get_main_queue(), ^{
- [[LCTools getCurrentVC] presentViewController: systemAlert animated: YES completion: nil];
- });
- }
- - (void)youpaifinitUI{
- UIView *navigationBarV = [[UIView alloc] init];
- [self addSubview:navigationBarV];
- [navigationBarV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.offset(0.0f);
- make.height.offset(44.0f);
- make.top.offset(StatusBarHeight);
- }];
-
- UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_close"] forState:UIControlStateNormal];
- [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_close"] forState:UIControlStateHighlighted];
- [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [navigationBarV addSubview:youpaipcloseBtn];
- self.youpaipcloseBtn = youpaipcloseBtn;
- [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(6.0f);
- make.top.bottom.offset(0.0f);
- make.width.offset(44.0f);
- }];
-
- UIButton *youpaipbeautyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipbeautyBtn setImage:[UIImage imageNamed:@"vqu_images_L_Live_beauty"] forState:UIControlStateNormal];
- [youpaipbeautyBtn setImage:[UIImage imageNamed:@"vqu_images_L_Live_beauty"] forState:UIControlStateHighlighted];
- [youpaipbeautyBtn setTitle:@"美颜" forState:UIControlStateNormal];
- [youpaipbeautyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- youpaipbeautyBtn.titleLabel.font = LCFont16;
- [youpaipbeautyBtn addTarget:self action:@selector(youpaifbeautyBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [navigationBarV addSubview:youpaipbeautyBtn];
- self.youpaipbeautyBtn = youpaipbeautyBtn;
- [youpaipbeautyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-16.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- UIButton *youpaipchangeCameraBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipchangeCameraBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_change_camera"] forState:UIControlStateNormal];
- [youpaipchangeCameraBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_change_camera"] forState:UIControlStateHighlighted];
- [youpaipchangeCameraBtn setTitle:@"翻转" forState:UIControlStateNormal];
- [youpaipchangeCameraBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- youpaipchangeCameraBtn.titleLabel.font = LCFont16;
- [youpaipchangeCameraBtn addTarget:self action:@selector(youpaifchangeCameraBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [navigationBarV addSubview:youpaipchangeCameraBtn];
- self.youpaipchangeCameraBtn = youpaipchangeCameraBtn;
- [youpaipchangeCameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(youpaipbeautyBtn.mas_left).offset(-18.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- UIButton *youpaipaddressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipaddressBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_address_s"] forState:UIControlStateNormal];
- [youpaipaddressBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_address_s"] forState:UIControlStateSelected];
- [youpaipaddressBtn setTitle:@"定位中" forState:UIControlStateNormal];
- [youpaipaddressBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- youpaipaddressBtn.titleLabel.font = LCFont16;
- [youpaipaddressBtn addTarget:self action:@selector(youpaifaddressBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [navigationBarV addSubview:youpaipaddressBtn];
- self.youpaipaddressBtn = youpaipaddressBtn;
- [youpaipaddressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(youpaipchangeCameraBtn.mas_left).offset(-18.0f);
- make.top.bottom.offset(0.0f);
- }];
-
-
- UIView *bgV = [[UIView alloc] init];
- bgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4f];
- [self addSubview:bgV];
- [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.offset(0.0f);
- make.top.equalTo(navigationBarV.mas_bottom).offset(16.0f);
- make.height.offset(141.0f);
- }];
-
-
- UIButton *youpaipcoverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- // [youpaipcoverBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_start_add_cover"] forState:UIControlStateNormal];
- [youpaipcoverBtn sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipcover] forState:UIControlStateNormal];
- youpaipcoverBtn.backgroundColor = HexColorFromRGB(0x2A2935);
- youpaipcoverBtn.layer.cornerRadius = 6.0f;
- youpaipcoverBtn.clipsToBounds = YES;
- youpaipcoverBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
- youpaipcoverBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
- youpaipcoverBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
- [youpaipcoverBtn addTarget:self action:@selector(youpaifopenAlbum) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:youpaipcoverBtn];
- self.youpaipcoverBtn = youpaipcoverBtn;
- [youpaipcoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(16.0f);
- make.centerY.equalTo(bgV.mas_centerY);
- make.size.mas_offset(CGSizeMake(109.0f, 109.0f));
- }];
- //加号图片
- UIImageView *im = [UIImageView new];
- [youpaipcoverBtn addSubview:im];
- [im mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(0);
-
- }];
- im.image = [UIImage imageNamed:@"vqu_images_L_live_fengmian"];
- if (self.youpaipcover) {
- im.hidden = YES;
- }else{
-
- im.hidden = NO;
- }
-
-
-
- UIButton *addCoverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- UIImage *bgimage = [LCTools ColorImage:CGSizeMake(109.0f, 26.0f) FromColors:@[HexColorFromRGB(0x1C1D23),HexColorFromRGB(0x1C1D23)] ByGradientType:GradientLeftToRight];
- [addCoverBtn setBackgroundImage:bgimage forState:UIControlStateNormal];
- [addCoverBtn setBackgroundImage:bgimage forState:UIControlStateHighlighted];
- addCoverBtn.userInteractionEnabled = NO;
- addCoverBtn.titleLabel.font = LCFont12;
- [addCoverBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [addCoverBtn setTitle:@"添加封面" forState:UIControlStateNormal];
- [youpaipcoverBtn addSubview:addCoverBtn];
- [addCoverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.offset(0.0f);
- make.height.offset(26.0f);
- }];
-
- UILabel *liveTitleL = [[UILabel alloc] init];
- liveTitleL.text = @"直播标题";
- liveTitleL.textColor = [UIColor whiteColor];
- liveTitleL.font = LCFont14;
- [bgV addSubview:liveTitleL];
- [liveTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipcoverBtn.mas_right).offset(16.0f);
- make.top.offset(43.0f);
- make.height.offset(16.0f);
- }];
-
- UITextField *youpaipliveTitleTF = [[UITextField alloc] init];
- youpaipliveTitleTF.font = LCBoldFont(19.0f);
- youpaipliveTitleTF.textColor = [UIColor whiteColor];
- NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"给直播写个标题吧~"];
- [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x9F9DA5) range:NSMakeRange(0, placeholder.length)];
- youpaipliveTitleTF.attributedPlaceholder = placeholder;
- youpaipliveTitleTF.tintColor = ZYPinkColor;
- [bgV addSubview:youpaipliveTitleTF];
- self.youpaipliveTitleTF = youpaipliveTitleTF;
- [youpaipliveTitleTF mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipcoverBtn.mas_right).offset(16.0f);
- make.top.equalTo(liveTitleL.mas_bottom).offset(8.0f);
- make.right.offset(-16.0f);
- make.height.offset(44.0f);
- }];
-
-
-
- UIButton *youpaipstartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- UIImage *image = [LCTools ColorImage:CGSizeMake(KScreenWidth - 12.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight];
- [youpaipstartBtn setBackgroundImage:image forState:UIControlStateNormal];
- [youpaipstartBtn setBackgroundImage:image forState:UIControlStateHighlighted];
- youpaipstartBtn.titleLabel.font = LCFont17;
- youpaipstartBtn.layer.cornerRadius = 24.0f;
- youpaipstartBtn.clipsToBounds = YES;
- [youpaipstartBtn addTarget:self action:@selector(youpaifstartBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [youpaipstartBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [youpaipstartBtn setTitle:@"开始直播" forState:UIControlStateNormal];
- [self addSubview:youpaipstartBtn];
- self.youpaipstartBtn = youpaipstartBtn;
- [youpaipstartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(60.0f);
- make.right.offset(-60.0f);
- make.bottom.offset(-(98.0f-SafeHeight));
- make.height.offset(48.0f);
- }];
-
- UIView *protocolBgV = [[UIView alloc] init];
- [self addSubview:protocolBgV];
- [protocolBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.bottom.equalTo(youpaipstartBtn.mas_top).offset(-15.0f);
- make.height.offset(20.0f);
- }];
-
- UIButton *youpaipagreeProtocolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipagreeProtocolBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_hint_No"] forState:UIControlStateNormal];
- [youpaipagreeProtocolBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_hint_select"] forState:UIControlStateSelected];
- [youpaipagreeProtocolBtn setTitle:@" 开播默认同意遵守" forState:UIControlStateNormal];
- [youpaipagreeProtocolBtn addTarget:self action:@selector(youpaifagreeProtocolBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [youpaipagreeProtocolBtn setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.8f] forState:UIControlStateNormal];
- youpaipagreeProtocolBtn.titleLabel.font = LCFont(12.0f);
- [protocolBgV addSubview:youpaipagreeProtocolBtn];
- self.youpaipagreeProtocolBtn = youpaipagreeProtocolBtn;
- [youpaipagreeProtocolBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.top.bottom.offset(0.0f);
- }];
-
- UIButton *protocolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [protocolBtn setTitle:@"《女神管理条例》" forState:UIControlStateNormal];
- [protocolBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [protocolBtn addTarget:self action:@selector(youpaifprotocolBtnClick) forControlEvents:UIControlEventTouchUpInside];
- protocolBtn.titleLabel.font = LCFont(12.0f);
- [protocolBgV addSubview:protocolBtn];
- [protocolBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipagreeProtocolBtn.mas_right);
- make.top.right.bottom.offset(0.0f);
- }];
- }
- - (void)youpaifupdateGpsCity{
- @weakify(self);
- [[LCLocationManager shareInstance]getLocationCity:^(NSString *city) {
- @strongify(self);
- if (![city isEqualToString:@""]) {
- self.youpaipgpsCity = [city substringWithRange:NSMakeRange(0, city.length - 1)];
- self.youpaipaddressBtn.selected = NO;
- }else{
- self.youpaipaddressBtn.selected = YES;
- }
- [self youpaifreloadCity];
- }];
- }
- - (void)youpaifreloadCity{
- if ([self.youpaipgpsCity isEqual:@""] || self.youpaipaddressBtn.selected) {
- [self.youpaipaddressBtn setTitle:@"关闭" forState:UIControlStateNormal];
- }else{
- [self.youpaipaddressBtn setTitle:self.youpaipgpsCity forState:UIControlStateNormal];
- }
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
- [self endEditing:YES];
- }
- - (void)youpaifagreeProtocolBtnClick:(UIButton *)sender{
- sender.selected = !sender.selected;
- }
- - (void)youpaifprotocolBtnClick{
- YOUPAILZLiveProtocolWindow *vc = [[YOUPAILZLiveProtocolWindow alloc] init];
- vc.isTouchDismiss = YES;
- @weakify(self);
- [vc setYoupaipagreeStartLiveBlock:^(BOOL isAgreeProtocol) {
- @strongify(self);
- self.youpaipagreeProtocolBtn.selected = isAgreeProtocol;
- if (isAgreeProtocol) {
- [self youpaifstartBtnClick];
- }
- }];
- [[LCTools getCurrentVC] TFPresentVC:vc completion:^{}];
- }
- - (void)youpaifcloseBtnClick{
- if (self.youpaipcloseClickBlock != nil) {
- self.youpaipcloseClickBlock();
- }
- }
- - (void)youpaifbeautyBtnClick{
- if (self.youpaipbeautyClickBlock != nil) {
- self.youpaipbeautyClickBlock();
- }
- }
- - (void)youpaifchangeCameraBtnClick{
- if (self.youpaipchangeCameraClickBlock != nil) {
- self.youpaipchangeCameraClickBlock();
- }
- }
- - (void)youpaifaddressBtnClick:(UIButton *)sender{
- if (!sender.selected) {
- @weakify(self);
- LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"坚决关闭" handler:^(LZAlertAction *action) {
- @strongify(self);
- sender.selected = !sender.selected;
- [self youpaifreloadCity];
- }];
- cancelAction.cornerRadius = 24.0f;
- cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
-
- }];
- confimAction.cornerRadius = 24.0f;
- confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"关闭定位,直播不会被附近人看到,直播间人数可能会减少,确认关闭吗?" action:@[cancelAction,confimAction]];
- [[LCTools getCurrentVC] TFPresentVC:alert completion:^{}];
- }else{
- sender.selected = !sender.selected;
- [self youpaifreloadCity];
- }
- }
- - (void)youpaifstartBtnClick{
- if (self.youpaipagreeProtocolBtn.selected) {
- self.youpaipstartBtn.userInteractionEnabled = NO;
- if (self.coverImage == nil) {
- [self youpaifstartLiveWithCover:@""];
- }else{
- [ZCHUDHelper showWithStatus:@"上传中..."];
- @weakify(self);
- [LCCommonHttp uploadWithImages:@[self.coverImage] Type:@"cover" successBlock:^(NSArray<NSString *> *ossImagePaths) {
- @strongify(self);
- [ZCHUDHelper dismiss];
- if (ossImagePaths.count != 0) {
- [self youpaifstartLiveWithCover:ossImagePaths[0]];
- }
- }];
- }
- }else{
- [self youpaifprotocolBtnClick];
- }
- }
- - (void)youpaifstartLiveWithCover:(NSString *)youpaipcover{
- if (youpaipcover.length == 0) {
- youpaipcover = self.youpaipcover;
- }
- @weakify(self);
- [LCHttpHelper requestWithURLString:StartLive parameters:@{@"room_title":self.youpaipliveTitleTF.text,@"room_cover":youpaipcover} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- self.youpaipliveModel = [YOUPAILZLiveModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [[YOUPAILZLiveManagerListUtils shared] youpaifreloadManagerListWithLiveId:self.youpaipliveModel.youpaiplive_id];
- [LCSaveData saveLiveRankTopThere:self.youpaipliveModel.youpaiprank_top_three];
- [self youpaipcountDownL];
- }else{
- self.youpaipstartBtn.userInteractionEnabled = YES;
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- }
- } failure:^(NSError *error) {
- @strongify(self);
- self.youpaipstartBtn.userInteractionEnabled = YES;
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (void)youpaifcountDown{
- [self addSubview:self.youpaipcountDownL];
- __block int timeout=3;
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(_timer, ^{
- if(timeout <= -1){
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- self.youpaipcountDownL.hidden = YES;
- if (self.youpaipstartLiveClickBlock != nil) {
- self.youpaipstartLiveClickBlock(self.youpaipliveModel);
- }
- });
- }else{
- NSString *strTime = [NSString stringWithFormat:@"%@",timeout <= 0 ? @"GO~" : @(timeout)];
- dispatch_async(dispatch_get_main_queue(), ^{
- self.youpaipcountDownL.hidden = NO;
- [self youpaifsetupShadowWithText:strTime view:self.youpaipcountDownL];
- self.youpaipcountDownL.transform = CGAffineTransformMakeScale(5.0f, 5.0f);
- [UIView animateWithDuration:0.25f animations:^{
- self.youpaipcountDownL.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
- }];
- });
- timeout--;
- }
- });
- dispatch_resume(_timer);
- }
- - (UILabel *)youpaipcountDownL{
- if (_youpaipcountDownL == nil) {
- _youpaipcountDownL = [[UILabel alloc] initWithFrame:self.bounds];
- _youpaipcountDownL.textColor = [UIColor whiteColor];
- _youpaipcountDownL.textAlignment = NSTextAlignmentCenter;
- _youpaipcountDownL.text = @"3";
- _youpaipcountDownL.font = LCBoldFont(70.0f);
- }
- return _youpaipcountDownL;
- }
- - (void)youpaifsetupShadowWithText:(NSString *)text view:(UILabel *)view{
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
- NSShadow *shadow = [[NSShadow alloc]init];
- // shadow.shadowBlurRadius = 1.0;
- shadow.shadowOffset = CGSizeMake(1, 1.5f);
- shadow.shadowColor = [HexColorFromRGB(0x000000) colorWithAlphaComponent:0.2f];
- [attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, text.length)];
- view.attributedText = attributedString;
- }
- - (void)youpaifopenAlbum{
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self];
- [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
- imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
- imagePickerVc.allowPickingVideo = NO;//是否允许选择视频
- imagePickerVc.allowPickingImage = YES;//是否允许选择照片
- imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
- imagePickerVc.showSelectedIndex = YES; //显示图片序号
- imagePickerVc.allowCrop = NO;//是否允许裁剪
-
- // // 裁剪框的尺寸
- // imagePickerVc.cropRect = CGRectMake(0, KScreenHeight/2-(KScreenWidth/3.0*4)/2, KScreenWidth,KScreenWidth/3.0*4);
-
- // 4. 照片排列按修改时间升序
- imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
- // You can get the photos by block, the same as by delegate.
- // 你可以通过block或者代理,来得到用户选择的照片.
- @weakify(self);
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- @strongify(self);
- if (photos.count != 0) {
- self.coverImage = photos[0];
- [self.youpaipcoverBtn sd_setImageWithURL:[NSURL URLWithString:@""] forState:UIControlStateNormal];
- [self.youpaipcoverBtn setImage:self.coverImage forState:UIControlStateNormal];
- }
- }];
- [[LCTools getCurrentVC] presentViewController:imagePickerVc animated:YES completion:nil];
- }
- @end
|