diff --git a/MoviaBox/AppDelegate/SceneDelegate.swift b/MoviaBox/AppDelegate/SceneDelegate.swift index e19d030..bbc987f 100644 --- a/MoviaBox/AppDelegate/SceneDelegate.swift +++ b/MoviaBox/AppDelegate/SceneDelegate.swift @@ -15,6 +15,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } + + SPAPPTool.windowScene = windowScene + ///监听语言切换 NotificationCenter.default.addObserver(self, selector: #selector(localizedDidChange), name: SPLocalizedManager.localizedDidChange, object: nil) ///监听网路变化 diff --git a/MoviaBox/Class/Mine/Controller/SPDeleteAccountViewController.swift b/MoviaBox/Class/Mine/Controller/SPDeleteAccountViewController.swift index d4437ea..414dcb6 100644 --- a/MoviaBox/Class/Mine/Controller/SPDeleteAccountViewController.swift +++ b/MoviaBox/Class/Mine/Controller/SPDeleteAccountViewController.swift @@ -139,11 +139,18 @@ extension SPDeleteAccountViewController { } @objc private func handleDeleteButton() { - SPLoginManager.manager.deleteAccount { isFinish in - if isFinish { - self.navigationController?.popViewController(animated: true) + + let alert = SPAlertView(iconImage: UIImage(named: "delete_account_icon_02"), text: "movia_deleteAccountInfo".localized, cancelTitle: "movia_Cancel".localized, sureTitle: "movia_delete".localized) + alert.clickSureButton = { + SPLoginManager.manager.deleteAccount { [weak self] isFinish in + guard let self = self else { return } + if isFinish { + self.navigationController?.popViewController(animated: true) + } } } + alert.show() + } } diff --git a/MoviaBox/Class/Mine/Controller/SPSettingsViewController.swift b/MoviaBox/Class/Mine/Controller/SPSettingsViewController.swift index d709dc8..e40c289 100644 --- a/MoviaBox/Class/Mine/Controller/SPSettingsViewController.swift +++ b/MoviaBox/Class/Mine/Controller/SPSettingsViewController.swift @@ -128,17 +128,15 @@ extension SPSettingsViewController { } ///退出登录 private func logout() { - let alert = UIAlertController(title: nil, message: "movia_confirm_logout".localized, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "movia_affirm".localized, style: .default, handler: { _ in + let alert = SPAlertView(iconImage: UIImage(named: "logout_icon_01"), text: "movia_logoutinfo".localized, cancelTitle: "movia_Cancel".localized, sureTitle: "movia_Log_out".localized) + alert.clickSureButton = { SPLoginManager.manager.logout { [weak self] isFinish in guard let self = self else { return } self.dataArr = self.createDataArr() } - })) + } + alert.show() - alert.addAction(UIAlertAction(title: "movia_Cancel".localized, style: .cancel)) - - self.present(alert, animated: true) } private func createDataArr() -> [SPMineItem] { @@ -150,9 +148,9 @@ extension SPSettingsViewController { ] if SPLoginManager.manager.isLogin { - arr.append(SPMineItem(type: .deleteAccount, title: "DeleteAccount".localized)) - arr.append(SPMineItem(type: .logout, title: "movia_signout".localized)) } + arr.append(SPMineItem(type: .deleteAccount, title: "DeleteAccount".localized)) + arr.append(SPMineItem(type: .logout, title: "movia_signout".localized)) return arr diff --git a/MoviaBox/Libs/APPTool/SPAPPTool.swift b/MoviaBox/Libs/APPTool/SPAPPTool.swift index 88740b1..1c738ca 100644 --- a/MoviaBox/Libs/APPTool/SPAPPTool.swift +++ b/MoviaBox/Libs/APPTool/SPAPPTool.swift @@ -12,6 +12,8 @@ class SPAPPTool: NSObject { ///app开启状态 引导页结束后变为已开启 static var isAppOpen = true + static var windowScene: UIWindowScene? + static var mainTabBarController: SPTabBarController? static func getAppDelegate() -> AppDelegate? { diff --git a/MoviaBox/Libs/Alert/SPAlertView.swift b/MoviaBox/Libs/Alert/SPAlertView.swift new file mode 100644 index 0000000..5c991d7 --- /dev/null +++ b/MoviaBox/Libs/Alert/SPAlertView.swift @@ -0,0 +1,149 @@ +// +// SPAlertView.swift +// MoviaBox +// +// Created by 佳尔 on 2025/5/13. +// + +import UIKit + +class SPAlertView: UIView { + + + var clickSureButton: (() -> Void)? + var clickCancelButton: (() -> Void)? + + private var alertWidth: CGFloat = kSPScreenWidth - 52 + private var alertHeight: CGFloat = 284 + + //MARK: UI属性 + private lazy var contentView: UIView = { + let view = UIView() + view.backgroundColor = .color202531() + view.layer.cornerRadius = 18 + view.layer.masksToBounds = true + view.layer.borderWidth = 1 + view.layer.borderColor = UIColor.color3D4556().cgColor + return view + }() + + private lazy var iconImageView: UIImageView = { + let imageView = UIImageView() + return imageView + }() + + private lazy var textLabel: UILabel = { + let label = UILabel() + label.numberOfLines = 0 + label.font = .fontMedium(ofSize: 20) + label.textColor = .colorFFFFFF() + label.textAlignment = .center + return label + }() + + private lazy var cancelButton: UIButton = { + let button = UIButton(type: .custom) + button.setTitleColor(.colorFFFFFF(), for: .normal) + button.titleLabel?.font = .fontMedium(ofSize: 14) + button.layer.cornerRadius = 18 + button.layer.masksToBounds = true + button.layer.borderWidth = 1 + button.layer.borderColor = UIColor.colorFFFFFF().cgColor + button.addTarget(self, action: #selector(handleCancelButton), for: .touchUpInside) + return button + }() + + private lazy var sureButton: UIButton = { + let button = UIButton(type: .custom) + button.setBackgroundImage(UIImage(color: .colorFF1F1F()), for: .normal) + button.setTitleColor(.colorFFFFFF(), for: .normal) + button.titleLabel?.font = .fontMedium(ofSize: 14) + button.layer.cornerRadius = 18 + button.layer.masksToBounds = true + button.addTarget(self, action: #selector(handleSureButton), for: .touchUpInside) + return button + }() + + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + init(iconImage: UIImage?, text: String, cancelTitle: String, sureTitle: String) { + super.init(frame: UIScreen.main.bounds) + self.backgroundColor = .color000000(alpha: 0.8) + alertHeight = 0 + +// contentView.frame = CGRect(x: 0, y: 0, width: alertWidth, height: alertHeight) + addSubview(contentView) + + iconImageView.image = iconImage + let imageSize = iconImage?.size ?? .zero + contentView.addSubview(iconImageView) + iconImageView.frame = CGRect(x: (alertWidth - imageSize.width) / 2, y: 28, width: imageSize.width, height: imageSize.height) + alertHeight = iconImageView.frame.maxY + + + textLabel.text = text + let textSize = textLabel.sizeThatFits(CGSize(width: alertWidth - 50, height: CGFLOAT_MAX)) + contentView.addSubview(textLabel) + textLabel.frame = CGRect(x: (alertWidth - textSize.width) / 2, y: alertHeight + 25, width: textSize.width, height: textSize.height) + alertHeight = textLabel.frame.maxY + + + cancelButton.setTitle(cancelTitle, for: .normal) + sureButton.setTitle(sureTitle, for: .normal) + + let buttonWidth = (alertWidth - 60 - 10) / 2 + let buttonHeight = 36.0 + contentView.addSubview(cancelButton) + contentView.addSubview(sureButton) + + cancelButton.frame = CGRect(x: 30, y: alertHeight + 38, width: buttonWidth, height: buttonHeight) + sureButton.frame = CGRect(x: cancelButton.frame.maxX + 10.0, y: cancelButton.frame.minY, width: buttonWidth, height: buttonHeight) + + alertHeight = sureButton.frame.maxY + 34 + + contentView.frame = CGRect(x: 0, y: 0, width: alertWidth, height: alertHeight) + } + + + + + +} + +extension SPAlertView { + // MARK: - 弹出 + @discardableResult func show() -> Self { + SPAlertWindowManager.manager.createWindow().addSubview(self) + creatShowAnimation() + + return self + } + func dismiss() { + removeFromSuperview() + SPAlertWindowManager.manager.dismissWindow() + } + private func creatShowAnimation() { + contentView.layer.position = center + contentView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) + UIView.animate(withDuration: 0.2, animations: { + self.contentView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) + }) { finished in + UIView.animate(withDuration: 0.1, animations: { + self.contentView.transform = CGAffineTransform.identity + }) + } + } + + @objc private func handleSureButton() { + self.clickSureButton?() + self.dismiss() + } + + @objc private func handleCancelButton() { + self.clickCancelButton?() + self.dismiss() + } +} diff --git a/MoviaBox/Libs/Alert/SPAlertWindowManager.swift b/MoviaBox/Libs/Alert/SPAlertWindowManager.swift new file mode 100644 index 0000000..56bd46a --- /dev/null +++ b/MoviaBox/Libs/Alert/SPAlertWindowManager.swift @@ -0,0 +1,38 @@ +// +// SPAlertWindowManager.swift +// MoviaBox +// +// Created by 佳尔 on 2025/5/13. +// + +import UIKit + +class SPAlertWindowManager { + + static let manager = SPAlertWindowManager() + + private var window: UIWindow? + + private var count = 0 + + func createWindow() -> UIWindow { + count += 1 + guard let window = window else { + let window = UIWindow(windowScene: SPAPPTool.windowScene!) + window.backgroundColor = .clear + window.windowLevel = .alert + window.isHidden = false + self.window = window + return window + } + return window + } + + func dismissWindow() { + count -= 1 + if count == 0 { + window?.isHidden = true + window = nil + } + } +} diff --git a/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Contents.json b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Contents.json new file mode 100644 index 0000000..6a4d508 --- /dev/null +++ b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Vector@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Vector@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@2x.png b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@2x.png new file mode 100644 index 0000000..930c7cd Binary files /dev/null and b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@2x.png differ diff --git a/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@3x.png b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@3x.png new file mode 100644 index 0000000..f7d99ed Binary files /dev/null and b/MoviaBox/Source/Assets.xcassets/icon/delete_account_icon_02.imageset/Vector@3x.png differ diff --git a/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Contents.json b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Contents.json new file mode 100644 index 0000000..5c4d3b1 --- /dev/null +++ b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Frame@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Frame@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@2x.png b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@2x.png new file mode 100644 index 0000000..b9dbd5e Binary files /dev/null and b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@2x.png differ diff --git a/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@3x.png b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@3x.png new file mode 100644 index 0000000..033e9fb Binary files /dev/null and b/MoviaBox/Source/Assets.xcassets/icon/logout_icon_01.imageset/Frame@3x.png differ diff --git a/MoviaBox/Source/en.lproj/Localizable.strings b/MoviaBox/Source/en.lproj/Localizable.strings index baf09c6..f1a9f08 100644 --- a/MoviaBox/Source/en.lproj/Localizable.strings +++ b/MoviaBox/Source/en.lproj/Localizable.strings @@ -103,7 +103,10 @@ "movia_play_now" = "Play Now"; "movia_login_title_facebook" = "Sign in with FaceBook"; "movia_login_title_apple" = "Sign in with Apple"; - +"movia_Log_out" = "Log out"; +"movia_logoutinfo" = "Are you sure you want to log out?"; +"movia_delete" = "Delete"; +"movia_deleteAccountInfo" = "Are you sure you want to deactivate your account?"; "movia_iap_error_toast_01" = "Invalid in-app purchase"; ///没有可恢复购买