Commit 2b6a5abdd3476b05322ac1b7395af95a4c0a9921
1 parent
e7d9e117
新增商品UI等问题修复
Showing
37 changed files
with
439 additions
and
228 deletions
metaCode/Classes/Common/Util/CNLiveCommonQiniuTool.swift
| ... | ... | @@ -94,13 +94,14 @@ class UploadManager: NSObject { |
| 94 | 94 | param.setValue("POST", forKey: "verb") |
| 95 | 95 | param.setValue("2", forKey: "storageType") |
| 96 | 96 | param.setValue(kBucketName_QN, forKey: "bucket") |
| 97 | - showLoading(message: "上传处理中...") | |
| 98 | 97 | CNLiveNetworking.setupShowResult(true) |
| 99 | 98 | CNLiveNetworking.setAllowRequestDefaultArgument(true) |
| 100 | 99 | CNLiveNetworking.setupShowDataResult(false) |
| 101 | - CNLiveNetworking.setupSignRequestKey(APPKey_wjj) | |
| 100 | + CNLiveNetworking.setupSignRequestKey(APPKey)//APPKey_wjj APPKey | |
| 101 | + | |
| 102 | 102 | CNLiveNetworking.requestNetwork(with: .POST, urlString: "\(CNLiveEnvironmentManager.shared.img_token_url)/vod_epg/getUploadAuthForApp", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in |
| 103 | 103 | hiddenLoading() |
| 104 | + | |
| 104 | 105 | if (error == nil) { |
| 105 | 106 | let resp = result as! NSDictionary |
| 106 | 107 | let errorCode = "\(resp["errorCode"] ?? 0)" |
| ... | ... | @@ -143,7 +144,7 @@ class UploadManager: NSObject { |
| 143 | 144 | showMessage(message: resp["errorMessage"] as! String) |
| 144 | 145 | } |
| 145 | 146 | } else { |
| 146 | - showMessage(message: error!.localizedDescription) | |
| 147 | + showMessage(message: error?.localizedDescription ?? "上传失败") | |
| 147 | 148 | } |
| 148 | 149 | } |
| 149 | 150 | } | ... | ... |
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveCreateShopClassifyViewController.swift
| ... | ... | @@ -51,7 +51,7 @@ class CNLiveCreateShopClassifyViewController:CNLiveBaseViewController, UITableVi |
| 51 | 51 | return tableView |
| 52 | 52 | }() |
| 53 | 53 | lazy var bottomNavView :UIView = { |
| 54 | - let bottomNavView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height - KTabBarHeight)) | |
| 54 | + let bottomNavView = UIView(frame: CGRect(x: 0, y: self.view.height - KTabBarHeight, width: self.view.width, height: KTabBarHeight)) | |
| 55 | 55 | bottomNavView.backgroundColor = HexColor("F2F2F2") |
| 56 | 56 | return bottomNavView |
| 57 | 57 | }() |
| ... | ... | @@ -65,18 +65,27 @@ class CNLiveCreateShopClassifyViewController:CNLiveBaseViewController, UITableVi |
| 65 | 65 | super.viewDidLoad() |
| 66 | 66 | self.initUI() |
| 67 | 67 | } |
| 68 | - | |
| 68 | + // MARK: - 初始化UI | |
| 69 | 69 | /// 初始化方法 |
| 70 | 70 | /// @param model 要编辑的分类数据,当isEdite为YES,才需要传 |
| 71 | 71 | /// @param isEdite 是否是编辑 YES:是 NO:不是 |
| 72 | - func initWithModel(model:CNLiveShopClassifyModel,isEdite:Bool){ | |
| 72 | + init(model:CNLiveShopClassifyModel,isEdite:Bool){ | |
| 73 | + super.init(nibName: nil, bundle: nil) | |
| 73 | 74 | self.shopClassifyModel = model |
| 74 | 75 | //设置店铺id |
| 75 | 76 | self.shopClassifyModel?.shop_id = DSUserInfoManager.shared.dsUserInfo.id |
| 76 | 77 | self.isEdite = isEdite |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | - // MARK: - 初始化UI | |
| 80 | + convenience init(){ | |
| 81 | + self.init(model: CNLiveShopClassifyModel(), isEdite: false) | |
| 82 | + } | |
| 83 | + | |
| 84 | + required init?(coder: NSCoder) { | |
| 85 | + fatalError("init(coder:) has not been implemented") | |
| 86 | + } | |
| 87 | + | |
| 88 | + | |
| 80 | 89 | func initUI(){ |
| 81 | 90 | self.view.addSubview(self.tableView) |
| 82 | 91 | self.initTopNav() |
| ... | ... | @@ -84,8 +93,9 @@ class CNLiveCreateShopClassifyViewController:CNLiveBaseViewController, UITableVi |
| 84 | 93 | } |
| 85 | 94 | |
| 86 | 95 | func initTopNav(){ |
| 96 | + navigationBarHidden = false | |
| 87 | 97 | if self.isEdite == true{ |
| 88 | - self.title = "编辑店铺分类" | |
| 98 | + titleName = "编辑店铺分类" | |
| 89 | 99 | let deleteNavBtn = UIButton(type: .custom) |
| 90 | 100 | deleteNavBtn.frame = CGRect(x: 0, y: KStatusBarHeight, width: KNavigationHeight-KStatusBarHeight, height: KNavigationHeight-KStatusBarHeight) |
| 91 | 101 | deleteNavBtn.backgroundColor = .clear |
| ... | ... | @@ -94,7 +104,7 @@ class CNLiveCreateShopClassifyViewController:CNLiveBaseViewController, UITableVi |
| 94 | 104 | deleteNavBtn.addTarget(self, action: #selector(deleteNavBtnClick), for: .touchUpInside) |
| 95 | 105 | self.rightNavBtns = [deleteNavBtn] |
| 96 | 106 | }else{ |
| 97 | - self.title = "创建店铺分类" | |
| 107 | + titleName = "创建店铺分类" | |
| 98 | 108 | |
| 99 | 109 | //初始化model,赋值一些默认数据 |
| 100 | 110 | self.shopClassifyModel = CNLiveShopClassifyModel() |
| ... | ... | @@ -111,6 +121,7 @@ class CNLiveCreateShopClassifyViewController:CNLiveBaseViewController, UITableVi |
| 111 | 121 | |
| 112 | 122 | func initBottomNav(){ |
| 113 | 123 | self.bottomNavView.backgroundColor = .white |
| 124 | + self.view.addSubview(self.bottomNavView) | |
| 114 | 125 | |
| 115 | 126 | let cancelBtn = UIButton(type: .custom) |
| 116 | 127 | cancelBtn.frame = CGRect(x: 0, y: 0, width: 130, height: KTabBarHeight) | ... | ... |
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveGoodsCategoryController.swift
| ... | ... | @@ -479,7 +479,7 @@ class CNLiveGoodsCategoryController: CNLiveBaseViewController, UITableViewDataSo |
| 479 | 479 | |
| 480 | 480 | ///创建店铺分类 |
| 481 | 481 | @objc func createBtnClick(){ |
| 482 | - let vc = CNLiveCreateShopClassifyViewController() | |
| 482 | + let vc = CNLiveCreateShopClassifyViewController() | |
| 483 | 483 | vc.classifyType = .oneLevelClassify |
| 484 | 484 | vc.successCompleteBlock = { |
| 485 | 485 | self.postShopClassify() | ... | ... |
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveModalPresentationViewController.swift
| ... | ... | @@ -8,31 +8,44 @@ |
| 8 | 8 | import Foundation |
| 9 | 9 | |
| 10 | 10 | typealias completionBlock = (_ finished:Bool)->Void |
| 11 | +typealias confirmActionBlock = ()->Void | |
| 11 | 12 | |
| 12 | 13 | class CNLiveModalPresentationViewController:UIViewController{ |
| 13 | 14 | |
| 14 | - var _contentView:UIView? | |
| 15 | - var contentView:UIView?{ | |
| 16 | - get{ | |
| 17 | - _contentView | |
| 18 | - } | |
| 19 | - set{ | |
| 20 | - _contentView = newValue | |
| 21 | - | |
| 22 | - } | |
| 23 | - } | |
| 15 | + var confirmBlock:confirmActionBlock? | |
| 16 | + lazy var contentView :UIView = { | |
| 17 | + let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) | |
| 18 | + return contentView | |
| 19 | + }() | |
| 20 | + | |
| 21 | + lazy var bgView :UIView = { | |
| 22 | + let bgView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height)) | |
| 23 | + bgView.backgroundColor = .black | |
| 24 | + bgView.alpha = 0.2 | |
| 25 | + return bgView | |
| 26 | + }() | |
| 24 | 27 | |
| 25 | 28 | override func viewDidLoad() { |
| 26 | 29 | super.viewDidLoad() |
| 27 | 30 | self.view.backgroundColor = .clear |
| 31 | + self.view.addSubview(self.bgView) | |
| 32 | + self.view.addSubview(self.contentView) | |
| 28 | 33 | } |
| 29 | 34 | |
| 35 | + @objc func cancelButtonAction(){ | |
| 36 | + self.hidingAnimationWithCompletion { finished in | |
| 37 | + | |
| 38 | + } | |
| 39 | + } | |
| 40 | + @objc func confirmButtonAction(){ | |
| 41 | + if ((self.confirmBlock?()) != nil){ | |
| 42 | + self.confirmBlock!() | |
| 43 | + } | |
| 44 | + } | |
| 30 | 45 | func showingAnimationWithCompletion(completion:@escaping completionBlock){ |
| 31 | - | |
| 32 | - self.contentView?.transform = CGAffineTransformMakeTranslation(0, self.view.height-(self.contentView?.top)!) | |
| 33 | - | |
| 46 | + | |
| 34 | 47 | UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut) { |
| 35 | - self.contentView?.transform = CGAffineTransformIdentity | |
| 48 | + self.contentView.top = (self.view.height-self.contentView.height)/2 | |
| 36 | 49 | } completion: { finished in |
| 37 | 50 | completion(finished) |
| 38 | 51 | } |
| ... | ... | @@ -40,13 +53,10 @@ class CNLiveModalPresentationViewController:UIViewController{ |
| 40 | 53 | |
| 41 | 54 | func hidingAnimationWithCompletion(completion:@escaping completionBlock){ |
| 42 | 55 | UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut) { |
| 43 | - self.contentView?.transform = CGAffineTransformMakeTranslation(0, self.view.height-self.contentView!.top) | |
| 56 | + self.contentView.top = self.view.height | |
| 44 | 57 | } completion: { finished in |
| 45 | - self.contentView?.transform = CGAffineTransformIdentity | |
| 46 | 58 | completion(finished) |
| 59 | + self.view.removeFromSuperview() | |
| 47 | 60 | } |
| 48 | 61 | } |
| 49 | - | |
| 50 | - | |
| 51 | - | |
| 52 | 62 | } | ... | ... |
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveShopNewProductController.swift
| ... | ... | @@ -51,8 +51,8 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 51 | 51 | } |
| 52 | 52 | vc.finishBlock = { |
| 53 | 53 | var singleView = self.getShopClassifyView() |
| 54 | - singleView.contentTextField.text = "\(self.selectShopClassifyVC.firCategoryName ?? "") \(self.selectShopClassifyVC.secCategoryName ?? "")" | |
| 55 | - singleView.layoutSubviews() | |
| 54 | + singleView?.contentTextField.text = "\(self.selectShopClassifyVC.firCategoryName ?? "") \(self.selectShopClassifyVC.secCategoryName ?? "")" | |
| 55 | + singleView?.layoutSubviews() | |
| 56 | 56 | } |
| 57 | 57 | self.addChild(vc) |
| 58 | 58 | vc.view.frame = CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height) |
| ... | ... | @@ -155,8 +155,8 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 155 | 155 | self.dataModel.initDataSource() |
| 156 | 156 | for i in 0..<self.dataModel.list.count { |
| 157 | 157 | let model = self.dataModel.list[i] |
| 158 | - let singleView = CNLiveShopAddGoodsSingleView.init(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 50)) | |
| 159 | - singleView.addEditGoodsListModel = model | |
| 158 | + let singleView = CNLiveShopAddGoodsSingleView.init(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 50), model: model) | |
| 159 | +// singleView.addEditGoodsListModel = model | |
| 160 | 160 | singleView.tag = i+1 |
| 161 | 161 | //完成frame更新通知 |
| 162 | 162 | singleView.updateFrameBlock = { |
| ... | ... | @@ -200,8 +200,7 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | func reloadBgScrollViewContentViewModel(model:CNLiveShopAddEditGoodsListModel,index:Int,isScrollToBottom:Bool){ |
| 203 | - let singleView = CNLiveShopAddGoodsSingleView() | |
| 204 | - singleView.addEditGoodsListModel = model | |
| 203 | + let singleView = CNLiveShopAddGoodsSingleView(frame: CGRect(x: 0, y: self.bgScrollView.height, width: self.bgScrollView.width, height: 50), model: model) | |
| 205 | 204 | singleView.tag = index |
| 206 | 205 | singleView.updateFrameBlock = { |
| 207 | 206 | self.viewWillLayoutSubviews() |
| ... | ... | @@ -229,7 +228,7 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 229 | 228 | } |
| 230 | 229 | } |
| 231 | 230 | self.bgScrollView.addSubview(singleView) |
| 232 | - singleView.frame = CGRect(x: 0, y: self.bgScrollView.height, width: self.bgScrollView.width, height: singleView.height) | |
| 231 | + | |
| 233 | 232 | self.bgScrollView.contentSize = CGSize(width: self.bgScrollView.width, height: self.bgScrollView.contentSize.height+50) |
| 234 | 233 | if (isScrollToBottom) { |
| 235 | 234 | self.bgScrollView.scrollToBottom() |
| ... | ... | @@ -287,7 +286,7 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 287 | 286 | } |
| 288 | 287 | |
| 289 | 288 | // MARK: - 获取店铺分类view |
| 290 | - func getShopClassifyView()->CNLiveShopAddGoodsSingleView{ | |
| 289 | + func getShopClassifyView()->CNLiveShopAddGoodsSingleView?{ | |
| 291 | 290 | for singleView in self.bgScrollView.subviews { |
| 292 | 291 | if singleView.isKind(of: CNLiveShopAddGoodsSingleView.self){ |
| 293 | 292 | let single = singleView as! CNLiveShopAddGoodsSingleView |
| ... | ... | @@ -296,7 +295,7 @@ class CNLiveShopNewProductController:CNLiveBaseViewController{ |
| 296 | 295 | } |
| 297 | 296 | } |
| 298 | 297 | } |
| 299 | - return CNLiveShopAddGoodsSingleView() | |
| 298 | + return nil | |
| 300 | 299 | } |
| 301 | 300 | // MARK: - 显示选取店铺分类界面 |
| 302 | 301 | func displaySelectShopClassifyVC(){ | ... | ... |
metaCode/Classes/Main/HomePage/View/CNDownSlideView.swift
| ... | ... | @@ -85,6 +85,8 @@ class CNDownSlideView:UIView{ |
| 85 | 85 | }else if(type == UpDownTypeShopDetail){ |
| 86 | 86 | |
| 87 | 87 | }else if(type == UpDownTypeShopControlConsole){ |
| 88 | + currentViewController()?.addChild(self.shopConsoleVC) | |
| 89 | + self.shopConsoleVC.didMove(toParent: currentViewController()) | |
| 88 | 90 | self.addSubview(self.shopConsoleVC.view) |
| 89 | 91 | } |
| 90 | 92 | } | ... | ... |
metaCode/Classes/Main/HomePage/View/CNUpSlideView.swift
| ... | ... | @@ -55,6 +55,7 @@ class CNUpSlideView:UIView{ |
| 55 | 55 | |
| 56 | 56 | }else if(type == UpDownTypeShopDetail){ |
| 57 | 57 | currentViewController()?.addChild(self.upSlideVC)//看行不行 |
| 58 | + self.upSlideVC.didMove(toParent: currentViewController()) | |
| 58 | 59 | self.addSubview(self.upSlideVC.view) |
| 59 | 60 | }else if(type == UpDownTypeShopControlConsole){ |
| 60 | 61 | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveAddGoodsSelectUploadImageView.swift
| ... | ... | @@ -11,6 +11,7 @@ import UniformTypeIdentifiers |
| 11 | 11 | import AVFoundation |
| 12 | 12 | import HXPHPicker |
| 13 | 13 | import SKPhotoBrowser |
| 14 | +import AVKit | |
| 14 | 15 | ///类型 |
| 15 | 16 | enum CNLiveSelectUploadImageViewDisplayType:Int { |
| 16 | 17 | ///选择 |
| ... | ... | @@ -38,8 +39,8 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 38 | 39 | |
| 39 | 40 | // MARK: - 属性 |
| 40 | 41 | /// 显示类型 |
| 41 | - var _displayType:CNLiveSelectUploadImageViewDisplayType? | |
| 42 | - var displayType:CNLiveSelectUploadImageViewDisplayType?{ | |
| 42 | + var _displayType:CNLiveSelectUploadImageViewDisplayType = .select | |
| 43 | + var displayType:CNLiveSelectUploadImageViewDisplayType{ | |
| 43 | 44 | get{ |
| 44 | 45 | _displayType |
| 45 | 46 | } |
| ... | ... | @@ -50,7 +51,7 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | /// 高度类型 |
| 53 | - var heightStyle:CNLiveSelectUploadImageViewHeightStyle? | |
| 54 | + var heightStyle:CNLiveSelectUploadImageViewHeightStyle = .autoCalc | |
| 54 | 55 | /// 每张图的间距 默认DS_adapt_length(15) |
| 55 | 56 | var _space:CGFloat = 15 |
| 56 | 57 | var space:CGFloat{ |
| ... | ... | @@ -101,13 +102,13 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 101 | 102 | } |
| 102 | 103 | } |
| 103 | 104 | /// 是否显示选取封面 |
| 104 | - var _isDisplySelectCover:Bool? | |
| 105 | + var _isDisplySelectCover:Bool = false | |
| 105 | 106 | var isDisplySelectCover:Bool?{ |
| 106 | 107 | get{ |
| 107 | 108 | _isDisplySelectCover |
| 108 | 109 | } |
| 109 | 110 | set{ |
| 110 | - _isDisplySelectCover = newValue | |
| 111 | + _isDisplySelectCover = newValue! | |
| 111 | 112 | self.resetUI() |
| 112 | 113 | } |
| 113 | 114 | } |
| ... | ... | @@ -133,7 +134,7 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 133 | 134 | self.uploadImageUrls.removeAll() |
| 134 | 135 | self.replaceImageUrls.removeAll() |
| 135 | 136 | for imageUrl in self.networkImageArr{ |
| 136 | - var uploadImageModel = CNLiveSelectUploadImageModel() | |
| 137 | + let uploadImageModel = CNLiveSelectUploadImageModel() | |
| 137 | 138 | uploadImageModel.imageUrl = imageUrl |
| 138 | 139 | uploadImageModel.isUploading = false |
| 139 | 140 | self.uploadImageUrls.append(uploadImageModel) |
| ... | ... | @@ -189,19 +190,19 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 189 | 190 | } |
| 190 | 191 | |
| 191 | 192 | /// 是否可以选择视频 (目前只能选取一个,在索引1显示) |
| 192 | - var _isAbleSelectVideo:Bool? | |
| 193 | + var _isAbleSelectVideo:Bool = false | |
| 193 | 194 | var isAbleSelectVideo:Bool?{ |
| 194 | 195 | get{ |
| 195 | 196 | _isAbleSelectVideo |
| 196 | 197 | } |
| 197 | 198 | set{ |
| 198 | - _isAbleSelectVideo = newValue | |
| 199 | + _isAbleSelectVideo = newValue! | |
| 199 | 200 | self.resetUI() |
| 200 | 201 | } |
| 201 | 202 | } |
| 202 | 203 | // MARK: - 上传操作 |
| 203 | 204 | /// 是否正在上传图片中 |
| 204 | - var isUploading:Bool? | |
| 205 | + var isUploading:Bool = false | |
| 205 | 206 | /// 开始上传图片 |
| 206 | 207 | var beginUploadImageCallBack:beginUploadImageCallBackBlock? |
| 207 | 208 | /// 结束上传图片 |
| ... | ... | @@ -277,7 +278,7 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 277 | 278 | @return 网络图片Url数组 |
| 278 | 279 | */ |
| 279 | 280 | func getCurrentSelectImageUrls()->Array<String>{ |
| 280 | - var imageUrls = NSMutableArray() | |
| 281 | + let imageUrls = NSMutableArray() | |
| 281 | 282 | for uploadImageModel in self.uploadImageUrls{ |
| 282 | 283 | if uploadImageModel.isUploading == true || uploadImageModel.imageUrl?.isEmpty == true{ |
| 283 | 284 | return Array() |
| ... | ... | @@ -383,14 +384,18 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 383 | 384 | didSet { |
| 384 | 385 | if self.heightStyle == .autoCalc{ |
| 385 | 386 | //算出带X图片的间距 X图片宽高均为DS_adapt_length(17) |
| 386 | - var addXRSpace = self.rSpace - 17*0.5 | |
| 387 | - var addXSpace = self.space - 17*0.5 | |
| 387 | + let addXRSpace = self.rSpace - 17*0.5 | |
| 388 | + let addXSpace = self.space - 17*0.5 | |
| 388 | 389 | let column = self.maxSelectImageCount < self.column ? self.maxSelectImageCount : self.column |
| 390 | + | |
| 389 | 391 | let totalSpace = self.lSpace + addXRSpace + addXSpace*CGFloat(column - 1) |
| 390 | - let aHeight = column == 0 ? 0.0 : (frame.size.width - totalSpace / CGFloat(column)) | |
| 392 | + let aHeight = column == 0 ? 0.0 : ((frame.size.width - totalSpace) / CGFloat(column)) | |
| 391 | 393 | |
| 392 | 394 | let subviewsCount = self.subviews.count |
| 393 | - let row = subviewsCount / column + (subviewsCount % column > 0 ? 1 : 0) | |
| 395 | + var row = 1 | |
| 396 | + if column > 0{ | |
| 397 | + row = subviewsCount / column + (subviewsCount % column > 0 ? 1 : 0) | |
| 398 | + } | |
| 394 | 399 | let height = aHeight * CGFloat(row) + (row > 1 ? addXSpace : 0) + 10 |
| 395 | 400 | var isNeedCallBack = false |
| 396 | 401 | if self.height != 0 && self.height != height{ |
| ... | ... | @@ -415,6 +420,8 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 415 | 420 | |
| 416 | 421 | override init(frame: CGRect) { |
| 417 | 422 | super.init(frame: frame) |
| 423 | + self.initData() | |
| 424 | + self.resetUI() | |
| 418 | 425 | } |
| 419 | 426 | |
| 420 | 427 | required init?(coder: NSCoder) { |
| ... | ... | @@ -476,26 +483,34 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 476 | 483 | if self.displayType == .select{ |
| 477 | 484 | var lastIsSelectImage = false |
| 478 | 485 | if self.isAbleSelectVideo == true{ |
| 486 | + //可以选择视频,索引1 | |
| 487 | + //前2个为 选择图片和选择视频占位图,最多7个图片 1个视频 | |
| 479 | 488 | let model1 = CNLiveSelectUploadImageModel() |
| 480 | 489 | model1.isSelectPhotoPlaceholder = true |
| 490 | + //选择照片 | |
| 481 | 491 | let singleImageView1 = self.createSingleImageView() |
| 482 | 492 | singleImageView1.tag = 1+DS_SUIV_ADD_TAG_COUNT |
| 483 | 493 | singleImageView1.setModel(model: model1, isHideDeleteBtn: isHideDeleteBtn, isCover: false) |
| 484 | 494 | self.addSubview(singleImageView1) |
| 495 | + //选择视频 | |
| 485 | 496 | let singleImageView2 = self.createSingleImageView() |
| 486 | 497 | singleImageView2.tag = 2+DS_SUIV_ADD_TAG_COUNT |
| 487 | 498 | singleImageView2.setModel(model: self.uploadVideoModel!, isHideDeleteBtn: isHideDeleteBtn, isCover: false) |
| 488 | 499 | self.addSubview(singleImageView2) |
| 489 | 500 | }else if self.uploadImageUrls.count < self.maxSelectImageCount{ |
| 501 | + //不可以选择视频,最后一个图片 | |
| 490 | 502 | lastIsSelectImage = true |
| 491 | 503 | } |
| 492 | 504 | var lastView:CNLiveSelUplSingleImageView? = nil |
| 493 | 505 | for i in 0..<self.uploadImageUrls.count { |
| 506 | + //给图片赋值 | |
| 494 | 507 | let model = self.uploadImageUrls[i] |
| 495 | - var singleImageView = self.createSingleImageView() | |
| 496 | - if self.isAbleSelectVideo! == true{ | |
| 508 | + let singleImageView = self.createSingleImageView() | |
| 509 | + if self.isAbleSelectVideo == true{ | |
| 510 | + //有2个默认占位图 | |
| 497 | 511 | singleImageView.tag = i+3+DS_SUIV_ADD_TAG_COUNT |
| 498 | 512 | }else{ |
| 513 | + //全是图片,没有占位图 | |
| 499 | 514 | singleImageView.tag = i+1+DS_SUIV_ADD_TAG_COUNT |
| 500 | 515 | } |
| 501 | 516 | singleImageView.setModel(model: model, isHideDeleteBtn: isHideDeleteBtn, isCover: i == 0 ? true : false) |
| ... | ... | @@ -503,11 +518,12 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 503 | 518 | lastView = singleImageView |
| 504 | 519 | } |
| 505 | 520 | if lastIsSelectImage{ |
| 506 | - var model = CNLiveSelectUploadImageModel() | |
| 521 | + //最后一张图片 | |
| 522 | + let model = CNLiveSelectUploadImageModel() | |
| 507 | 523 | model.isSelectPhotoPlaceholder = true |
| 508 | - var singleImageView = self.createSingleImageView() | |
| 524 | + let singleImageView = self.createSingleImageView() | |
| 509 | 525 | if (lastView != nil){ |
| 510 | - singleImageView.tag = lastView!.tag | |
| 526 | + singleImageView.tag = lastView!.tag + 1 | |
| 511 | 527 | }else{ |
| 512 | 528 | singleImageView.tag = DS_SUIV_ADD_TAG_COUNT+1 |
| 513 | 529 | } |
| ... | ... | @@ -515,22 +531,25 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 515 | 531 | self.addSubview(singleImageView) |
| 516 | 532 | } |
| 517 | 533 | }else{ |
| 534 | + //纯展示,不可选择 | |
| 518 | 535 | if self.networkVideoUrl?.count ?? 0 > 0{ |
| 519 | - var model = CNLiveSelectUploadImageModel() | |
| 536 | + //给视频配置model | |
| 537 | + let model = CNLiveSelectUploadImageModel() | |
| 520 | 538 | model.videoUrl = self.networkVideoUrl |
| 521 | 539 | model.imageUrl = self.networkVideoImageUrl |
| 522 | 540 | model.isVideo = true |
| 523 | 541 | |
| 524 | - var singleImageView = self.createSingleImageView() | |
| 542 | + let singleImageView = self.createSingleImageView() | |
| 525 | 543 | singleImageView.tag = 1+DS_SUIV_ADD_TAG_COUNT |
| 526 | 544 | singleImageView.setModel(model: model, isHideDeleteBtn: isHideDeleteBtn, isCover: false) |
| 527 | 545 | self.addSubview(singleImageView) |
| 528 | 546 | } |
| 529 | 547 | for i in 0..<self.networkImageArr.count { |
| 530 | - var model = CNLiveSelectUploadImageModel() | |
| 548 | + //给图片配置model | |
| 549 | + let model = CNLiveSelectUploadImageModel() | |
| 531 | 550 | model.imageUrl = self.networkImageArr[i] |
| 532 | 551 | |
| 533 | - var singleImageView = self.createSingleImageView() | |
| 552 | + let singleImageView = self.createSingleImageView() | |
| 534 | 553 | if self.networkVideoUrl!.count > 0{ |
| 535 | 554 | singleImageView.tag = i + 2+DS_SUIV_ADD_TAG_COUNT |
| 536 | 555 | }else{ |
| ... | ... | @@ -545,7 +564,7 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 545 | 564 | |
| 546 | 565 | /// 创建单个视图 |
| 547 | 566 | func createSingleImageView()->CNLiveSelUplSingleImageView{ |
| 548 | - var singleImageView = CNLiveSelUplSingleImageView() | |
| 567 | + let singleImageView = CNLiveSelUplSingleImageView() | |
| 549 | 568 | singleImageView.deleteImage = self.deleteImage |
| 550 | 569 | singleImageView.isDisplySelectCover = self.isDisplySelectCover |
| 551 | 570 | singleImageView.displayType = self.displayType |
| ... | ... | @@ -572,11 +591,13 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 572 | 591 | |
| 573 | 592 | // MARK: - 选取图片/视频 |
| 574 | 593 | func selectImageModel(model:CNLiveSelectUploadImageModel){ |
| 575 | - self.clickCallBack!() | |
| 594 | + if self.clickCallBack != nil{ | |
| 595 | + self.clickCallBack!() | |
| 596 | + } | |
| 576 | 597 | UIApplication.shared.keyWindow?.endEditing(true) |
| 577 | - if model.isVideo! == true{ | |
| 578 | - if model.localVideoUrl != nil{ | |
| 579 | - CNLiveCommonManager.shared.skipPlayerVCWithPlayURL(playURL: URL(string: model.videoUrl!)!, coverImage: model.image!, coverImageUrl: nil) | |
| 598 | + if (model.isVideo == true){ | |
| 599 | + if (model.localVideoUrl != nil){ | |
| 600 | + CNLiveCommonManager.shared.skipPlayerVCWithPlayURL(playURL: URL(string: model.videoUrl ?? "")!, coverImage: model.image!, coverImageUrl: nil) | |
| 580 | 601 | }else if model.videoUrl?.count ?? 0 > 0{ |
| 581 | 602 | CNLiveCommonManager.shared.skipPlayerVCWithPlayURL(playURL: model.localVideoUrl!, coverImage: nil, coverImageUrl: model.imageUrl) |
| 582 | 603 | }else{ |
| ... | ... | @@ -593,7 +614,7 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 593 | 614 | currentViewController()?.present(pickerController, animated: true) |
| 594 | 615 | } |
| 595 | 616 | }else{ |
| 596 | - if model.isSelectPhotoPlaceholder! == true{ | |
| 617 | + if (model.isSelectPhotoPlaceholder != nil) && (model.isSelectPhotoPlaceholder == true){ | |
| 597 | 618 | if self.uploadImageUrls.count >= self.maxSelectImageCount{ |
| 598 | 619 | let message = String(format: "最多只能选取%ld张图片", self.maxSelectImageCount) |
| 599 | 620 | showMessage(message: message) |
| ... | ... | @@ -612,17 +633,18 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 612 | 633 | currentViewController()?.present(pickerController, animated: true) |
| 613 | 634 | |
| 614 | 635 | }else{ |
| 615 | - if model.isUploading! == true || model.imageUrl == nil{ | |
| 636 | + if model.isUploading == true || model.imageUrl == nil{ | |
| 616 | 637 | return |
| 617 | 638 | } |
| 618 | 639 | let subviews = self.subviews |
| 619 | 640 | var currentPage = 0 |
| 620 | 641 | var images = [SKPhoto]() |
| 621 | 642 | for i in 0..<self.uploadImageUrls.count { |
| 622 | - var cmodel = self.uploadImageUrls[i] | |
| 623 | - if cmodel.isUploading == nil && cmodel.imageUrl?.count ?? 0 > 0{ | |
| 643 | + let cmodel = self.uploadImageUrls[i] | |
| 644 | + if cmodel.isUploading == false && cmodel.imageUrl?.count ?? 0 > 0{ | |
| 624 | 645 | let photo = SKPhoto.photoWithImageURL(cmodel.imageUrl!) |
| 625 | 646 | photo.shouldCachePhotoURLImage = false |
| 647 | + photo.photoURL = cmodel.imageUrl | |
| 626 | 648 | images.append(photo) |
| 627 | 649 | } |
| 628 | 650 | if cmodel.imageUrl == model.imageUrl{ |
| ... | ... | @@ -639,28 +661,42 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 639 | 661 | |
| 640 | 662 | // MARK: - 删除图片/视频 |
| 641 | 663 | func delteImageModel(model:CNLiveSelectUploadImageModel){ |
| 642 | - self.clickCallBack!() | |
| 664 | + if self.clickCallBack?() != nil{ | |
| 665 | + self.clickCallBack!() | |
| 666 | + } | |
| 667 | + | |
| 643 | 668 | UIApplication.shared.keyWindow?.endEditing(true) |
| 644 | 669 | let subviews = self.subviews |
| 645 | 670 | for i in 0..<subviews.count { |
| 646 | 671 | let singleImageView = self.viewWithTag(i+1+DS_SUIV_ADD_TAG_COUNT) as! CNLiveSelUplSingleImageView |
| 672 | + //TODO 目前imageUrl为nil | |
| 647 | 673 | if model.imageUrl == singleImageView.model?.imageUrl{ |
| 674 | + //要删除model的imageUrl和subview的imageUrl相等 | |
| 648 | 675 | if singleImageView.model?.isVideo == true{ |
| 676 | + //subview是视频 | |
| 649 | 677 | if singleImageView.model?.isUploading == true{ |
| 678 | + //subview正在上传中 | |
| 650 | 679 | UploadManager.shared.cancelUploadKey(key: singleImageView.model!.uploadKey!) |
| 651 | 680 | }else{ |
| 681 | + //subview上传完成 | |
| 682 | + //标记当前有视频,并替换model | |
| 652 | 683 | self.replaceVideoUrls.append(singleImageView.model!) |
| 653 | 684 | let videoModel = CNLiveSelectUploadImageModel() |
| 654 | 685 | videoModel.isVideo = true |
| 655 | 686 | self.uploadVideoModel = videoModel |
| 656 | 687 | } |
| 657 | 688 | }else{ |
| 689 | + //subview是纯图片 | |
| 658 | 690 | if singleImageView.model?.isUploading == true{ |
| 691 | + //上传中 | |
| 659 | 692 | UploadManager.shared.cancelUploadKey(key: singleImageView.model!.uploadKey!) |
| 660 | 693 | }else{ |
| 661 | - let index = self.uploadImageUrls.firstIndex(of: singleImageView.model!)! | |
| 662 | - self.uploadImageUrls.remove(at: index) | |
| 663 | - self.replaceImageUrls.append(singleImageView.model!) | |
| 694 | + //上传完成 | |
| 695 | + if let index = self.uploadImageUrls.firstIndex(of: singleImageView.model!){ | |
| 696 | + //移除上传完成的model | |
| 697 | + self.uploadImageUrls.remove(at: index) | |
| 698 | + self.replaceImageUrls.append(singleImageView.model!) | |
| 699 | + } | |
| 664 | 700 | } |
| 665 | 701 | } |
| 666 | 702 | break |
| ... | ... | @@ -668,85 +704,116 @@ class CNLiveAddGoodsSelectUploadImageView: UIView,UIImagePickerControllerDelegat |
| 668 | 704 | } |
| 669 | 705 | self.resetUI() |
| 670 | 706 | self.autoAdjustHeight() |
| 671 | - self.changeUploadDataCallBack!(self.getCurrentSelectImageUrls(),self.getCurrentSelectVideoUrl()) | |
| 707 | + if self.changeUploadDataCallBack?(self.getCurrentSelectImageUrls(),self.getCurrentSelectVideoUrl()) != nil{ | |
| 708 | + self.changeUploadDataCallBack!(self.getCurrentSelectImageUrls(),self.getCurrentSelectVideoUrl()) | |
| 709 | + } | |
| 672 | 710 | } |
| 673 | 711 | |
| 674 | 712 | // MARK: - PickerControllerDelegate |
| 675 | 713 | func pickerController(_ pickerController: HXPHPicker.PhotoPickerController, didFinishSelection result: HXPHPicker.PickerResult) { |
| 676 | - | |
| 677 | - | |
| 678 | - let photoAssets = result.photoAssets | |
| 679 | - for asset in photoAssets{ | |
| 680 | - if asset.mediaType == .video | |
| 681 | - { | |
| 682 | - let videoFileName = "\(asset.phAsset?.localIdentifier ?? "").mp4".replacingOccurrences(of: "-", with: "").replacingOccurrences(of: "/", with: "") | |
| 683 | - let videoURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(videoFileName) | |
| 684 | - | |
| 685 | - let videoData = NSData(contentsOf: videoURL) ?? NSData() | |
| 686 | - self.splitVideoFileUrlFps(splitFileUrl: videoURL, fps: 1) { isSucc,firstImage in | |
| 687 | - if isSucc{ | |
| 688 | - self.uploadVideoModel?.videoUrl = nil | |
| 689 | - self.uploadVideoModel?.image = firstImage.first | |
| 690 | - self.uploadVideoModel?.localVideoUrl = videoURL | |
| 691 | - self.uploadVideoModel?.isUploading = true | |
| 692 | - | |
| 693 | - self.uploadVideoModel?.uploadKey = UploadManager.uploadVideo(videoData: videoData, progressBlock: { [weak self] key, progress in | |
| 694 | - self!.uploadVideoModel?.uploadingPercent = progress | |
| 695 | - self?.replaceVideoModelInSubviews(model: (self?.uploadVideoModel)!, target: firstImage.first!) | |
| 696 | - }, successBlock: { [weak self] key,url in | |
| 697 | - self?.uploadVideoModel?.videoUrl = url | |
| 698 | - self?.uploadVideoModel?.isUploading = false | |
| 699 | - self?.uploadVideoModel?.uploadKey = nil | |
| 700 | - self?.replaceVideoModelInSubviews(model: (self?.uploadVideoModel)!, target: firstImage.first!) | |
| 701 | - self?.uploadingCount = self!.uploadingCount - 1 | |
| 702 | - if self?.uploadingCount == 0{ | |
| 714 | + result.getVideoURL { videoUrls in | |
| 715 | + if videoUrls.count == 0{ | |
| 716 | + return | |
| 717 | + } | |
| 718 | + let videoUrl = videoUrls.first! as URL | |
| 719 | + let videoData:NSData | |
| 720 | + do { | |
| 721 | + videoData = try NSData(contentsOf: videoUrl) ?? NSData() | |
| 722 | + print(videoData) | |
| 723 | + }catch{ | |
| 724 | + print("无法加载视频数据") | |
| 725 | + } | |
| 726 | + self.splitVideoFileUrlFps(splitFileUrl: videoUrl, fps: 1) { isSucc,firstImage in | |
| 727 | + if isSucc{ | |
| 728 | + self.uploadVideoModel?.videoUrl = nil | |
| 729 | + self.uploadVideoModel?.image = firstImage.first | |
| 730 | + self.uploadVideoModel?.localVideoUrl = videoUrl | |
| 731 | + self.uploadVideoModel?.isUploading = true | |
| 732 | + | |
| 733 | + self.uploadVideoModel?.uploadKey = UploadManager.uploadVideo(videoData: videoData, progressBlock: { [weak self] key, progress in | |
| 734 | + self!.uploadVideoModel?.uploadingPercent = progress | |
| 735 | + self?.replaceVideoModelInSubviews(model: (self?.uploadVideoModel)!, target: firstImage.first!) | |
| 736 | + }, successBlock: { [weak self] key,url in | |
| 737 | + self?.uploadVideoModel?.videoUrl = url | |
| 738 | + self?.uploadVideoModel?.isUploading = false | |
| 739 | + self?.uploadVideoModel?.uploadKey = nil | |
| 740 | + self?.replaceVideoModelInSubviews(model: (self?.uploadVideoModel)!, target: firstImage.first!) | |
| 741 | + self?.uploadingCount = self!.uploadingCount - 1 | |
| 742 | + if self?.uploadingCount == 0{ | |
| 743 | + if ((self?.endUploadImageCallBack?()) != nil){ | |
| 703 | 744 | self?.endUploadImageCallBack!() |
| 704 | 745 | } |
| 746 | + } | |
| 747 | + if ((self?.changeUploadDataCallBack?((self?.getCurrentSelectImageUrls())!,(self?.getCurrentSelectVideoUrl())!)) != nil){ | |
| 705 | 748 | self?.changeUploadDataCallBack!((self?.getCurrentSelectImageUrls())!,(self?.getCurrentSelectVideoUrl())!) |
| 706 | - }) | |
| 749 | + } | |
| 750 | + }) | |
| 751 | + DispatchQueue.main.async { | |
| 707 | 752 | self.resetUI() |
| 708 | 753 | self.autoAdjustHeight() |
| 709 | 754 | self.uploadingCount = self.uploadingCount + 1 |
| 710 | 755 | if self.uploadingCount == 1{ |
| 711 | - self.beginUploadImageCallBack!() | |
| 756 | + if ((self.beginUploadImageCallBack?()) != nil){ | |
| 757 | + self.beginUploadImageCallBack!() | |
| 758 | + } | |
| 712 | 759 | } |
| 760 | + | |
| 713 | 761 | } |
| 714 | 762 | } |
| 715 | - }else if asset.mediaType == .photo{ | |
| 716 | - let image = asset.localImageAsset?.image | |
| 717 | - let imageData = asset.localImageAsset?.imageData | |
| 718 | - var model = CNLiveSelectUploadImageModel() | |
| 763 | + } | |
| 764 | + | |
| 765 | + } | |
| 766 | + result.getImage { [weak self] img, photoAsset, index in | |
| 767 | + if photoAsset.mediaType == .video { | |
| 768 | + return | |
| 769 | + } | |
| 770 | + if let image = img { | |
| 771 | + let imageData = image.jpegData(compressionQuality: 1.0)! as NSData | |
| 772 | + let model = CNLiveSelectUploadImageModel() | |
| 719 | 773 | model.image = image |
| 720 | 774 | model.isUploading = true |
| 721 | 775 | |
| 722 | - self.uploadVideoModel?.uploadKey = UploadManager.uploadImage(imageData: imageData! as NSData) { [weak self] key, percent in | |
| 776 | + self!.uploadVideoModel?.uploadKey = UploadManager.uploadImage(imageData: imageData) { [weak self] key, percent in | |
| 723 | 777 | model.uploadingPercent = percent |
| 724 | - self?.replaceImageModelInDataArr(model: model, target: image!) | |
| 778 | + self?.replaceImageModelInDataArr(model: model, target: image) | |
| 725 | 779 | } successBlock: { key, url in |
| 726 | 780 | model.imageUrl = url |
| 727 | 781 | model.isUploading = false |
| 728 | 782 | model.uploadKey = nil |
| 729 | - self.replaceImageModelInDataArr(model: model, target: image!) | |
| 783 | + self!.replaceImageModelInDataArr(model: model, target: image) | |
| 730 | 784 | |
| 731 | - self.uploadingCount = self.uploadingCount - 1 | |
| 785 | + self!.uploadingCount = self!.uploadingCount - 1 | |
| 732 | 786 | |
| 733 | - if self.uploadingCount == 0{ | |
| 734 | - self.endUploadImageCallBack!() | |
| 787 | + if self!.uploadingCount == 0{ | |
| 788 | + if self!.endUploadImageCallBack?() != nil{ | |
| 789 | + self!.endUploadImageCallBack!() | |
| 790 | + } | |
| 791 | + } | |
| 792 | + | |
| 793 | + if self!.changeUploadDataCallBack?(self!.getCurrentSelectImageUrls(),self!.getCurrentSelectVideoUrl()) != nil{ | |
| 794 | + self!.changeUploadDataCallBack!(self!.getCurrentSelectImageUrls(),self!.getCurrentSelectVideoUrl()) | |
| 735 | 795 | } |
| 736 | - self.changeUploadDataCallBack!(self.getCurrentSelectImageUrls(),self.getCurrentSelectVideoUrl()) | |
| 737 | 796 | } |
| 738 | - self.uploadImageUrls.append(model) | |
| 739 | - self.resetUI() | |
| 740 | - self.autoAdjustHeight() | |
| 741 | - self.uploadingCount = self.uploadingCount + 1 | |
| 742 | - if self.uploadingCount == 1{ | |
| 743 | - self.beginUploadImageCallBack!() | |
| 797 | + self!.uploadImageUrls.append(model) | |
| 798 | + self!.resetUI() | |
| 799 | + self!.autoAdjustHeight() | |
| 800 | + self!.uploadingCount = self!.uploadingCount + 1 | |
| 801 | + if self!.uploadingCount == 1{ | |
| 802 | + if self!.beginUploadImageCallBack?() != nil{ | |
| 803 | + self!.beginUploadImageCallBack!() | |
| 804 | + } | |
| 744 | 805 | } |
| 806 | + }else{ | |
| 807 | + print("failed") | |
| 745 | 808 | } |
| 809 | + } completionHandler: { (images) in | |
| 810 | + | |
| 746 | 811 | } |
| 747 | 812 | pickerController.dismiss(animated: true) |
| 748 | 813 | } |
| 749 | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 750 | 817 | // MARK: - 获取视频的第一帧 |
| 751 | 818 | func splitVideoFileUrlFps(splitFileUrl: URL, fps: Float, splitCompleteClosure: @escaping (Bool, [UIImage]) -> Void) { |
| 752 | 819 | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveSelUplSingleImageView.swift
| ... | ... | @@ -89,13 +89,13 @@ class CNLiveSelUplSingleImageView: UIView { |
| 89 | 89 | self.model = model |
| 90 | 90 | self.isHideDeleteBtn = isHideDeleteBtn |
| 91 | 91 | self.isCover = isCover |
| 92 | - if self.model?.isSelectPhotoPlaceholder! == true{ | |
| 92 | + if (self.model?.isSelectPhotoPlaceholder != nil && self.model?.isSelectPhotoPlaceholder == true){ | |
| 93 | 93 | self.displayImageView?.image = UIImage(named: "DS_SelUplImageView_selectImage") |
| 94 | 94 | self.progressLab?.isHidden = true |
| 95 | 95 | self.deleteBtn?.isHidden = true |
| 96 | 96 | self.playImageView?.isHidden = true |
| 97 | 97 | self.coverBtn?.isHidden = true |
| 98 | - }else if self.model?.isVideo! == true{ | |
| 98 | + }else if (self.model?.isVideo == true && self.model?.isVideo != nil){ | |
| 99 | 99 | if self.model?.videoUrl?.count ?? 0 > 0{ |
| 100 | 100 | self.displayImageView?.image = self.model?.image |
| 101 | 101 | if self.model?.image == nil{ |
| ... | ... | @@ -108,9 +108,9 @@ class CNLiveSelUplSingleImageView: UIView { |
| 108 | 108 | self.deleteBtn?.isHidden = false |
| 109 | 109 | } |
| 110 | 110 | self.playImageView?.isHidden = false |
| 111 | - }else if self.model?.isUploading! == true{ | |
| 111 | + }else if (self.model?.isUploading != nil && self.model?.isUploading == true){ | |
| 112 | 112 | self.displayImageView?.image = self.model?.image |
| 113 | - self.progressLab?.text = String(format: "%.0f%%", (self.model?.uploadingPercent)!*100) | |
| 113 | + self.progressLab?.text = String(format: "%.0f%%", (self.model!.uploadingPercent)*100) | |
| 114 | 114 | self.progressLab?.isHidden = false |
| 115 | 115 | self.deleteBtn?.isHidden = false |
| 116 | 116 | self.playImageView?.isHidden = true |
| ... | ... | @@ -133,12 +133,12 @@ class CNLiveSelUplSingleImageView: UIView { |
| 133 | 133 | self.deleteBtn?.isHidden = false |
| 134 | 134 | } |
| 135 | 135 | }else if self.model?.isUploading! == true{ |
| 136 | - self.progressLab?.text = String(format: "%.0f%%", (self.model?.uploadingPercent)!*100) | |
| 136 | + self.progressLab?.text = String(format: "%.0f%%", self.model?.uploadingPercent ?? 0 * 100) | |
| 137 | 137 | self.progressLab?.isHidden = false |
| 138 | 138 | self.deleteBtn?.isHidden = false |
| 139 | 139 | } |
| 140 | 140 | self.playImageView?.isHidden = true |
| 141 | - self.coverBtn?.isHidden = self.isDisplySelectCover! == true ? false : true | |
| 141 | + self.coverBtn?.isHidden = (self.isDisplySelectCover != nil && self.isDisplySelectCover == true) ? false : true | |
| 142 | 142 | if self.isCover == true{ |
| 143 | 143 | self.coverBtn?.setTitle("主页", for: .normal) |
| 144 | 144 | self.coverBtn?.setTitleColor(HexColor("#F5A623"), for: .normal) |
| ... | ... | @@ -189,8 +189,8 @@ class CNLiveSelUplSingleImageView: UIView { |
| 189 | 189 | self.deleteImageView?.frame = CGRect(x: self.deleteBtn!.width-17, y: 0, width: 17, height: 17) |
| 190 | 190 | self.displayImageView?.frame = CGRect(x: 0, y: self.deleteImageView!.height/2, width: self.width-self.deleteImageView!.width/2, height: self.width-self.deleteImageView!.height/2) |
| 191 | 191 | self.progressLab?.frame = self.displayImageView!.frame |
| 192 | - self.playImageView?.frame = CGRect(x: self.displayImageView!.width-26/2, y: self.displayImageView!.top+self.displayImageView!.height-26/2, width: 26, height: 26) | |
| 193 | - self.coverBtn?.frame = CGRect(x: self.displayImageView!.left, y: self.displayImageView!.bottom, width: self.displayImageView!.width, height: 20) | |
| 192 | + self.playImageView?.frame = CGRect(x: (self.displayImageView!.width-26)/2, y: self.displayImageView!.top+(self.displayImageView!.height-26)/2, width: 26, height: 26) | |
| 193 | + self.coverBtn?.frame = CGRect(x: self.displayImageView!.left, y: self.displayImageView!.bottom-20, width: self.displayImageView!.width, height: 20) | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // MARK: - initUI | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopAddGoodsSingleView.swift
| ... | ... | @@ -47,7 +47,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 47 | 47 | var delectButton = UIButton() |
| 48 | 48 | var rightImageView = UIImageView() |
| 49 | 49 | var contentSwitch = UISwitch() |
| 50 | - var uploadImageView = CNLiveAddGoodsSelectUploadImageView(frame: CGRectZero) | |
| 50 | + var uploadImageView = CNLiveAddGoodsSelectUploadImageView() | |
| 51 | 51 | var contentTextBgView = CNLiveRoundedRectView() |
| 52 | 52 | var contentTextView = CNLiveShopTextView() |
| 53 | 53 | var addBtn = UIButton() |
| ... | ... | @@ -59,9 +59,9 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 59 | 59 | //开始输入前的文本 |
| 60 | 60 | var beginText:String? |
| 61 | 61 | |
| 62 | - override init(frame: CGRect) { | |
| 62 | + init(frame: CGRect,model:CNLiveShopAddEditGoodsListModel) { | |
| 63 | 63 | super.init(frame: frame) |
| 64 | - | |
| 64 | + self.addEditGoodsListModel = model | |
| 65 | 65 | NotificationCenter.default.addObserver(self, selector: #selector(textFieldTextDidChangeNotification), name: Notification.Name("UITextFieldTextDidChangeNotification"), object:nil) |
| 66 | 66 | self.addObserver(self, forKeyPath: "tag",options: [.new,.old],context: nil) |
| 67 | 67 | |
| ... | ... | @@ -101,7 +101,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 101 | 101 | { |
| 102 | 102 | self.titleLabel.textColor = HexColor("#333333") |
| 103 | 103 | if (self.addEditGoodsListModel?.subtitle?.count ?? 0 > 0) { |
| 104 | - self.titleLabel.text = "\(self.addEditGoodsListModel?.title ?? "")+\(self.addEditGoodsListModel?.subtitle ?? "")" | |
| 104 | + self.titleLabel.text = "\(self.addEditGoodsListModel?.title ?? "")\(self.addEditGoodsListModel?.subtitle ?? "")" | |
| 105 | 105 | }else{ |
| 106 | 106 | self.titleLabel.text = self.addEditGoodsListModel?.title ?? "" |
| 107 | 107 | } |
| ... | ... | @@ -169,8 +169,8 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 169 | 169 | self.uploadImageView = CNLiveAddGoodsSelectUploadImageView(frame: CGRectZero) |
| 170 | 170 | self.uploadImageView.column = 3 |
| 171 | 171 | self.uploadImageView.maxSelectImageCount = (model.maxSelectImageCount! as NSString).integerValue |
| 172 | - self.uploadImageView.isAbleSelectVideo = model.isAbleSelectVideo | |
| 173 | - self.uploadImageView.isDisplySelectCover = model.isAbleSelectCover | |
| 172 | + self.uploadImageView.isAbleSelectVideo = model.isAbleSelectVideo ?? false | |
| 173 | + self.uploadImageView.isDisplySelectCover = model.isAbleSelectCover ?? false | |
| 174 | 174 | if model.id?.isEmpty == true { |
| 175 | 175 | self.uploadImageView.deleteImage = UIImage(named: "DS_shop_manageGoodsDetails_delete") |
| 176 | 176 | } |
| ... | ... | @@ -252,7 +252,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 252 | 252 | if (self.addEditGoodsListModel!.contentType == "1") { |
| 253 | 253 | if (self.addEditGoodsListModel!.isDelect ?? false) { |
| 254 | 254 | self.delectButton.frame = CGRect(x: KSreenWidth-50, y: 0, width: 40, height: 50) |
| 255 | - self.contentTextField.frame = CGRect(x: self.titleLabel.right+15, y: 0, width: self.width-self.titleLabel.right+15*2-40, height: 50) | |
| 255 | + self.contentTextField.frame = CGRect(x: self.titleLabel.right+15, y: 0, width: self.width-self.titleLabel.right-15*2-40, height: 50) | |
| 256 | 256 | }else{ |
| 257 | 257 | self.contentTextField.frame = CGRect(x: self.titleLabel.right+15, y: 0, width: self.width-self.titleLabel.right-15*2, height: 50) |
| 258 | 258 | } |
| ... | ... | @@ -271,7 +271,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 271 | 271 | } |
| 272 | 272 | self.addSubview(self.contentTextField) |
| 273 | 273 | }else if (self.addEditGoodsListModel!.style == "3") { |
| 274 | - self.uploadImageView.frame = CGRect(x: 0, y: self.titleLabel.bottom+2, width: self.width, height: 0) | |
| 274 | + self.uploadImageView.frame = CGRect(x: 0, y: self.titleLabel.bottom+2, width: self.width, height: 50) | |
| 275 | 275 | if (self.height == 0) { |
| 276 | 276 | self.height = self.uploadImageView.bottom+15 |
| 277 | 277 | if ((self.updateFrameBlock) != nil) { |
| ... | ... | @@ -311,9 +311,9 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 311 | 311 | } |
| 312 | 312 | @objc func selectDelectParamAction(){ |
| 313 | 313 | AlertTool.showSystemAlert(title: "确认删除?", message: nil, actionTitles: ["取消","确定"], style: .alert, actionStyles:[.cancel,.default] ) { index in |
| 314 | - if (index == 1) { | |
| 315 | - if ((self.updateFrameBlock) != nil) { | |
| 316 | - self.updateFrameBlock!() | |
| 314 | + if (index == 2) { | |
| 315 | + if ((self.changeFrameBlock) != nil) { | |
| 316 | + self.changeFrameBlock!(true, self.addEditGoodsListModel!, self) | |
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | } |
| ... | ... | @@ -522,7 +522,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate, UITextViewDeleg |
| 522 | 522 | cs = CharacterSet(charactersIn: string).inverted |
| 523 | 523 | let filterArr = string.components(separatedBy: cs) |
| 524 | 524 | // 对比一下是否为数字 |
| 525 | - return filterArr.count == string.count ? true:false | |
| 525 | + return filterArr.first!.count == string.count ? true:false | |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | } | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopClassifySwitchTableViewCell.swift
| ... | ... | @@ -49,6 +49,7 @@ class CNLiveShopClassifySwitchTableViewCell: UITableViewCell { |
| 49 | 49 | override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { |
| 50 | 50 | super.init(style: style, reuseIdentifier: reuseIdentifier) |
| 51 | 51 | self.selectionStyle = .none |
| 52 | + self.initUI() | |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | required init?(coder: NSCoder) { | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopClassilyIconTableViewCell.swift
| ... | ... | @@ -16,7 +16,7 @@ class CNLiveShopClassilyIconTableViewCell: UITableViewCell { |
| 16 | 16 | var selectUploadImageView:CNLiveAddGoodsSelectUploadImageView?{ |
| 17 | 17 | get{ |
| 18 | 18 | if _selectUploadImageView == nil{ |
| 19 | - _selectUploadImageView = CNLiveAddGoodsSelectUploadImageView() | |
| 19 | + _selectUploadImageView = CNLiveAddGoodsSelectUploadImageView(frame: CGRect(x: 0, y: 40, width: 120, height: 120)) | |
| 20 | 20 | _selectUploadImageView?.maxSelectImageCount = 1 |
| 21 | 21 | _selectUploadImageView?.isAbleSelectVideo = false |
| 22 | 22 | _selectUploadImageView?.deleteImage = UIImage(named: "DS_happ_daren_dynamic_delete") |
| ... | ... | @@ -60,6 +60,7 @@ class CNLiveShopClassilyIconTableViewCell: UITableViewCell { |
| 60 | 60 | override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { |
| 61 | 61 | super.init(style: style, reuseIdentifier: reuseIdentifier) |
| 62 | 62 | self.selectionStyle = .none |
| 63 | + self.initUI() | |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | required init?(coder: NSCoder) { |
| ... | ... | @@ -78,6 +79,6 @@ class CNLiveShopClassilyIconTableViewCell: UITableViewCell { |
| 78 | 79 | make.top.equalTo(0) |
| 79 | 80 | make.height.equalTo(40) |
| 80 | 81 | } |
| 81 | - self.selectUploadImageView?.frame = CGRect(x: 0, y: 40, width: 120, height: 120) | |
| 82 | + | |
| 82 | 83 | } |
| 83 | 84 | } | ... | ... |
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopGoodsManageDetailsInputManager.swift
| ... | ... | @@ -87,14 +87,22 @@ class CNLiveShopGoodsManageDetailsInputManager:NSObject{ |
| 87 | 87 | |
| 88 | 88 | let modalViewController = CNLiveModalPresentationViewController() |
| 89 | 89 | modalViewController.contentView = contentView |
| 90 | + | |
| 91 | + currentViewController()?.addChild(modalViewController) | |
| 92 | + modalViewController.didMove(toParent: currentViewController()) | |
| 93 | + currentViewController()?.view.addSubview(modalViewController.view) | |
| 90 | 94 | modalViewController.showingAnimationWithCompletion { finished in |
| 91 | 95 | |
| 92 | 96 | } |
| 93 | 97 | self.modalViewController = modalViewController |
| 94 | 98 | |
| 95 | - cancelButton.addTarget(modalViewController, action: #selector(cancelButtonAction), for: .touchUpInside) | |
| 99 | + cancelButton.addTarget(self, action: #selector(cancelButtonAction), for: .touchUpInside) | |
| 100 | + confirmButton.addTarget(self, action: #selector(confirmButtonAction), for: .touchUpInside) | |
| 96 | 101 | |
| 97 | 102 | self.completerBlock = completeBlock |
| 103 | + self.modalViewController.confirmBlock = { | |
| 104 | + self.confirmButtonAction() | |
| 105 | + } | |
| 98 | 106 | } |
| 99 | 107 | |
| 100 | 108 | @objc func cancelButtonAction(){ | ... | ... |
metaCode/Classes/Main/Model/GoodsDetail/CNLiveSelectUploadImageModel.swift
| ... | ... | @@ -16,7 +16,7 @@ class CNLiveSelectUploadImageModel: BaseModel,Equatable { |
| 16 | 16 | /** |
| 17 | 17 | 是否是视频 |
| 18 | 18 | */ |
| 19 | - var isVideo:Bool? | |
| 19 | + var isVideo:Bool = false | |
| 20 | 20 | /** |
| 21 | 21 | 本地视频路径 |
| 22 | 22 | */ |
| ... | ... | @@ -36,7 +36,7 @@ class CNLiveSelectUploadImageModel: BaseModel,Equatable { |
| 36 | 36 | /** |
| 37 | 37 | 是否正在上传中 |
| 38 | 38 | */ |
| 39 | - var isUploading:Bool? | |
| 39 | + var isUploading:Bool = false | |
| 40 | 40 | /** |
| 41 | 41 | 上传的key 用于取消上传 |
| 42 | 42 | */ |
| ... | ... | @@ -44,7 +44,7 @@ class CNLiveSelectUploadImageModel: BaseModel,Equatable { |
| 44 | 44 | /** |
| 45 | 45 | 上传百分比 0~1 |
| 46 | 46 | */ |
| 47 | - var uploadingPercent:CGFloat? | |
| 47 | + var uploadingPercent:CGFloat = 0 | |
| 48 | 48 | |
| 49 | 49 | static func == (lhs: CNLiveSelectUploadImageModel, rhs: CNLiveSelectUploadImageModel) -> Bool { |
| 50 | 50 | ... | ... |
metaCode/Classes/Main/Model/GoodsDetail/CNLiveShopGoodsDetailsModel.swift
metaCode/Classes/Main/Model/GoodsManager/CNLiveShopAddEditGoodsModel.swift
| ... | ... | @@ -11,6 +11,7 @@ class CNLiveShopAddEditGoodsModel: BaseModel { |
| 11 | 11 | ///列表 |
| 12 | 12 | var list = [CNLiveShopAddEditGoodsListModel]() |
| 13 | 13 | func initDataSource(){ |
| 14 | + if self.list.count > 0 {return} | |
| 14 | 15 | var dataArr:Array<Any> = [] |
| 15 | 16 | let dic1 = ["style":"1","isHaveTo":true,"title":"商品分类","contentType":"2"] as [String : Any] |
| 16 | 17 | let dic2 = ["style":"1","isHaveTo":true,"title":"店铺分类","contentType":"2"] as [String : Any] |
| ... | ... | @@ -18,7 +19,7 @@ class CNLiveShopAddEditGoodsModel: BaseModel { |
| 18 | 19 | let dic4 = ["style":"3","isHaveTo":true,"title":"商品轮播","isDisplayLine":true,"isAbleSelectVideo":true,"isAbleSelectCover":true,"maxSelectImageCount":"7"] as [String : Any] |
| 19 | 20 | let dic5 = ["style":"1","isHaveTo":true,"title":"商品名称","isDisplayLine":true,"contentType":"1"] as [String : Any] |
| 20 | 21 | let dic6 = ["style":"4","isHaveTo":false,"title":"商品副标题","isDisplayLine":true,"placeholder":"请在此输入..."] as [String : Any] |
| 21 | - let dic7 = ["style":"1","isHaveTo":true,"title":"本店售价","subtitle":"(实际售价)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentTextColor":"0xFC1541","contentType":"1"] as [String : Any] | |
| 22 | + let dic7 = ["style":"1","isHaveTo":true,"title":"本店售价","subtitle":"(实际售价)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentTextColor":"#FC1541","contentType":"1"] as [String : Any] | |
| 22 | 23 | let dic8 = ["style":"1","isHaveTo":true,"title":"市场售价","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentType":"1"] as [String : Any] |
| 23 | 24 | let dic9 = ["style":"1","isHaveTo":false,"title":"商品重量","subtitle":"(kg)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"3","contentType":"1"] as [String : Any] |
| 24 | 25 | let dic10 = ["style":"5","isHaveTo":false,"title":"最低起售","subtitle":"(件)","isDisplayLine":true,"desc":"如起售数超出库存买家无法购买","decimalLength":"3","contentType":"4"] as [String : Any] |
| ... | ... | @@ -68,7 +69,7 @@ class CNLiveShopAddEditGoodsModel: BaseModel { |
| 68 | 69 | // ["style":"3","isHaveTo":true,"title":"商品轮播","isDisplayLine":true,"isAbleSelectVideo":true,"isAbleSelectCover":true,"maxSelectImageCount":"7"], |
| 69 | 70 | // ["style":"1","isHaveTo":true,"title":"商品名称","isDisplayLine":true,"contentType":"1"], |
| 70 | 71 | // ["style":"4","isHaveTo":false,"title":"商品副标题","isDisplayLine":true,"placeholder":"请在此输入..."], |
| 71 | -// ["style":"1","isHaveTo":true,"title":"本店售价","subtitle":"(实际售价)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentTextColor":"0xFC1541","contentType":"1"], | |
| 72 | +// ["style":"1","isHaveTo":true,"title":"本店售价","subtitle":"(实际售价)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentTextColor":"#FC1541","contentType":"1"], | |
| 72 | 73 | // ["style":"1","isHaveTo":true,"title":"市场售价","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"2","contentType":"1"], |
| 73 | 74 | // ["style":"1","isHaveTo":false,"title":"商品重量","subtitle":"(kg)","isDisplayLine":true,"contentTextFieldkeyboardType":"2","decimalLength":"3","contentType":"1"], |
| 74 | 75 | // ["style":"5","isHaveTo":false,"title":"最低起售","subtitle":"(件)","isDisplayLine":true,"desc":"如起售数超出库存买家无法购买","decimalLength":"3","contentType":"4"], |
| ... | ... | @@ -122,7 +123,7 @@ class CNLiveShopAddEditGoodsListModel: BaseModel { |
| 122 | 123 | var contentTextFieldkeyboardType:String? |
| 123 | 124 | /// 样式一属性 小数点位数 |
| 124 | 125 | var decimalLength:String? |
| 125 | - /// 样式一属性 内容输入框颜色 默认0x787878 | |
| 126 | + /// 样式一属性 内容输入框颜色 默认#787878 | |
| 126 | 127 | var contentTextColor: String? |
| 127 | 128 | /// 样式一属性 1输入框 2选择 3开关 4可以增加数量 |
| 128 | 129 | var contentType:String? | ... | ... |
metaCode/Classes/Main/Util/CNLiveCommonManager.swift
| ... | ... | @@ -18,7 +18,7 @@ class CNLiveCommonManager: NSObject{ |
| 18 | 18 | /// @param coverImage 封面图 |
| 19 | 19 | /// @param coverImageUrl 封面图url |
| 20 | 20 | func skipPlayerVCWithPlayURL(playURL:URL,coverImage:UIImage?,coverImageUrl:String?){ |
| 21 | - var vc = CNLivePlayerViewController() | |
| 21 | + let vc = CNLivePlayerViewController() | |
| 22 | 22 | vc.setPlayUrl(playUrl: playURL, isLive: false) |
| 23 | 23 | vc.coverImageUrl = coverImageUrl |
| 24 | 24 | currentViewController()?.navigationController?.pushViewController(vc, animated: false) | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerBottomNaviView.swift
| ... | ... | @@ -37,14 +37,14 @@ class CNLivePlayerBottomNaviView:UIView{ |
| 37 | 37 | |
| 38 | 38 | // MARK: - 属性 |
| 39 | 39 | /// 是否是横屏 |
| 40 | - var _isLandscape:Bool? | |
| 40 | + var _isLandscape:Bool = false | |
| 41 | 41 | var isLandscape:Bool?{ |
| 42 | 42 | get{ |
| 43 | 43 | _isLandscape |
| 44 | 44 | } |
| 45 | 45 | set{ |
| 46 | - _isLandscape = newValue | |
| 47 | - if _isLandscape!{ | |
| 46 | + _isLandscape = newValue! | |
| 47 | + if _isLandscape{ | |
| 48 | 48 | self.frameImageView?.image = UIImage(named: "DS_player_reduce") |
| 49 | 49 | }else{ |
| 50 | 50 | self.frameImageView?.image = UIImage(named: "DS_player_magnify") | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerControlView.swift
| ... | ... | @@ -46,7 +46,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 46 | 46 | /// 播放器 |
| 47 | 47 | weak var player:PLPlayer? |
| 48 | 48 | /// 视频链接是否为直播 |
| 49 | - var isLive:Bool? | |
| 49 | + var isLive:Bool = false | |
| 50 | 50 | // MARK: - UI |
| 51 | 51 | /// 封面图 |
| 52 | 52 | var _coverImageView:UIImageView? |
| ... | ... | @@ -241,7 +241,9 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 241 | 241 | } |
| 242 | 242 | set{ |
| 243 | 243 | _coverImageUrl = newValue |
| 244 | - self.coverImageView?.kf.setImage(with: URL(string: _coverImageUrl!)) | |
| 244 | + if _coverImageUrl != nil{ | |
| 245 | + self.coverImageView?.kf.setImage(with: URL(string: _coverImageUrl!)) | |
| 246 | + } | |
| 245 | 247 | } |
| 246 | 248 | } |
| 247 | 249 | |
| ... | ... | @@ -258,9 +260,9 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 258 | 260 | } |
| 259 | 261 | |
| 260 | 262 | /// 是否隐藏信息视图 |
| 261 | - var isAlphaMessage:Bool? | |
| 263 | + var isAlphaMessage:Bool = false | |
| 262 | 264 | /// 是否锁屏 |
| 263 | - var isLockScreen:Bool? | |
| 265 | + var isLockScreen:Bool = false | |
| 264 | 266 | /// 全屏样式 |
| 265 | 267 | var _fullScreenType:CNLivePlayerFullScreenType? |
| 266 | 268 | var fullScreenType:CNLivePlayerFullScreenType?{ |
| ... | ... | @@ -274,13 +276,13 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 274 | 276 | } |
| 275 | 277 | |
| 276 | 278 | /// 是否全屏 |
| 277 | - var _isFullScreen:Bool? | |
| 279 | + var _isFullScreen:Bool = false | |
| 278 | 280 | var isFullScreen:Bool?{ |
| 279 | 281 | get{ |
| 280 | 282 | _isFullScreen |
| 281 | 283 | } |
| 282 | 284 | set{ |
| 283 | - _isFullScreen = newValue | |
| 285 | + _isFullScreen = newValue! | |
| 284 | 286 | // [DSCnliveShopSDKManager sharedManager].isNeedLandscapeMask = _isFullScreen; |
| 285 | 287 | |
| 286 | 288 | } |
| ... | ... | @@ -312,7 +314,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 312 | 314 | fullScreenType == DSPlayerFullScreenTypeInWindowOrientation 时默认 50 |
| 313 | 315 | fullScreenType == DSPlayerFullScreenTypeFullDisplayOfVideoInterface 时默认 导航高度 |
| 314 | 316 | */ |
| 315 | - var _portraitTopNaviHeight:CGFloat = 0 | |
| 317 | + var _portraitTopNaviHeight:CGFloat = 50 | |
| 316 | 318 | var portraitTopNaviHeight:CGFloat{ |
| 317 | 319 | get{ |
| 318 | 320 | if (_portraitTopNaviHeight > 0) { |
| ... | ... | @@ -419,7 +421,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 419 | 421 | } |
| 420 | 422 | set{ |
| 421 | 423 | _autoHideControlsTime = newValue |
| 422 | - if _autoHideControlsTime <= 0 && !self.isAlphaMessage! && self.player?.status == .statusPlaying{ | |
| 424 | + if _autoHideControlsTime <= 0 && !self.isAlphaMessage && self.player?.status == .statusPlaying{ | |
| 423 | 425 | self.isAlphaMessage = true |
| 424 | 426 | self.hideOrDisplayControls() |
| 425 | 427 | } |
| ... | ... | @@ -551,8 +553,8 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 551 | 553 | |
| 552 | 554 | @objc func lockBtnClick(){ |
| 553 | 555 | self.autoHideControlsTime = CGFloat(kDSPlayerAutoHideControlsTime) |
| 554 | - self.isLockScreen = !self.isLockScreen! | |
| 555 | - if self.isLockScreen!{ | |
| 556 | + self.isLockScreen = !self.isLockScreen | |
| 557 | + if self.isLockScreen{ | |
| 556 | 558 | self.lockBtn?.setBackgroundImage(UIImage(named: "DS_player_lock_close"), for: .normal) |
| 557 | 559 | self.topNaviView?.isUserInteractionEnabled = false |
| 558 | 560 | self.bottomNaviView?.isUserInteractionEnabled = false |
| ... | ... | @@ -570,8 +572,8 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 570 | 572 | func hideOrDisplayControls(){ |
| 571 | 573 | self.switchAlphaMessageStateCallBack!() |
| 572 | 574 | UIView.animate(withDuration: CGFloat(kDSPlayerAnimateTimeInterval)) { |
| 573 | - if self.isLockScreen! == false{ | |
| 574 | - if self.isAlphaMessage!{ | |
| 575 | + if self.isLockScreen == false{ | |
| 576 | + if self.isAlphaMessage{ | |
| 575 | 577 | self.topNaviView?.alpha = 0 |
| 576 | 578 | self.bottomNaviView?.alpha = 0 |
| 577 | 579 | self.bottomProgressView?.alpha = 1 |
| ... | ... | @@ -588,7 +590,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 588 | 590 | self.bottomProgressView?.alpha = 0 |
| 589 | 591 | } |
| 590 | 592 | }else{ |
| 591 | - if (self.isAlphaMessage!) { | |
| 593 | + if (self.isAlphaMessage) { | |
| 592 | 594 | self.topNaviView?.alpha = 0 |
| 593 | 595 | self.bottomNaviView?.alpha = 0 |
| 594 | 596 | self.bottomProgressView?.alpha = 1 |
| ... | ... | @@ -674,7 +676,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 674 | 676 | func gestureViewSingleTap(gestureView: CNLivePlayerGestureView, recognizer: UITapGestureRecognizer) { |
| 675 | 677 | |
| 676 | 678 | self.autoHideControlsTime = CGFloat(kDSPlayerAutoHideControlsTime) |
| 677 | - self.isAlphaMessage = !self.isAlphaMessage! | |
| 679 | + self.isAlphaMessage = !self.isAlphaMessage | |
| 678 | 680 | self.hideOrDisplayControls() |
| 679 | 681 | } |
| 680 | 682 | |
| ... | ... | @@ -697,7 +699,7 @@ class CNLivePlayerControlView:UIView,CNLivePlayerGestureViewDelegate{ |
| 697 | 699 | self.isUserInteractionEnabled = false |
| 698 | 700 | let velocity = panGestureRecognizer.velocity(in: panGestureRecognizer.view) |
| 699 | 701 | if abs(velocity.y) < abs(velocity.x){ |
| 700 | - if self.isLive!{ | |
| 702 | + if self.isLive{ | |
| 701 | 703 | panGestureRecognizer.isEnabled = false |
| 702 | 704 | let delayTime = DispatchTime.now() + DispatchTimeInterval.seconds(Int(0.1)) |
| 703 | 705 | DispatchQueue.main.asyncAfter(deadline: delayTime) { | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerGestureView.swift
| ... | ... | @@ -41,12 +41,14 @@ class CNLivePlayerGestureView:UIView{ |
| 41 | 41 | } |
| 42 | 42 | set{ |
| 43 | 43 | _style = newValue |
| 44 | - self.removeGestureRecognizer(self.singleTapGestureRecognizer!) | |
| 45 | - self.singleTapGestureRecognizer = nil | |
| 46 | - self.removeGestureRecognizer(self.doubleTapGestureRecognizer!) | |
| 47 | - self.doubleTapGestureRecognizer = nil | |
| 48 | - self.removeGestureRecognizer(self.panGestureRecognizer!) | |
| 49 | - self.panGestureRecognizer = nil | |
| 44 | + if self.singleTapGestureRecognizer != nil && self.doubleTapGestureRecognizer != nil && self.panGestureRecognizer != nil{ | |
| 45 | + self.removeGestureRecognizer(self.singleTapGestureRecognizer!) | |
| 46 | + self.singleTapGestureRecognizer = nil | |
| 47 | + self.removeGestureRecognizer(self.doubleTapGestureRecognizer!) | |
| 48 | + self.doubleTapGestureRecognizer = nil | |
| 49 | + self.removeGestureRecognizer(self.panGestureRecognizer!) | |
| 50 | + self.panGestureRecognizer = nil | |
| 51 | + } | |
| 50 | 52 | self.addGesture() |
| 51 | 53 | } |
| 52 | 54 | } |
| ... | ... | @@ -60,12 +62,14 @@ class CNLivePlayerGestureView:UIView{ |
| 60 | 62 | } |
| 61 | 63 | set{ |
| 62 | 64 | _private_style = newValue |
| 63 | - self.removeGestureRecognizer(self.singleTapGestureRecognizer!) | |
| 64 | - self.singleTapGestureRecognizer = nil | |
| 65 | - self.removeGestureRecognizer(self.doubleTapGestureRecognizer!) | |
| 66 | - self.doubleTapGestureRecognizer = nil | |
| 67 | - self.removeGestureRecognizer(self.panGestureRecognizer!) | |
| 68 | - self.panGestureRecognizer = nil | |
| 65 | + if self.singleTapGestureRecognizer != nil && self.doubleTapGestureRecognizer != nil && self.panGestureRecognizer != nil{ | |
| 66 | + self.removeGestureRecognizer(self.singleTapGestureRecognizer!) | |
| 67 | + self.singleTapGestureRecognizer = nil | |
| 68 | + self.removeGestureRecognizer(self.doubleTapGestureRecognizer!) | |
| 69 | + self.doubleTapGestureRecognizer = nil | |
| 70 | + self.removeGestureRecognizer(self.panGestureRecognizer!) | |
| 71 | + self.panGestureRecognizer = nil | |
| 72 | + } | |
| 69 | 73 | self.addGesture() |
| 70 | 74 | } |
| 71 | 75 | } | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerLoadingView.swift
| ... | ... | @@ -12,13 +12,13 @@ class CNLivePlayerLoadingView:UIView,CAAnimationDelegate{ |
| 12 | 12 | /** |
| 13 | 13 | 是否在加载中 |
| 14 | 14 | */ |
| 15 | - var _isLoading:Bool? | |
| 15 | + var _isLoading:Bool = false | |
| 16 | 16 | var isLoading:Bool?{ |
| 17 | 17 | get{ |
| 18 | 18 | _isLoading |
| 19 | 19 | } |
| 20 | 20 | set{ |
| 21 | - _isLoading = newValue | |
| 21 | + _isLoading = newValue! | |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerProgressSlider.swift
| ... | ... | @@ -76,7 +76,7 @@ class CNLivePlayerProgressSlider:UIView{ |
| 76 | 76 | }else if (_value < 0) { |
| 77 | 77 | _value = 0 |
| 78 | 78 | } |
| 79 | - if self.isDraggingSlideBlock!{ | |
| 79 | + if !self.isDraggingSlideBlock{ | |
| 80 | 80 | self.slider?.value = Float(_value) |
| 81 | 81 | } |
| 82 | 82 | } |
| ... | ... | @@ -94,7 +94,7 @@ class CNLivePlayerProgressSlider:UIView{ |
| 94 | 94 | //滑块 |
| 95 | 95 | var slider:CNLivePlayerSlider? |
| 96 | 96 | //是否在拖动滑块 |
| 97 | - var isDraggingSlideBlock:Bool? | |
| 97 | + var isDraggingSlideBlock:Bool = false | |
| 98 | 98 | |
| 99 | 99 | // MARK: - init |
| 100 | 100 | init() { | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerTopNaviView.swift
| ... | ... | @@ -23,13 +23,13 @@ class CNLivePlayerTopNaviView:UIView{ |
| 23 | 23 | /// 返回按钮 |
| 24 | 24 | var backBtn:UIButton? |
| 25 | 25 | /// 返回按钮图片 |
| 26 | - var backImageView:UIImageView? | |
| 26 | + var backImageView:UIImageView = UIImageView() | |
| 27 | 27 | /// 标题 |
| 28 | 28 | var titleLab:UILabel? |
| 29 | 29 | |
| 30 | 30 | // MARK: - 属性 |
| 31 | 31 | /// 是否是横屏 |
| 32 | - var isLandscape:Bool? | |
| 32 | + var isLandscape:Bool = false | |
| 33 | 33 | |
| 34 | 34 | // MARK: - 回调 |
| 35 | 35 | /// 点击返回回调 |
| ... | ... | @@ -39,6 +39,7 @@ class CNLivePlayerTopNaviView:UIView{ |
| 39 | 39 | init() { |
| 40 | 40 | super.init(frame: CGRectZero) |
| 41 | 41 | self.initUI() |
| 42 | + self.isLandscape = false | |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | required init?(coder: NSCoder) { |
| ... | ... | @@ -47,8 +48,8 @@ class CNLivePlayerTopNaviView:UIView{ |
| 47 | 48 | override func layoutSubviews() { |
| 48 | 49 | super.layoutSubviews() |
| 49 | 50 | self.bgGradientView?.frame = CGRect(x: 0, y: 0, width: self.width, height: self.height) |
| 50 | - self.backBtn?.frame = CGRect(x: self.isLandscape! ? KStatusBarHeight : 5, y: self.height-44, width: 44, height: 44) | |
| 51 | - self.backImageView?.frame = CGRect(x: (self.backBtn!.width-22)/2, y: (self.backBtn!.height-22)/2, width: 22, height: 22) | |
| 51 | + self.backBtn?.frame = CGRect(x: self.isLandscape ? KStatusBarHeight : 5, y: self.height-44, width: 44, height: 44) | |
| 52 | + self.backImageView.frame = CGRect(x: (self.backBtn!.width-22)/2, y: (self.backBtn!.height-22)/2, width: 22, height: 22) | |
| 52 | 53 | } |
| 53 | 54 | // MARK: - initUI |
| 54 | 55 | func initUI(){ |
| ... | ... | @@ -64,10 +65,10 @@ class CNLivePlayerTopNaviView:UIView{ |
| 64 | 65 | self.addSubview(self.backBtn!) |
| 65 | 66 | |
| 66 | 67 | self.backImageView = UIImageView() |
| 67 | - self.backImageView?.clipsToBounds = true | |
| 68 | - self.backImageView?.contentMode = .scaleAspectFit | |
| 69 | - self.backImageView?.image = UIImage(named: "DS_player_nav_back") | |
| 70 | - self.backBtn?.addSubview(self.backImageView!) | |
| 68 | + self.backImageView.clipsToBounds = true | |
| 69 | + self.backImageView.contentMode = .scaleAspectFit | |
| 70 | + self.backImageView.image = UIImage(named: "DS_player_nav_back") | |
| 71 | + self.backBtn?.addSubview(self.backImageView) | |
| 71 | 72 | |
| 72 | 73 | |
| 73 | 74 | } | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerView.swift
| ... | ... | @@ -25,36 +25,36 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 25 | 25 | /// 初始化视频链接地址 为空为停止播放 |
| 26 | 26 | var playUrl:URL? |
| 27 | 27 | /// 视频链接是否为直播 |
| 28 | - var isLive:Bool? | |
| 28 | + var isLive:Bool = false | |
| 29 | 29 | |
| 30 | 30 | // MARK: - 播放属性 |
| 31 | 31 | /// 是否循环播放(默认NO) |
| 32 | - var _isLoopPlay:Bool? | |
| 33 | - var isLoopPlay:Bool?{ | |
| 32 | + var _isLoopPlay:Bool = false | |
| 33 | + var isLoopPlay:Bool{ | |
| 34 | 34 | get{ |
| 35 | 35 | _isLoopPlay |
| 36 | 36 | } |
| 37 | 37 | set{ |
| 38 | 38 | _isLoopPlay = newValue |
| 39 | - if self.isLive!{ | |
| 39 | + if self.isLive{ | |
| 40 | 40 | return |
| 41 | 41 | } |
| 42 | - self.player?.loopPlay = _isLoopPlay! | |
| 42 | + self.player?.loopPlay = _isLoopPlay | |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /// 开始播放时间 |
| 47 | - var startPlayTime:Double? | |
| 47 | + var startPlayTime:Double = 0.0 | |
| 48 | 48 | /// 获取播放时间 |
| 49 | 49 | func getPlayTime() -> Double{ |
| 50 | 50 | return CMTimeGetSeconds(self.player!.currentTime) |
| 51 | 51 | } |
| 52 | 52 | /// 是否播放完成 |
| 53 | - var isPlayEnd:Bool? | |
| 53 | + var isPlayEnd:Bool = false | |
| 54 | 54 | /// 是否用户手动暂停 |
| 55 | - var isUserStop:Bool? | |
| 55 | + var isUserStop:Bool = false | |
| 56 | 56 | /// 控制器是否在进行disappear |
| 57 | - var _viewControllerIsDisappear:Bool? | |
| 57 | + var _viewControllerIsDisappear:Bool = false | |
| 58 | 58 | var viewControllerIsDisappear:Bool?{ |
| 59 | 59 | get{ |
| 60 | 60 | _viewControllerIsDisappear |
| ... | ... | @@ -65,7 +65,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 65 | 65 | }else if (_viewControllerIsDisappear == false && viewControllerIsDisappear == true) { |
| 66 | 66 | self.pauseWithIsRemoveKVOsAndNotifications(isRemove: true) |
| 67 | 67 | } |
| 68 | - _viewControllerIsDisappear = newValue | |
| 68 | + _viewControllerIsDisappear = newValue! | |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| ... | ... | @@ -130,20 +130,22 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 130 | 130 | self?.switchAlphaMessageStateCallBack!(self!) |
| 131 | 131 | } |
| 132 | 132 | controlView.switchLockScreenCallBack = {[weak self] in |
| 133 | - self?.switchLockScreenCallBack!(self!) | |
| 133 | + if ((self?.switchLockScreenCallBack?(self!)) != nil){ | |
| 134 | + self?.switchLockScreenCallBack!(self!) | |
| 135 | + } | |
| 134 | 136 | } |
| 135 | 137 | return controlView |
| 136 | 138 | }() |
| 137 | 139 | |
| 138 | 140 | // MARK: - 屏幕方向 |
| 139 | 141 | /// 是否开启检测设备转屏 默认开启 |
| 140 | - var _isMonitorDeviceOrientation:Bool? | |
| 142 | + var _isMonitorDeviceOrientation:Bool = true | |
| 141 | 143 | var isMonitorDeviceOrientation:Bool?{ |
| 142 | 144 | get{ |
| 143 | 145 | _isMonitorDeviceOrientation |
| 144 | 146 | } |
| 145 | 147 | set{ |
| 146 | - _isMonitorDeviceOrientation = newValue | |
| 148 | + _isMonitorDeviceOrientation = newValue! | |
| 147 | 149 | self.removeNotification() |
| 148 | 150 | self.registerNotification() |
| 149 | 151 | } |
| ... | ... | @@ -181,7 +183,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 181 | 183 | self.previewView.frame = CGRect(x: 0, y: 0, width: KSreenWidth, height: KSreenHeight) |
| 182 | 184 | self.layoutSubviews() |
| 183 | 185 | |
| 184 | - if (!self.controlView.isAlphaMessage!) { | |
| 186 | + if (!self.controlView.isAlphaMessage) { | |
| 185 | 187 | self.controlView.lockBtn!.alpha = 1 |
| 186 | 188 | } |
| 187 | 189 | } |
| ... | ... | @@ -279,7 +281,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 279 | 281 | return KVOs |
| 280 | 282 | }() |
| 281 | 283 | //是否是本地的url |
| 282 | - var isLocalUrl:Bool? | |
| 284 | + var isLocalUrl:Bool = false | |
| 283 | 285 | |
| 284 | 286 | /// 初始化视频 |
| 285 | 287 | /// @param playUrl 视频链接地址 为空为停止播放 |
| ... | ... | @@ -311,7 +313,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 311 | 313 | } |
| 312 | 314 | option.setOptionValue(format, forKey: PLPlayerOptionKeyVideoPreferFormat) |
| 313 | 315 | option.setOptionValue(kPLLogNone, forKey: PLPlayerOptionKeyLogLevel) |
| 314 | - if self.isLive!{ | |
| 316 | + if self.isLive{ | |
| 315 | 317 | self.player = PLPlayer(liveWith: self.playUrl as URL?, option: nil) |
| 316 | 318 | self.player?.loopPlay = false |
| 317 | 319 | self.controlView.bottomNaviView?.isHidden = false |
| ... | ... | @@ -322,7 +324,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 322 | 324 | self.controlView.bottomProgressView?.isHidden = true |
| 323 | 325 | }else{ |
| 324 | 326 | self.player = PLPlayer(url: self.playUrl, option: nil) |
| 325 | - self.player!.loopPlay = self.isLoopPlay! | |
| 327 | + self.player!.loopPlay = self.isLoopPlay | |
| 326 | 328 | |
| 327 | 329 | self.controlView.bottomNaviView?.isHidden = false |
| 328 | 330 | self.controlView.bottomNaviView?.playBtn!.isHidden = false |
| ... | ... | @@ -400,7 +402,9 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 400 | 402 | }) |
| 401 | 403 | } |
| 402 | 404 | func invalidateTimer(){ |
| 403 | - CNLiveTimer.bk_removeTimer(timer: self.timer!) | |
| 405 | + if self.timer != nil{ | |
| 406 | + CNLiveTimer.bk_removeTimer(timer: self.timer!) | |
| 407 | + } | |
| 404 | 408 | } |
| 405 | 409 | |
| 406 | 410 | // MARK: - 初始化界面 |
| ... | ... | @@ -498,10 +502,12 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 498 | 502 | self.controlView.bottomNaviView?.isUserInteractionEnabled = true |
| 499 | 503 | self.controlView.circlePlayBtn?.setBackgroundImage(UIImage(named: "DS_player_circle_pause"), for: .normal) |
| 500 | 504 | self.controlView.bottomNaviView?.playImageView!.image = UIImage(named: "DS_player_pause") |
| 501 | - self.playerPlayingCallBack!(self) | |
| 502 | - if self.startPlayTime! > 0{ | |
| 505 | + if ((self.playerPlayingCallBack?(self)) != nil){ | |
| 506 | + self.playerPlayingCallBack!(self) | |
| 507 | + } | |
| 508 | + if self.startPlayTime > 0{ | |
| 503 | 509 | self.controlView.loadingView?.startAnimate() |
| 504 | - self.player?.seek(to: CMTime(value: CMTimeValue(Int(self.startPlayTime!)*30), timescale: 30)) | |
| 510 | + self.player?.seek(to: CMTime(value: CMTimeValue(Int(self.startPlayTime)*30), timescale: 30)) | |
| 505 | 511 | self.startPlayTime = 0 |
| 506 | 512 | } |
| 507 | 513 | break |
| ... | ... | @@ -509,7 +515,10 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 509 | 515 | self.controlView.loadingView?.stopAnimate() |
| 510 | 516 | self.controlView.circlePlayBtn?.setBackgroundImage(UIImage(named: "DS_player_circle_start"), for: .normal) |
| 511 | 517 | self.controlView.bottomNaviView?.playImageView!.image = UIImage(named: "DS_player_start") |
| 512 | - self.playerPausedCallBack!(self) | |
| 518 | + if ((self.playerPausedCallBack?(self)) != nil){ | |
| 519 | + self.playerPausedCallBack!(self) | |
| 520 | + } | |
| 521 | + | |
| 513 | 522 | break |
| 514 | 523 | case .statusStopped: |
| 515 | 524 | self.controlView.loadingView?.stopAnimate() |
| ... | ... | @@ -527,7 +536,9 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 527 | 536 | self.controlView.bottomNaviView?.playImageView!.image = UIImage(named: "DS_player_start") |
| 528 | 537 | self.controlView.gestureView?.private_style = .none |
| 529 | 538 | self.controlView.bottomNaviView?.progressSlider?.isUserInteractionEnabled = false |
| 530 | - self.playerDidToEndCallBack!(self) | |
| 539 | + if ((self.playerDidToEndCallBack?(self)) != nil){ | |
| 540 | + self.playerDidToEndCallBack!(self) | |
| 541 | + } | |
| 531 | 542 | break |
| 532 | 543 | @unknown default: break |
| 533 | 544 | |
| ... | ... | @@ -630,7 +641,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 630 | 641 | var currentOrientation = UIDevice.current.orientation |
| 631 | 642 | //设备方向和屏幕方向一直不操作 设备方向为倒向不操作 锁屏且屏幕方向为正不操作 |
| 632 | 643 | if (self.currentOrientation == currentOrientation || currentOrientation == .portraitUpsideDown || |
| 633 | - (self.controlView.isLockScreen! && currentOrientation == .portrait)) { | |
| 644 | + (self.controlView.isLockScreen && currentOrientation == .portrait)) { | |
| 634 | 645 | return |
| 635 | 646 | } |
| 636 | 647 | //修改 |
| ... | ... | @@ -667,7 +678,7 @@ class CNLivePlayerView:UIView,PLPlayerDelegate{ |
| 667 | 678 | */ |
| 668 | 679 | @objc func didBecomeActiveNotification(){ |
| 669 | 680 | DispatchQueue.main.async { |
| 670 | - if !self.isUserStop! && !self.isPlayEnd!{ | |
| 681 | + if !self.isUserStop && !self.isPlayEnd{ | |
| 671 | 682 | self.play() |
| 672 | 683 | self.setNeedsLayout() |
| 673 | 684 | } | ... | ... |
metaCode/Classes/Main/Util/CNLivePlayer/CNLivePlayerViewController.swift
| ... | ... | @@ -19,7 +19,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 19 | 19 | /** |
| 20 | 20 | 视频链接是否为直播 |
| 21 | 21 | */ |
| 22 | - var isLive:Bool? | |
| 22 | + var isLive:Bool = false | |
| 23 | 23 | |
| 24 | 24 | /// 初始化视频 |
| 25 | 25 | /// @param playUrl 视频链接地址 为空为停止播放 |
| ... | ... | @@ -32,7 +32,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 32 | 32 | }else{ |
| 33 | 33 | self.isLocalUrl = false |
| 34 | 34 | } |
| 35 | - self.playerView?.setPlayUrl(playUrl: self.playUrl!, isLive: self.isLive!) | |
| 35 | + self.playerView?.setPlayUrl(playUrl: self.playUrl!, isLive: self.isLive) | |
| 36 | 36 | self.playerView?.startPlayTime = playTime |
| 37 | 37 | } |
| 38 | 38 | // MARK: - 封面图 |
| ... | ... | @@ -75,11 +75,14 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 75 | 75 | _playerView = CNLivePlayerView() |
| 76 | 76 | _playerView?.controlView.fullScreenType = .inCurrentViewOrientation |
| 77 | 77 | _playerView?.popCallBack = {[weak self] in |
| 78 | - self!.popActionCallBack!(self!.playerView!.getPlayTime(), self!.playerView!.isUserStop!, self!.playerView!.isPlayEnd!) | |
| 78 | + if ((self!.popActionCallBack?(self!.playerView!.getPlayTime(), self!.playerView!.isUserStop, self!.playerView!.isPlayEnd)) != nil) | |
| 79 | + { | |
| 80 | + self!.popActionCallBack!(self!.playerView!.getPlayTime(), self!.playerView!.isUserStop, self!.playerView!.isPlayEnd) | |
| 81 | + } | |
| 79 | 82 | } |
| 80 | 83 | _playerView?.switchAlphaMessageStateCallBack = { playerView in |
| 81 | 84 | UIView.animate(withDuration: kDSPlayerAnimateTimeInterval) { |
| 82 | - if (playerView.controlView.isLockScreen! || playerView.controlView.isAlphaMessage!) { | |
| 85 | + if (playerView.controlView.isLockScreen || playerView.controlView.isAlphaMessage) { | |
| 83 | 86 | self.isStatusBarHidden = true |
| 84 | 87 | self.setNeedsStatusBarAppearanceUpdate() |
| 85 | 88 | }else { |
| ... | ... | @@ -105,7 +108,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 105 | 108 | } |
| 106 | 109 | |
| 107 | 110 | //是否是本地的url |
| 108 | - private var isLocalUrl:Bool? | |
| 111 | + private var isLocalUrl:Bool = false | |
| 109 | 112 | |
| 110 | 113 | var isStatusBarLight:Bool = true |
| 111 | 114 | var isStatusBarHidden:Bool = true |
| ... | ... | @@ -124,7 +127,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 124 | 127 | }else{ |
| 125 | 128 | self.isLocalUrl = false |
| 126 | 129 | } |
| 127 | - self.playerView?.setPlayUrl(playUrl: self.playUrl!, isLive: self.isLive!) | |
| 130 | + self.playerView?.setPlayUrl(playUrl: self.playUrl!, isLive: self.isLive) | |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | 133 | // MARK: - viewDidLoad |
| ... | ... | @@ -154,7 +157,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 154 | 157 | } |
| 155 | 158 | override func viewDidAppear(_ animated: Bool) { |
| 156 | 159 | super.viewDidAppear(animated) |
| 157 | - if (!self.isLocalUrl!) { | |
| 160 | + if (!self.isLocalUrl) { | |
| 158 | 161 | // if ([DSNetworkRequest shareClient].netStatus == DSNetworkStatusNotReachable) { |
| 159 | 162 | // self.playerView.controlView.failureView.hidden = NO; |
| 160 | 163 | // self.playerView.controlView.failureView.errorMessage = @"当前网络不可用,请检查网络后重试"; |
| ... | ... | @@ -164,7 +167,7 @@ class CNLivePlayerViewController:CNLiveBaseViewController{ |
| 164 | 167 | // DS_showMessage(@"当前正在用流量播放"); |
| 165 | 168 | // } |
| 166 | 169 | } |
| 167 | - if (!self.playerView!.isUserStop! && !self.playerView!.isPlayEnd!) { | |
| 170 | + if (!self.playerView!.isUserStop && !self.playerView!.isPlayEnd) { | |
| 168 | 171 | self.playerView?.play() |
| 169 | 172 | } |
| 170 | 173 | } | ... | ... |
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_delete.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "DS_SelUplImageView_delete@2x.png", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "filename" : "DS_SelUplImageView_delete@3x.png", | |
| 14 | + "idiom" : "universal", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "author" : "xcode", | |
| 20 | + "version" : 1 | |
| 21 | + } | |
| 22 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_delete.imageset/DS_SelUplImageView_delete@2x.png
0 → 100644
1.29 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_delete.imageset/DS_SelUplImageView_delete@3x.png
0 → 100644
1.84 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_play.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "DS_SelUplImageView_play@2x.png", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "filename" : "DS_SelUplImageView_play@3x.png", | |
| 14 | + "idiom" : "universal", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "author" : "xcode", | |
| 20 | + "version" : 1 | |
| 21 | + } | |
| 22 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_play.imageset/DS_SelUplImageView_play@2x.png
0 → 100644
2.21 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_play.imageset/DS_SelUplImageView_play@3x.png
0 → 100644
3.63 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectImage.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "DS_SelUplImageView_selectImage@2x.png", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "filename" : "DS_SelUplImageView_selectImage@3x.png", | |
| 14 | + "idiom" : "universal", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "author" : "xcode", | |
| 20 | + "version" : 1 | |
| 21 | + } | |
| 22 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectImage.imageset/DS_SelUplImageView_selectImage@2x.png
0 → 100644
5.8 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectImage.imageset/DS_SelUplImageView_selectImage@3x.png
0 → 100644
15 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectVideo.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "DS_SelUplImageView_selectVideo@2x.png", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "filename" : "DS_SelUplImageView_selectVideo@3x.png", | |
| 14 | + "idiom" : "universal", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "author" : "xcode", | |
| 20 | + "version" : 1 | |
| 21 | + } | |
| 22 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectVideo.imageset/DS_SelUplImageView_selectVideo@2x.png
0 → 100644
6.06 KB
metaCode/Supporting Files/Assets.xcassets/Shop/DS_SelUplImageView_selectVideo.imageset/DS_SelUplImageView_selectVideo@3x.png
0 → 100644
15.8 KB