350 lines
13 KiB
Swift
350 lines
13 KiB
Swift
//
|
||
// HomeVoiceVC.swift
|
||
// yinmeng-ios
|
||
//
|
||
// Created by MaiMang on 2024/2/25.
|
||
//
|
||
|
||
import UIKit
|
||
import NIMSDK
|
||
import Nuke
|
||
|
||
class HomeVoiceVC: BaseViewController,HiddenNavigationBarProtocol {
|
||
var myModel:HomeVoiceModel?
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
setUILayout()
|
||
requestData()
|
||
requsetFansListData()
|
||
userInfoBtn.addTarget(self, action: #selector(userInfoBtnAction), for: .touchUpInside)
|
||
}
|
||
@objc func userInfoBtnAction(){
|
||
let userInfoView:HomeVoiceUserInfoView = HomeVoiceUserInfoView.init(frame: .zero)
|
||
userInfoView.clickBtnBlock = {[weak self] (type,model) in
|
||
guard let weakSelf = self else {
|
||
return
|
||
}
|
||
if type == 3{
|
||
let vc = UserPayViewController()
|
||
self?.navigationController?.pushViewController(vc, animated: true)
|
||
return
|
||
}
|
||
}
|
||
userInfoView.type = 1
|
||
userInfoView.model = self.myModel
|
||
self.view.addSubview(userInfoView)
|
||
userInfoView.snp.makeConstraints { make in
|
||
make.edges.equalTo(self.view)
|
||
}
|
||
|
||
}
|
||
func requsetFansListData(){
|
||
let uid = "\(AuthManager.userUid)"
|
||
RequestGet(path: "fans/following", parma: ["uid":uid,"pageNo":"1","pageSize":"50"]) { data in
|
||
|
||
if let list = Deserialized<HomeVoiceModel>.toArray(with: data) {
|
||
self.followView.modelList = list
|
||
}
|
||
} fail: { code, data in
|
||
print(code)
|
||
}
|
||
}
|
||
func setUILayout(){
|
||
|
||
view.addSubview(backgroundView)
|
||
view.addSubview(scrollView)
|
||
scrollView.addSubview(topLogoIcon)
|
||
scrollView.addSubview(chooseItemVeiw)
|
||
scrollView.addSubview(changeItemView)
|
||
scrollView.addSubview(userInfoBtn)
|
||
|
||
scrollView.addSubview(publishView)
|
||
scrollView.addSubview(bgPlayMusicView)
|
||
|
||
|
||
|
||
|
||
|
||
backgroundView.snp.makeConstraints { make in
|
||
make.edges.equalTo(self.view)
|
||
}
|
||
scrollView.snp.makeConstraints { make in
|
||
make.edges.equalTo(self.view)
|
||
}
|
||
topLogoIcon.snp.makeConstraints { make in
|
||
make.left.equalTo(20)
|
||
make.top.equalTo(14 + NavHeight)
|
||
make.width.equalTo(260)
|
||
make.height.equalTo(23)
|
||
}
|
||
chooseItemVeiw.snp.makeConstraints { make in
|
||
make.left.equalTo(20)
|
||
make.top.equalTo(self.topLogoIcon.snp.bottom).offset(18)
|
||
make.width.equalTo(61)
|
||
make.height.equalTo(27)
|
||
}
|
||
changeItemView.snp.makeConstraints { make in
|
||
make.left.equalTo(self.chooseItemVeiw.snp.right).offset(8)
|
||
make.top.height.equalTo(self.chooseItemVeiw)
|
||
make.width.equalTo(76)
|
||
}
|
||
userInfoBtn.snp.makeConstraints { make in
|
||
make.left.equalTo(ScreenWidth - 70)
|
||
make.height.equalTo(40)
|
||
make.width.equalTo(50)
|
||
make.centerY.equalTo(changeItemView)
|
||
}
|
||
|
||
|
||
bgPlayMusicView.snp.makeConstraints { make in
|
||
make.left.equalTo(14)
|
||
make.top.equalTo(self.chooseItemVeiw.snp.bottom).offset(10)
|
||
make.width.equalTo(ScreenWidth-28)
|
||
make.height.equalTo(424)
|
||
}
|
||
publishView.snp.makeConstraints { make in
|
||
make.left.equalTo(14)
|
||
make.top.equalTo(self.bgPlayMusicView.snp.bottom).offset(10)
|
||
make.width.equalTo(ScreenWidth-28)
|
||
make.height.equalTo(144)
|
||
}
|
||
publishView.superview?.layoutIfNeeded()
|
||
scrollView.contentSize = CGSize(width: ScreenWidth, height: publishView.frame.origin.y + publishView.frame.size.height)
|
||
let margin:CGFloat = (ScreenWidth - 90 * 3 - 28)/4
|
||
for i in 0..<9 {
|
||
let x = CGFloat((i % 3)) * (90.0 + margin) + margin
|
||
let y = CGFloat((i / 3)) * (114 + 16) + 24
|
||
|
||
let itemView = HomeVoicePlayMusicItemView(frame: CGRect(x: x, y: y, width: 90, height: 114))
|
||
let tap = UITapGestureRecognizer.init(target: self, action: #selector(clickAvatarAction(sender:)))
|
||
itemView.tag = i + 100
|
||
itemView.addGestureRecognizer(tap)
|
||
let longTap = UIPanGestureRecognizer(target: self, action: #selector(clickLongTapAction(sender:)))
|
||
itemView.addGestureRecognizer(longTap)
|
||
bgPlayMusicView.addSubview(itemView)
|
||
itemViewList.append(itemView)
|
||
}
|
||
|
||
let x = ScreenWidth - 28 - 44 - 3
|
||
followView.frame = CGRect(x:x , y: 3, width: 44, height: 418)
|
||
|
||
|
||
|
||
|
||
|
||
chooseTypeView.chooseTypeBlock = {[weak self] type in
|
||
guard let weakSelf = self else {
|
||
return
|
||
}
|
||
weakSelf.chooseItemVeiw.isChoose = false
|
||
weakSelf.gender = type == 0 ? "" : "\(type)"
|
||
weakSelf.requestData()
|
||
}
|
||
let tap = UITapGestureRecognizer(target: self, action: #selector(chooseItemAction))
|
||
chooseItemVeiw.addGestureRecognizer(tap)
|
||
let changeTap = UITapGestureRecognizer.init(target: self, action: #selector(changeItemAction))
|
||
changeItemView.addGestureRecognizer(changeTap)
|
||
bgPlayMusicView.addSubview(followView)
|
||
scrollView.addSubview(chooseTypeView)
|
||
chooseTypeView.snp.makeConstraints { make in
|
||
make.width.equalTo(64)
|
||
make.height.equalTo(107)
|
||
make.centerX.equalTo(self.chooseItemVeiw)
|
||
make.top.equalTo(self.changeItemView.snp.bottom)
|
||
}
|
||
followView.clickAvatarBlcok = {[weak self] model in
|
||
guard let weakSelf = self else {
|
||
return
|
||
}
|
||
let userInfoView:HomeVoiceUserInfoView = HomeVoiceUserInfoView.init(frame: .zero)
|
||
userInfoView.clickBtnBlock = {[weak self] (type,model) in
|
||
|
||
let session = NIMSession("\(model.uid)", type: .P2P)
|
||
let chatVC = ChatVC.init(session: session)
|
||
self?.navigationController?.pushViewController(chatVC, animated: true)
|
||
}
|
||
userInfoView.model = model
|
||
weakSelf.view.addSubview(userInfoView)
|
||
userInfoView.snp.makeConstraints { make in
|
||
make.edges.equalTo(weakSelf.view)
|
||
}
|
||
}
|
||
publishView.clickPublishBlock = {[weak self] in
|
||
let recordView = HomeVoiceRecordView.init(frame: .zero)
|
||
recordView.myModel = self?.myModel
|
||
self?.view.addSubview(recordView)
|
||
recordView.snp.makeConstraints { make in
|
||
make.edges.equalTo((self?.view)!)
|
||
}
|
||
}
|
||
}
|
||
|
||
@objc func clickLongTapAction(sender:UIPanGestureRecognizer){
|
||
let i = (sender.view?.tag ?? 100) - 100
|
||
if sender.state == .began{
|
||
location = sender.view?.center
|
||
}else if sender.state == .changed{
|
||
let point = sender.location(in: self.view)
|
||
if (point.y < 0 || point.y > self.view.frame.size.height){return}
|
||
let changePoint = sender.translation(in: self.view)
|
||
let x = (sender.view?.center.x ?? 0) + changePoint.x
|
||
let y = (sender.view?.center.y ?? 0) + changePoint.y
|
||
sender.view?.center = CGPoint(x: x, y: y)
|
||
sender.setTranslation(.zero, in: self.view)
|
||
}else{
|
||
|
||
guard let centerPoint = sender.view?.center else{return}
|
||
let point = CGPoint(x: centerPoint.x + 14, y: centerPoint.y+136)
|
||
|
||
let minX:CGFloat = 33
|
||
let minY:CGFloat = 570
|
||
let maxX:CGFloat = 133
|
||
let maxY:CGFloat = 570 + 133
|
||
if point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY{
|
||
if let view = sender.view as? HomeVoicePlayMusicItemView ,let model = view.model{
|
||
publishView.model = model
|
||
}
|
||
}
|
||
if let location = self.location{
|
||
sender.view?.center = location
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
@objc func clickAvatarAction(sender:UITapGestureRecognizer){
|
||
guard let view = sender.view as? HomeVoicePlayMusicItemView else{
|
||
return
|
||
}
|
||
|
||
let userInfoView:HomeVoiceUserInfoView = HomeVoiceUserInfoView.init(frame: .zero)
|
||
userInfoView.clickBtnBlock = {[weak self] (type,model) in
|
||
|
||
let session = NIMSession("\(model.uid)", type: .P2P)
|
||
let chatVC = ChatVC.init(session: session)
|
||
self?.navigationController?.pushViewController(chatVC, animated: true)
|
||
}
|
||
userInfoView.model = view.model
|
||
self.view.addSubview(userInfoView)
|
||
userInfoView.snp.makeConstraints { make in
|
||
make.edges.equalTo(self.view)
|
||
}
|
||
|
||
}
|
||
@objc func changeItemAction(){
|
||
requestData()
|
||
makeRotationAnim(view: changeItemView.leftIconView)
|
||
}
|
||
func makeRotationAnim(view: UIView) {
|
||
// 1.创建动画
|
||
let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
|
||
// 2.设置动画属性
|
||
rotationAnim.fromValue = 0 // 开始角度
|
||
rotationAnim.toValue = Double.pi * 2 // 结束角度
|
||
rotationAnim.repeatCount = 2 // 重复次数
|
||
rotationAnim.duration = 0.5
|
||
rotationAnim.autoreverses = false // 动画完成后自动重新开始,默认为NO
|
||
rotationAnim.isRemovedOnCompletion = true //默认是true,切换到其他控制器再回来,动画效果会消失,需要设置成false,动画就不会停了
|
||
view.layer.add(rotationAnim, forKey: nil) // 给需要旋转的view增加动画
|
||
|
||
}
|
||
func requestData(){
|
||
RequestGet(path: "voiceShow/listRandom", parma: ["gender":gender]) { data in
|
||
guard let dic = data as? [String : Any]else {
|
||
return
|
||
}
|
||
let curData = dic["randomList"]
|
||
let myDic = dic["me"]
|
||
if let model = Deserialized<HomeVoiceModel>.toModel(with: myDic) {
|
||
self.myModel = model
|
||
}
|
||
if let list = Deserialized<HomeVoiceModel>.toArray(with: curData) {
|
||
for i in 0..<9 {
|
||
if i < list.count{
|
||
let view:HomeVoicePlayMusicItemView = self.itemViewList[i]
|
||
let model = list[i]
|
||
view.model = model
|
||
|
||
}
|
||
}
|
||
}
|
||
} fail: { code, data in
|
||
print(code)
|
||
}
|
||
|
||
}
|
||
@objc func chooseItemAction(){
|
||
chooseItemVeiw.isChoose = !chooseItemVeiw.isChoose
|
||
chooseTypeView.isHidden = !chooseItemVeiw.isChoose
|
||
|
||
}
|
||
var gender = ""
|
||
private lazy var backgroundView:UIImageView = {
|
||
let _backgroundView = UIImageView()
|
||
_backgroundView.image = UIImage(named: "yin_home_voice_bg")
|
||
_backgroundView.isUserInteractionEnabled = true
|
||
return _backgroundView
|
||
}()
|
||
|
||
var topLogoIcon:UIImageView = {
|
||
let _topLogoIcon = UIImageView()
|
||
_topLogoIcon.image = UIImage(named: "yin_home_voice_top_icon")
|
||
return _topLogoIcon
|
||
}()
|
||
|
||
var chooseItemVeiw:HomeVoiceChooseItemVeiw = {
|
||
let _chooseItemVeiw = HomeVoiceChooseItemVeiw(frame: .zero)
|
||
_chooseItemVeiw.image = "yin_home_voice_choose_icon"
|
||
_chooseItemVeiw.text = "筛选"
|
||
_chooseItemVeiw.isUserInteractionEnabled = true
|
||
|
||
return _chooseItemVeiw
|
||
}()
|
||
var changeItemView:HomeVoiceChooseItemVeiw = {
|
||
let _changeItemView = HomeVoiceChooseItemVeiw(frame: .zero)
|
||
_changeItemView.image = "yin_home_voice_change_icon"
|
||
_changeItemView.text = "换一换"
|
||
return _changeItemView
|
||
}()
|
||
|
||
var userInfoBtn:UIButton = {
|
||
let _userInfoBtn = UIButton()
|
||
_userInfoBtn.setBackgroundImage(UIImage(named: "yin_home_voice_user_info_bg"), for: .normal)
|
||
_userInfoBtn.setImage(UIImage(named: "yin_home_voice_user_info_icon"), for: .normal)
|
||
|
||
|
||
return _userInfoBtn
|
||
}()
|
||
var chooseTypeView:HomeVoiceChooseTypeView = {
|
||
let _chooseTypeView = HomeVoiceChooseTypeView(frame: .zero)
|
||
_chooseTypeView.isHidden = true
|
||
return _chooseTypeView
|
||
}()
|
||
|
||
var bgPlayMusicView:UIImageView = {
|
||
let _bgPlayMusicView = UIImageView()
|
||
_bgPlayMusicView.image = UIImage(named: "yin_home_voice_play_music_bg")
|
||
|
||
_bgPlayMusicView.isUserInteractionEnabled = true
|
||
return _bgPlayMusicView
|
||
}()
|
||
|
||
|
||
var scrollView:UIScrollView = {
|
||
let _scrollView = UIScrollView()
|
||
_scrollView.backgroundColor = .clear
|
||
return _scrollView
|
||
}()
|
||
var itemViewList:[HomeVoicePlayMusicItemView] = []
|
||
var followView:HomeVoiceFollowView = {
|
||
let _followView = HomeVoiceFollowView(frame: .zero)
|
||
|
||
return _followView
|
||
}()
|
||
var publishView:HomeVoicePublishView = {
|
||
let _publishView = HomeVoicePublishView(frame: .zero)
|
||
return _publishView
|
||
}()
|
||
var location:CGPoint?
|
||
}
|