458 lines
17 KiB
Swift
458 lines
17 KiB
Swift
//
|
||
// PlanetStarClickItemView.swift
|
||
// yinmeng-ios
|
||
//
|
||
// Created by duoban on 2024/2/26.
|
||
//
|
||
|
||
import UIKit
|
||
import Nuke
|
||
|
||
typealias RefreshBlcok = (_ userId: String?)->Void
|
||
|
||
class PlanetStarClickItemView: UIView {
|
||
|
||
|
||
deinit{
|
||
if self.timer != nil{
|
||
self.timer?.invalidate()
|
||
self.timer = nil
|
||
}
|
||
}
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
yin_initUI()
|
||
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(beginRotationAnimation), userInfo: nil, repeats: true)
|
||
}
|
||
@objc func beginRotationAnimation(){
|
||
if self.isStop == true{
|
||
return
|
||
}
|
||
|
||
self.vapView.transform = CGAffineTransformRotate(self.vapView.transform, Double.pi / 1000 * 1);
|
||
|
||
|
||
}
|
||
|
||
func yin_initUI(){
|
||
addSubview(vapView)
|
||
vapView.frame = CGRect(x: -185, y: ScreenHeight/2 - 429 / 2 - 60, width: 429, height: 429)
|
||
|
||
parser.parse(withNamed: "StarIcon", in: Bundle.main) {[weak self] videoItem in
|
||
|
||
self?.vapView.videoItem = videoItem
|
||
self?.vapView.loops = 100000;
|
||
self?.vapView.startAnimation()
|
||
|
||
} failureBlock: { error in
|
||
|
||
}
|
||
for i in 0..<12 {
|
||
let clickHeadImageView = UIImageView()
|
||
clickHeadImageView.isUserInteractionEnabled = true
|
||
clickHeadImageView.layer.cornerRadius = 31
|
||
clickHeadImageView.layer.masksToBounds = true
|
||
clickHeadImageView.layer.borderWidth = 1
|
||
clickHeadImageView.layer.borderColor = ThemeColor(hexStr: "#57CDFF").cgColor
|
||
clickHeadImageView.tag = i + 100
|
||
clickHeadImageView.frame = CGRect(x: 0, y: 0, width: clickWidth, height: clickHeight)
|
||
|
||
let tap = UITapGestureRecognizer.init(target: self, action: #selector(clickImageViewAction))
|
||
clickHeadImageView.addGestureRecognizer(tap)
|
||
vapView.addSubview(clickHeadImageView)
|
||
clickViewList.append(clickHeadImageView)
|
||
}
|
||
setClickViewLayout()
|
||
vapView.superview?.layoutIfNeeded()
|
||
addSubview(bgImageView)
|
||
addSubview(imageView)
|
||
imageView.isHidden = true
|
||
|
||
let scale = ScreenWidth / 375 * 100
|
||
bgImageView.frame = CGRect(x: ScreenWidth , y: ScreenHeight/2 - 140 , width: 385, height: 254)
|
||
bgImageView.addSubview(backBtn)
|
||
backBtn.snp.makeConstraints { make in
|
||
make.width.height.equalTo(30)
|
||
make.top.equalTo(65)
|
||
make.right.equalTo(-round(scale))
|
||
}
|
||
bgImageView.addSubview(giftView)
|
||
giftView.snp.makeConstraints { make in
|
||
make.width.height.equalTo(58)
|
||
make.right.equalTo(self.backBtn)
|
||
make.top.equalTo(self.backBtn.snp.bottom).offset(1)
|
||
}
|
||
giftParser.parse(withNamed: "StarGift", in: Bundle.main) {[weak self] videoItem in
|
||
|
||
self?.giftView.videoItem = videoItem
|
||
self?.giftView.loops = 100000;
|
||
self?.giftView.startAnimation()
|
||
|
||
} failureBlock: { error in
|
||
|
||
}
|
||
bgImageView.isHidden = true
|
||
addSubview(refreshBtn)
|
||
refreshBtn.snp.makeConstraints { make in
|
||
make.centerY.equalTo(self.vapView)
|
||
make.width.height.equalTo((44))
|
||
make.right.equalTo(-32)
|
||
}
|
||
|
||
|
||
addSubview(bgUserInfoView)
|
||
|
||
bgUserInfoView.isHidden = true
|
||
bgUserInfoView.addSubview(nameLabelView)
|
||
bgUserInfoView.addSubview(sexImageVeiw)
|
||
bgUserInfoView.addSubview(attentionBtn)
|
||
bgUserInfoView.addSubview(chatBtn)
|
||
bgUserInfoView.addSubview(bgSignatureView)
|
||
bgSignatureView.addSubview(signatureView)
|
||
|
||
bgUserInfoView.snp.makeConstraints { make in
|
||
make.centerY.equalTo(self.bgImageView).offset(30)
|
||
make.height.equalTo((275))
|
||
make.left.equalTo(8)
|
||
make.width.equalTo(180)
|
||
}
|
||
nameLabelView.snp.makeConstraints { make in
|
||
make.left.top.equalTo(self.bgUserInfoView)
|
||
make.height.equalTo(28)
|
||
make.right.lessThanOrEqualTo(-25)
|
||
}
|
||
sexImageVeiw.snp.makeConstraints { make in
|
||
make.width.height.equalTo(16)
|
||
make.left.equalTo(self.nameLabelView.snp.right).offset(3)
|
||
make.centerY.equalTo(self.nameLabelView)
|
||
}
|
||
attentionBtn.snp.makeConstraints { make in
|
||
make.left.equalTo(self.nameLabelView)
|
||
make.top.equalTo(self.nameLabelView.snp.bottom).offset(10)
|
||
make.width.equalTo(72)
|
||
make.height.equalTo(48)
|
||
}
|
||
chatBtn.snp.makeConstraints { make in
|
||
make.left.equalTo(self.attentionBtn.snp.right).offset(8)
|
||
make.top.width.height.equalTo(self.attentionBtn)
|
||
}
|
||
bgSignatureView.snp.makeConstraints { make in
|
||
make.width.equalTo(154)
|
||
make.height.equalTo(86)
|
||
make.top.equalTo(self.nameLabelView.snp.bottom).offset(65)
|
||
make.left.equalTo(self.nameLabelView)
|
||
}
|
||
signatureView.snp.makeConstraints { make in
|
||
make.edges.equalTo(self.bgSignatureView).inset(9)
|
||
}
|
||
}
|
||
@objc func attentionBtnAction(){
|
||
self.attentionBtn.isSelected = !self.attentionBtn.isSelected
|
||
let type = self.attentionBtn.isSelected ? "1" : "2"
|
||
let params = ["uid":"\(AuthManager.userUid)","ticket":AuthManager.ticket,"type":type,"likedUid":self.chooseModel?.uid] as [String : Any]
|
||
|
||
RequestPost(path: "fans/like", parma: params) { data in
|
||
if(self.attentionBtn.isSelected){
|
||
HUDTool.show(with: "关注成功")
|
||
}else{
|
||
HUDTool.show(with: "取消关注成功")
|
||
}
|
||
} fail: { code, data in
|
||
|
||
}
|
||
|
||
}
|
||
@objc func chatBtnAction(){
|
||
if let _refreshBlcok = refreshBlcok,let uid = self.chooseModel?.uid{
|
||
|
||
_refreshBlcok(uid)
|
||
}
|
||
}
|
||
@objc func refreshBtnAction(){
|
||
if let _refreshBlcok = refreshBlcok{
|
||
_refreshBlcok(nil)
|
||
}
|
||
makeRotationAnim(view: refreshBtn)
|
||
}
|
||
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增加动画
|
||
|
||
}
|
||
@objc func clickImageViewAction(sender:UITapGestureRecognizer){
|
||
self.isStop = true
|
||
self.vapView.transform = CGAffineTransformIdentity
|
||
let j = (sender.view?.tag ?? 100) - 100
|
||
self.chooseModel = self.dataList[j]
|
||
if let _chooseModel = self.chooseModel{
|
||
self.sexImageVeiw.image = _chooseModel.gender == 1 ? UIImage(named: "yin_plane_star_man") : UIImage(named: "yin_plane_star__woman")
|
||
self.nameLabelView.text = _chooseModel.nick
|
||
self.attentionBtn.isSelected = _chooseModel.hasLike
|
||
self.signatureView.text = _chooseModel.userDesc
|
||
}
|
||
if let startPoint = sender.view?.frame.origin{
|
||
let movePoint = ceterPoint!
|
||
let start = getAngle(point: startPoint)
|
||
let move = getAngle(point: movePoint)
|
||
if getLocation(startPoint) == 1 || getLocation(startPoint) == 4{
|
||
angle = angle + move - start
|
||
}else{
|
||
angle = angle + start - move + Double.pi
|
||
}
|
||
UIView.animate(withDuration: 0.4) {
|
||
self.setClickViewLayout()
|
||
}completion: { isCompletion in
|
||
self.setCliickViewAnimationCompletionLayout(view: sender.view as! UIImageView)
|
||
}
|
||
}
|
||
}
|
||
|
||
func setCliickViewAnimationCompletionLayout(view:UIImageView){
|
||
imageView.image = view.image
|
||
imageView.isHidden = false
|
||
refreshBtn.isHidden = true
|
||
let scale = ScreenWidth / 375 * 170
|
||
|
||
imageView.layer.borderColor = view.layer.borderColor
|
||
imageView.frame = CGRect(x: round(scale) + 44 , y: ScreenHeight/2 - 85+44, width: 52, height: 52)
|
||
imageView.layer.cornerRadius = 52/2
|
||
bgImageView.isHidden = false
|
||
imageView.isHidden = false
|
||
vapView.videoItem = nil
|
||
radius = 280
|
||
|
||
|
||
let scale1 = ScreenWidth / 375 * 115
|
||
|
||
|
||
UIView.animate(withDuration: 0.4) {
|
||
|
||
self.vapView.frame = CGRect(x: -200, y: ScreenHeight/2 - 480 / 2 - 60, width: 480, height: 480)
|
||
|
||
for imageVeiw in self.clickViewList {
|
||
|
||
imageVeiw.frame = CGRect(x: 0, y: 0, width: 52, height: 52)
|
||
imageVeiw.layer.cornerRadius = 52/2
|
||
|
||
}
|
||
self.setClickViewLayout()
|
||
self.imageView.frame = CGRect(x: round(scale) , y: ScreenHeight/2 - 85, width: 140, height: 140)
|
||
self.imageView.layer.cornerRadius = 140/2
|
||
self.bgImageView.frame = CGRect(x: round(scale1) , y: ScreenHeight/2 - 140 , width: 385, height: 254)
|
||
}completion: { isCompletion in
|
||
self.bgUserInfoView.isHidden = false
|
||
}
|
||
}
|
||
|
||
@objc func clickBackBtnAction(){
|
||
bgUserInfoView.isHidden = true
|
||
imageView.isHidden = true
|
||
radius = 224
|
||
UIView.animate(withDuration: 0.4) {
|
||
|
||
self.vapView.frame = CGRect(x: -185, y: ScreenHeight/2 - 429 / 2 - 60, width: 429, height: 429)
|
||
|
||
for imageVeiw in self.clickViewList {
|
||
imageVeiw.frame = CGRect(x: 0, y: 0, width: 62, height:62)
|
||
imageVeiw.layer.cornerRadius = 62/2
|
||
}
|
||
self.setClickViewLayout()
|
||
|
||
self.bgImageView.frame = CGRect(x: ScreenWidth , y: ScreenHeight/2 - 140 , width: 385, height: 254)
|
||
}completion: { isCompletion in
|
||
self.refreshBtn.isHidden = false
|
||
self.parser.parse(withNamed: "StarIcon", in: Bundle.main) {[weak self] videoItem in
|
||
|
||
self?.vapView.videoItem = videoItem
|
||
self?.vapView.loops = 100000;
|
||
self?.vapView.startAnimation()
|
||
|
||
} failureBlock: { error in
|
||
|
||
}
|
||
self.isStop = false
|
||
}
|
||
}
|
||
|
||
func setClickViewLayout(){
|
||
for (i,clickView) in clickViewList.enumerated() {
|
||
let j = CGFloat(i)
|
||
let width = clickView.frame.width
|
||
let y = radius + sin((j/12) * Double.pi*2 + angle) * (429/2 - width/2 - 20)
|
||
let x = radius + cos((j/12) * Double.pi*2 + angle) * (429/2 - width/2 - 20)
|
||
clickView.center = CGPoint(x: x, y: y)
|
||
if (ceterPoint == nil && i == 0){
|
||
ceterPoint = CGPoint(x: x, y: y)
|
||
}
|
||
}
|
||
}
|
||
func getAngle(point:CGPoint) -> Double{
|
||
let x = point.x - radius
|
||
let y = point.y - radius
|
||
let h = hypot(x, y)
|
||
let v:Double = y / h
|
||
return asin(v)
|
||
}
|
||
func getLocation(_ point:CGPoint) -> Int{
|
||
let x = Int(point.x - radius)
|
||
let y = Int(point.y - radius)
|
||
if (x >= 0){
|
||
return y >= 0 ? 1 : 4
|
||
}
|
||
return y >= 0 ? 2 : 3
|
||
}
|
||
func getAngleValue() -> Double{
|
||
let num:Double = 12.0
|
||
let value:Double = 2 * Double.pi / num
|
||
let remainder:Double = fmod(angle, value)
|
||
if(angle > 0 || angle == 0){
|
||
if fabs(remainder) > value / 2 {
|
||
angle = angle - fabs(remainder)
|
||
angle = angle + value
|
||
}else{
|
||
angle = angle - fabs(remainder)
|
||
}
|
||
}else{
|
||
if fabs(remainder) > value / 2{
|
||
angle = angle + fabs(remainder)
|
||
angle = angle - value
|
||
}else{
|
||
angle = angle + fabs(remainder)
|
||
}
|
||
}
|
||
return angle
|
||
}
|
||
|
||
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
var ceterPoint:CGPoint?
|
||
var clickViewList:[UIImageView] = []
|
||
var clickWidth:CGFloat = 62
|
||
var clickHeight:CGFloat = 62
|
||
var radius:CGFloat = 224
|
||
var angle:Double = 0
|
||
var chooseModel:PlanetStarModel?
|
||
var dataList:[PlanetStarModel] = [] {
|
||
didSet{
|
||
for (i,model) in dataList.enumerated(){
|
||
if(i < clickViewList.count){
|
||
let clickView = clickViewList[i]
|
||
Nuke.loadImage(with: model.avatar, into: clickView)
|
||
clickView.layer.borderColor = model.gender == 2 ? ThemeColor(hexStr: "#D667FF").cgColor : ThemeColor(hexStr: "#57CDFF").cgColor
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
var backBtn:UIButton = {
|
||
let _backBtn = UIButton()
|
||
_backBtn.setImage(UIImage(named: "yin_plane_star_back"), for: .normal)
|
||
_backBtn.addTarget(self, action: #selector(clickBackBtnAction), for: .touchUpInside)
|
||
return _backBtn
|
||
}()
|
||
|
||
private lazy var vapView:SVGAImageView = {
|
||
let _vapView = SVGAImageView()
|
||
_vapView.contentMode = .scaleAspectFill
|
||
return _vapView
|
||
}()
|
||
private lazy var parser:SVGAParser = {
|
||
let _parser = SVGAParser()
|
||
|
||
return _parser
|
||
}()
|
||
private lazy var giftView:SVGAImageView = {
|
||
let _giftView = SVGAImageView()
|
||
_giftView.contentMode = .scaleAspectFill
|
||
return _giftView
|
||
}()
|
||
private lazy var giftParser:SVGAParser = {
|
||
let _giftParser = SVGAParser()
|
||
|
||
return _giftParser
|
||
}()
|
||
var imageView:UIImageView = {
|
||
let _imageView = UIImageView(frame: CGRect(x: 0, y: 0, width:52, height: 52))
|
||
_imageView.layer.cornerRadius = 52/2
|
||
_imageView.layer.borderWidth = 1;
|
||
_imageView.layer.masksToBounds = true
|
||
return _imageView
|
||
}()
|
||
|
||
var bgImageView:UIImageView = {
|
||
let _bgImageView = UIImageView()
|
||
_bgImageView.image = UIImage(named: "yin_plane_star_water_drop_bg")
|
||
_bgImageView.isUserInteractionEnabled = true
|
||
return _bgImageView
|
||
}()
|
||
|
||
var refreshBtn:UIButton = {
|
||
let _refreshBtn = UIButton()
|
||
_refreshBtn.setImage(UIImage(named: "yin_plane_star_refresh"), for: .normal)
|
||
_refreshBtn.addTarget(self, action: #selector(refreshBtnAction), for: .touchUpInside)
|
||
return _refreshBtn
|
||
}()
|
||
|
||
|
||
var nameLabelView:UILabel = {
|
||
let _nameLabelView = UILabel()
|
||
_nameLabelView.text = ""
|
||
_nameLabelView.font = UIFont.systemFont(ofSize: 20, weight: .medium)
|
||
_nameLabelView.textColor = .white
|
||
return _nameLabelView
|
||
}()
|
||
var sexImageVeiw:UIImageView = {
|
||
let _sexImageVeiw = UIImageView()
|
||
|
||
return _sexImageVeiw
|
||
}()
|
||
var attentionBtn:UIButton = {
|
||
let _attentionBtn = UIButton()
|
||
_attentionBtn.setBackgroundImage(UIImage(named: "yin_plane_star_attention_bg"), for: .normal)
|
||
_attentionBtn.setImage(UIImage(named: "yin_plane_star_no_attention_icon"), for: .normal)
|
||
_attentionBtn.setImage(UIImage(named: "yin_plane_star_attention_icon"), for: .selected)
|
||
_attentionBtn.addTarget(self, action: #selector(attentionBtnAction), for: .touchUpInside)
|
||
return _attentionBtn
|
||
|
||
|
||
}()
|
||
var chatBtn:UIButton = {
|
||
let _chatBtn = UIButton()
|
||
_chatBtn.setBackgroundImage(UIImage(named: "yin_plane_star_attention_bg"), for: .normal)
|
||
_chatBtn.setImage(UIImage(named: "yin_plane_star_chat_icon"), for: .normal)
|
||
_chatBtn.addTarget(self, action: #selector(chatBtnAction), for: .touchUpInside)
|
||
return _chatBtn
|
||
}()
|
||
var bgSignatureView:UIImageView = {
|
||
let _bgSignatureView = UIImageView()
|
||
_bgSignatureView.image = UIImage(named: "yin_plane_star_signature_bg")
|
||
return _bgSignatureView
|
||
}()
|
||
var signatureView:UILabel = {
|
||
let _signatureView = UILabel()
|
||
_signatureView.font = UIFont.systemFont(ofSize: 11, weight: .regular)
|
||
_signatureView.textColor = ThemeColor(hexStr: "#ECEBF0")
|
||
_signatureView.text = ""
|
||
_signatureView.numberOfLines = 0
|
||
return _signatureView
|
||
}()
|
||
var bgUserInfoView:UIView = {
|
||
let _bgUserInfoView = UIView()
|
||
|
||
return _bgUserInfoView
|
||
}()
|
||
var timer:Timer?
|
||
var isStop:Bool = false
|
||
var refreshBlcok:RefreshBlcok?
|
||
}
|