Commit 105c2f12 authored by yqz's avatar yqz

Merge branch 'develop_0409' into Fe

* develop_0409:
  修改
  修改充电引导页
parents c26a67b1 e79bbfb5
{
"images" : [
{
"filename" : "img_bj_battery.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_bj_battery@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_bj_battery@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_01.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_01@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_01@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_02.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_02@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_02@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_03.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_03@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_03@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_04.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_04@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_04@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_05.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_05@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_05@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_06.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_06@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_06@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_07.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_07@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_07@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "img_phone_battery_08.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_phone_battery_08@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_phone_battery_08@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_delete_duplicates.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_delete_duplicates@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_delete_duplicates@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -10,9 +10,40 @@ import Foundation
class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigationControllerDelegate {
let imageString : [String] = [
"img_phone_battery_02",
"img_phone_battery_03",
"img_phone_battery_04",
"img_phone_battery_05",
"img_phone_battery_06",
"img_phone_battery_07"
]
let tipString : [String] = [
"Animation Works with Apple Shortcuts",
"Tap to New Automation to add an automation",
"Scroll the page and select Charger section",
"Select 'ls Connected' and 'Run lmmediately',then tap on Next",
"Tap on New Blank Automation to connect the app",
"Type 'Cleanup' & select Run Charging Animation and tap on Done!"
]
let numberOfPages = 7
var pageControl: UIPageControl = {
let view = UIPageControl()
view.numberOfPages = 7
view.currentPage = 0
view.pageIndicatorTintColor = .white
view.currentPageIndicatorTintColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
return view
}()
lazy var guideScrollView: UIScrollView = {
let view = UIScrollView(frame: self.view.bounds)
view.contentSize = CGSize(width: self.view.bounds.width * CGFloat(8), height: self.view.bounds.height)
view.contentSize = CGSize(width: self.view.bounds.width * CGFloat(7), height: self.view.bounds.height)
view.isPagingEnabled = true
view.showsHorizontalScrollIndicator = false
view.delegate = self
......@@ -34,6 +65,7 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati
super.viewDidLoad()
self.view.addSubview(self.guideScrollView)
self.view.addSubview(self.closeButton)
self.view.addSubview(self.pageControl)
navigationController?.delegate = self
......@@ -42,19 +74,22 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati
make.top.equalToSuperview().offset(statusBarHeight + 15)
make.width.height.equalTo(28)
}
// 先添加一个快捷指令的页面
let shortcutsView = ChargeGuideOpenShortcutsView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
shortcutsView.backgroundColor = .gray
self.guideScrollView.addSubview(shortcutsView)
shortcutsView.callback = {[weak self] text in
guard let self else {return}
if text as! String == "next" {
self.guideScrollView.contentOffset = CGPointMake(self.view.bounds.width, 0)
}
self.pageControl.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.height.equalTo(8)
make.width.equalTo(250)
make.bottom.equalToSuperview().offset(-62)
}
for i in 1..<7{
for i in 0..<6{
let view = ChargeGuideNormalView(frame: CGRect(x: self.view.bounds.width * CGFloat(i), y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
view.guideView.image = UIImage(named: self.imageString[i])
view.tipTitleLabel.text = self.tipString[i]
if i==0 {
view.detailTipTitleLabel.isHidden = false
}else {
view.detailTipTitleLabel.isHidden = true
}
self.guideScrollView.addSubview(view)
view.orderFlag = i
view.callback = {[weak self] text in
......@@ -68,7 +103,7 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati
}
}
let endView = ChargeGuideEndView(frame: CGRect(x: self.view.bounds.width * 7, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
let endView = ChargeGuideEndView(frame: CGRect(x: self.view.bounds.width * 6, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
endView.callback = {[weak self] text in
guard let self else {return}
if text as! String == "over" {
......@@ -83,11 +118,21 @@ class ChargeGuideController : BaseViewController,UIScrollViewDelegate,UINavigati
}
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .pop {
return CustomPopAnimator()
}
return nil
if operation == .pop {
return CustomPopAnimator()
}
return nil
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let pageIndex = round(scrollView.contentOffset.x / scrollView.bounds.width)
if Int(pageIndex) == (self.numberOfPages - 1){
self.pageControl.isHidden = true
}else{
self.pageControl.isHidden = false
}
self.pageControl.currentPage = Int(pageIndex)
}
}
// 自定义转场动画类
......@@ -95,19 +140,19 @@ class CustomPopAnimator: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromVC = transitionContext.viewController(forKey:.from),
let toVC = transitionContext.viewController(forKey:.to) else {
return
}
let containerView = transitionContext.containerView
containerView.insertSubview(toVC.view, belowSubview: fromVC.view)
let screenBounds = UIScreen.main.bounds
let finalFrame = CGRect(x: 0, y: screenBounds.height * 2, width: screenBounds.width, height: screenBounds.height)
UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
fromVC.view.frame = finalFrame
}) { (finished) in
......
......@@ -13,16 +13,44 @@ class ChargeGuideStartController : BaseViewController {
lazy var backView : UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "img_bj_battery")
return view
}()
lazy var tipTitleLabel:UILabel={
let view = UILabel()
view.text = "Take a few minutes to set upthe feature"
view.backgroundColor = .clear
view.numberOfLines = 0
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 18, weight: .bold)
view.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
return view
}()
lazy var detailTipTitleLabel:UILabel={
let view = UILabel()
view.text = "Enjoy amazing animations every time you charge,just set it up once!"
view.numberOfLines = 0
view.backgroundColor = .clear
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 12, weight: .regular)
view.textColor = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1)
return view
}()
lazy var chargeView : UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "img_phone_battery_01")
return view
}()
lazy var startButton : UIButton = {
let view = UIButton()
view.setTitle("Get Started", for: .normal)
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
view.backgroundColor = UIColor(red: 0.15, green: 0.42, blue: 1, alpha: 1)
view.setTitleColor(.white, for: .normal)
view.clipsToBounds = true
view.layer.cornerRadius = 8
view.layer.cornerRadius = 25
view.addTarget(self, action: #selector(getStart), for: .touchUpInside)
return view
}()
......@@ -43,16 +71,41 @@ class ChargeGuideStartController : BaseViewController {
self.view.addSubview(self.backView)
self.view.addSubview(self.startButton)
self.view.addSubview(self.closeButton)
self.view.addSubview(self.tipTitleLabel)
self.view.addSubview(self.detailTipTitleLabel)
self.view.addSubview(self.chargeView)
self.backView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
}
self.tipTitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(statusBarHeight + 44)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
make.height.equalTo(50)
}
self.detailTipTitleLabel.snp.makeConstraints { make in
make.top.equalTo(self.tipTitleLabel.snp.bottom).offset(4)
make.height.equalTo(34)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
}
self.startButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.right.equalToSuperview().offset(-15)
make.bottom.equalToSuperview().offset(-70)
make.height.equalTo(46)
make.bottom.equalToSuperview().offset(-68)
make.height.equalTo(50)
}
self.chargeView.snp.makeConstraints { make in
make.bottom.equalTo(self.startButton.snp.top)
make.height.equalTo(476)
make.left.equalToSuperview().offset(27)
make.right.equalToSuperview().offset(-26)
}
self.closeButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
......
......@@ -8,31 +8,49 @@
import Foundation
class ChargeGuideEndView : UIView{
var callback :callBack<Any> = {text in}
var callback : callBack<Any> = {text in}
lazy var backView : UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "img_bj_battery")
return view
}()
lazy var gotoAnimationButton : UIButton = {
let view = UIButton()
view.setTitle("Go to Animations", for: .normal)
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
view.setTitleColor(.white, for: .normal)
view.clipsToBounds = true
view.layer.cornerRadius = 8
view.addTarget(self, action: #selector(gotoAnimation), for: .touchUpInside)
lazy var tipTitleLabel:UILabel={
let view = UILabel()
view.text = "Great Job!"
view.backgroundColor = .clear
view.numberOfLines = 0
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 18, weight: .bold)
view.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
return view
}()
lazy var detailTipTitleLabel:UILabel={
let view = UILabel()
view.text = "Let's find your perfect charging animation."
view.numberOfLines = 0
view.backgroundColor = .clear
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 12, weight: .regular)
view.textColor = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1)
return view
}()
lazy var startOverButton : UIButton = {
lazy var chargeView : UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "img_phone_battery_08")
return view
}()
lazy var startButton : UIButton = {
let view = UIButton()
view.setTitle("Start Over", for: .normal)
view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1)
view.setTitle("Go to Animations", for: .normal)
view.backgroundColor = UIColor(red: 0.15, green: 0.42, blue: 1, alpha: 1)
view.setTitleColor(.white, for: .normal)
view.clipsToBounds = true
view.layer.cornerRadius = 8
view.addTarget(self, action: #selector(startOver), for: .touchUpInside)
view.layer.cornerRadius = 25
view.addTarget(self, action: #selector(closeCurrentPage), for: .touchUpInside)
return view
}()
......@@ -44,34 +62,48 @@ class ChargeGuideEndView : UIView{
self.addSubview(self.backView)
self.addSubview(self.gotoAnimationButton)
self.addSubview(self.startOverButton)
self.addSubview(self.startButton)
self.addSubview(self.tipTitleLabel)
self.addSubview(self.detailTipTitleLabel)
self.addSubview(self.chargeView)
self.backView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
}
self.gotoAnimationButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.right.equalToSuperview().offset(-15)
make.bottom.equalToSuperview().offset(-150)
make.height.equalTo(46)
self.tipTitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(statusBarHeight + 44)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
make.height.equalTo(50)
}
self.detailTipTitleLabel.snp.makeConstraints { make in
make.top.equalTo(self.tipTitleLabel.snp.bottom).offset(4)
make.height.equalTo(34)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
}
self.startOverButton.snp.makeConstraints { make in
self.startButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.right.equalToSuperview().offset(-15)
make.bottom.equalToSuperview().offset(-70)
make.height.equalTo(46)
make.bottom.equalToSuperview().offset(-168)
make.height.equalTo(50)
}
self.chargeView.snp.makeConstraints { make in
make.top.equalTo(self.detailTipTitleLabel.snp.bottom).offset(42)
make.height.equalTo(352)
make.left.equalToSuperview().offset(27)
make.right.equalToSuperview().offset(-26)
}
}
@objc func gotoAnimation(){
@objc func closeCurrentPage(){
self.responderViewController()?.navigationController?.popViewController(animated: true)
}
@objc func startOver(){
callback("over")
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
......
......@@ -15,27 +15,33 @@ class ChargeGuideNormalView : UIView{
lazy var backView : UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "img_bj_battery")
return view
}()
lazy var backButton : UIButton = {
let view = UIButton()
view.setTitle("Back", for: .normal)
view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1)
view.setTitleColor(.white, for: .normal)
view.clipsToBounds = true
view.layer.cornerRadius = 8
view.addTarget(self, action: #selector(getBack), for: .touchUpInside)
lazy var tipTitleLabel:UILabel={
let view = UILabel()
view.text = "Animation Works with Apple Shortcuts"
view.backgroundColor = .clear
view.numberOfLines = 0
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 18, weight: .bold)
view.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
return view
}()
lazy var detailTipTitleLabel:UILabel={
let view = UILabel()
view.text = "Which helps to indicate the start of battery charging"
view.numberOfLines = 0
view.backgroundColor = .clear
view.textAlignment = .center
view.font = UIFont.systemFont(ofSize: 12, weight: .regular)
view.textColor = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1)
return view
}()
lazy var nextButton : UIButton = {
let view = UIButton()
view.setTitle("Next", for: .normal)
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
view.clipsToBounds = true
view.layer.cornerRadius = 8
view.addTarget(self, action: #selector(getNext), for: .touchUpInside)
lazy var guideView : UIImageView = {
let view = UIImageView()
return view
}()
......@@ -47,33 +53,36 @@ class ChargeGuideNormalView : UIView{
self.addSubview(self.backView)
self.addSubview(self.backButton)
self.addSubview(self.nextButton)
self.addSubview(self.tipTitleLabel)
self.addSubview(self.detailTipTitleLabel)
self.addSubview(self.guideView)
self.backView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
}
self.backView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
self.tipTitleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(statusBarHeight + 44)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
make.height.equalTo(50)
}
self.backButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.width.equalTo(self.snp.width).multipliedBy(0.5).offset(-20)
make.bottom.equalToSuperview().offset(-70)
make.height.equalTo(46)
self.detailTipTitleLabel.snp.makeConstraints { make in
make.top.equalTo(self.tipTitleLabel.snp.bottom).offset(4)
make.height.equalTo(34)
make.left.equalToSuperview().offset(30)
make.right.equalToSuperview().offset(-30)
}
self.nextButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.width.equalTo(self.snp.width).multipliedBy(0.5).offset(-20)
make.bottom.equalToSuperview().offset(-70)
make.height.equalTo(46)
self.guideView.snp.makeConstraints { make in
make.top.equalTo(self.detailTipTitleLabel.snp.bottom).offset(17)
make.centerX.equalToSuperview()
make.width.equalTo(316)
make.height.equalTo(534)
}
}
@objc func getBack(){
callback("back")
}
@objc func getNext(){
callback("next")
......
......@@ -31,6 +31,7 @@ class CompressSelectCell : UICollectionViewCell {
let options = PHImageRequestOptions()
options.isSynchronous = false
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [model.ident], options: nil)
PHImageManager.default().requestImage(for: fetchResult.firstObject!, targetSize: PHImageManagerMaximumSize, contentMode:.aspectFit, options: options) { (image, _) in
......
......@@ -33,7 +33,12 @@ class PreVideoController : BaseViewController {
private func setupVideoPlayer() {
guard let asset = fetchAsset() else { return }
PHImageManager.default().requestAVAsset(forVideo: asset, options: nil) { [weak self] (avAsset, _, _) in
let options = PHVideoRequestOptions()
options.version = .current
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
PHImageManager.default().requestAVAsset(forVideo: asset, options: options) { [weak self] (avAsset, _, _) in
guard let self = self, let avAsset = avAsset as? AVURLAsset else { return }
DispatchQueue.main.async {
......
......@@ -7,6 +7,8 @@
import Foundation
class PreViewController : BaseViewController {
var dataSource : [String] = []
var imageIdent : String = ""
......
......@@ -6,17 +6,37 @@
//
import Foundation
import Photos
class HomeVideoDetailController :BaseViewController {
private var headerHeight : CGFloat = 168
private var currentHeaderView: HomeVideoDetailCustomHeaderView?
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required init(model: HomePhotosModel) {
self.model = model
super.init(nibName: nil, bundle: nil)
}
private var videoDetailNavView:VideoDetaiNavView?
var model : HomePhotosModel? {
didSet{
self.collectionView.reloadData()
var resourceData : [String] = []
func dealData(){
var dataArray : [String] = []
for item in self.model.assets {
dataArray = dataArray + item
}
self.resourceData = dataArray
}
var model : HomePhotosModel
// 排序
var currentSort : Int = 0 {
didSet{
......@@ -24,23 +44,29 @@ class HomeVideoDetailController :BaseViewController {
}
}
// 资源类型 - 相册或者视频
var currentResourceType : Int = 0
// 所有的数据
var resourceData = [HomePhotosModel](){
// 当前页面选中的
var selectedModel : [String] = [] {
didSet{
DispatchQueue.main.async {
self.collectionView.reloadData()
DispatchQueue.main.async { [self] in
if self.selectedModel.count == 0 {
self.deleteButton.isHidden = true
self.headerHeight = 168
self.currentHeaderView?.tipBackView.isHidden = false
}else{
self.headerHeight = 90
self.currentHeaderView?.tipBackView.isHidden = true
self.deleteButton.isHidden = false
if self.selectedModel.count == 1{
self.deleteButton.setTitle("Delete \(self.selectedModel.count) Video", for: .normal)
}else{
self.deleteButton.setTitle("Delete \(selectedModel.count) Videos", for: .normal)
}
}
self.collectionView.collectionViewLayout.invalidateLayout()
}
}
}
// 当前页面选中的
var selectedModel : [ResourceModel] = []
lazy var collectionView:UICollectionView = {
......@@ -58,7 +84,6 @@ class HomeVideoDetailController :BaseViewController {
if #available(iOS 11.0, *) {
sview.contentInsetAdjustmentBehavior = .never
}
sview.backgroundColor = .clear
return sview
......@@ -66,12 +91,11 @@ class HomeVideoDetailController :BaseViewController {
lazy var deleteButton : UIButton = {
let view = UIButton()
view.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
view.setTitle("Delete", for: UIControl.State.normal)
view.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 1), for: .normal)
view.setTitleColor(.white, for: .normal)
view.clipsToBounds = true
view.layer.cornerRadius = 23
view.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
view.addTarget(self, action: #selector(deleteButtonAction), for: .touchUpInside)
return view
}()
......@@ -97,6 +121,9 @@ class HomeVideoDetailController :BaseViewController {
make.height.equalTo(46)
}
// 删除按钮默认隐藏,有选中的时候才出来
self.deleteButton.isHidden = true
}
override func viewDidLoad() {
......@@ -105,7 +132,7 @@ class HomeVideoDetailController :BaseViewController {
self.navigationController?.navigationBar.isHidden = true
setUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
......@@ -131,8 +158,27 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CompressSelectCell", for: indexPath) as! CompressSelectCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomeVideoDetailCell", for: indexPath) as! HomeVideoDetailCell
cell.resourceIdent = self.resourceData[indexPath.row]
cell.currentOrder = indexPath.row
cell.clickCallBack = {[weak self] click,order in
guard let self else {return}
if click == true {
self.selectedModel.append(self.resourceData[order])
}else{
self.selectedModel.removeAll { $0 == self.resourceData[order] }
}
}
cell.cellCallBack = {[weak self] ident,order in
guard let self else {return}
DispatchQueue.main.async {
let vc : PreVideoController = PreVideoController(localIdentifier: ident)
self.navigationController?.pushViewController(vc, animated: true)
}
}
return cell
}
......@@ -161,15 +207,17 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// 点击之后跳转详情页面
}
func referenceSizeForHeader(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGSize {
return CGSize (width: self.collectionView.width, height: 168)
return CGSize (width: self.collectionView.width, height: headerHeight)
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HomeVideoDetailCustomHeaderView", for: indexPath) as! HomeVideoDetailCustomHeaderView
// 记录当前的 headerView
currentHeaderView = header
return header
}else{
let footer = collectionView.dequeueReusableSupplementaryView(
......@@ -211,9 +259,32 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
@objc func deleteButtonAction(){
// 然后清理下当前页面的值
clearSelected()
// 删除当前选择
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: self.selectedModel, options: nil)
PHPhotoLibrary.shared().performChanges ({
PHAssetChangeRequest.deleteAssets(fetchResult as NSFastEnumeration)
}){ success, error in
if(success){
print("删除文件成功")
// 移除当前总数据源的数据
for item in self.selectedModel {
self.resourceData.removeAll{ $0 == item }
}
}else {
if let error = error {
print("删除文件时出错: \(error.localizedDescription)")
}
}
// 更新页面
DispatchQueue.main.async {
self.clearSelected()
self.collectionView.reloadData()
}
}
}
......
......@@ -34,8 +34,8 @@ class HomeViewController:BaseViewController {
guard let self else {return}
if otherItemRow == 0 {
DispatchQueue.main.async {
let vc:HomeVideoDetailController = HomeVideoDetailController()
vc.model = model
let vc:HomeVideoDetailController = HomeVideoDetailController(model: model)
vc.dealData()
self.navigationController?.pushViewController(vc, animated: true)
}
}
......@@ -52,6 +52,15 @@ class HomeViewController:BaseViewController {
self.navigationController?.pushViewController(vc, animated: true)
}
}
if otherItemRow == 2 || otherItemRow == 4{
DispatchQueue.main.async {
let vc:HomePhotosDetailViewController = HomePhotosDetailViewController(model: model)
vc.dealData()
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
homeView?.indexCallBack = {[weak self] index in
......
//
// PhotosDeleteViewController.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import Foundation
class PhotosDeleteViewController : BaseViewController {
}
//
// EmptyTrashView.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import Foundation
class EmptyTrashView : UIView {
lazy var numberLabel : UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 18, weight: .bold)
label.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
label.textAlignment = .left
label.text = "0 images"
return label
}()
lazy var numberTailLabel : UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 14, weight: .regular)
label.textColor = UIColor(red: 0.7, green: 0.7, blue: 0.7, alpha: 1)
label.textAlignment = .left
label.text = "in the trash"
return label
}()
lazy var infoView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
view.clipsToBounds = true
view.layer.cornerRadius = 24
return view
}()
lazy var trashImageView: UIImageView = {
let view = UIImageView()
view.backgroundColor = .clear
view.image = UIImage(named: "ic_delete_duplicates")
return view
}()
lazy var trashLabel : UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 16, weight: .bold)
label.textColor = .white
label.textAlignment = .left
label.text = "Empty Trash"
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.addSubview(self.numberLabel)
self.addSubview(self.numberTailLabel)
self.addSubview(self.infoView)
self.infoView.addSubview(self.trashImageView)
self.infoView.addSubview(self.trashLabel)
self.numberLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.top.equalToSuperview().offset(17)
make.width.equalTo(120)
make.height.equalTo(25)
}
self.numberTailLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(15)
make.top.equalTo(self.numberLabel.snp.bottom).offset(2)
make.width.equalTo(150)
make.height.equalTo(20)
}
self.infoView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.centerY.equalToSuperview()
make.width.equalTo(180)
make.height.equalTo(48)
}
self.trashImageView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16)
make.centerY.equalToSuperview()
make.width.equalTo(24)
make.height.equalTo(24)
}
self.trashLabel.snp.makeConstraints { make in
make.left.equalTo(self.trashImageView.snp.right).offset(8)
make.right.equalToSuperview().offset(-16)
make.centerY.equalToSuperview()
make.height.equalTo(22)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//
// HomePhotosDetailCustomHeaderView.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import Foundation
class HomePhotosDetailCustomHeaderView : UICollectionReusableView {
var sortCallback : ()->Void = {}
lazy var modelTitlelabel :UILabel = {
let label = UILabel()
label.text = "Photos"
label.textAlignment = .left
label.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
label.font = UIFont.systemFont(ofSize: 20, weight: .bold)
return label
}()
lazy var btnView :UIView = {
let view = UIView()
view.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 0.99, alpha: 1)
view.layer.cornerRadius = 16
view.clipsToBounds = true
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(sortAction))
view.isUserInteractionEnabled = true
view.addGestureRecognizer(tap)
return view
}()
lazy var selectImageView :UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "ic_newest_similar")
return view
}()
lazy var selectlabel :UILabel = {
let label = UILabel()
label.text = "Largest"
label.textAlignment = .center
label.textColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
label.font = UIFont.systemFont(ofSize: 14, weight: .bold)
return label
}()
lazy var countLabel :UILabel = {
let label = UILabel()
label.text = "0 Photos"
label.textAlignment = .left
label.textColor = UIColor(red: 0, green: 0.51, blue: 1, alpha: 1)
label.font = UIFont.systemFont(ofSize: 14, weight: .regular)
return label
}()
private func setUI(){
self.addSubview(self.modelTitlelabel)
self.addSubview(self.btnView)
self.addSubview(self.countLabel)
self.btnView.addSubview(self.selectImageView)
self.btnView.addSubview(self.selectlabel)
self.modelTitlelabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(0)
make.top.equalToSuperview().offset(14)
make.width.equalTo(150 * RScreenW())
make.height.equalTo(28)
}
self.btnView.snp.makeConstraints { make in
make.right.equalToSuperview().offset(0)
make.top.equalToSuperview().offset(12)
make.width.equalTo(103 * RScreenW())
make.height.equalTo(32)
}
self.selectImageView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.centerY.equalToSuperview()
make.width.height.equalTo(20)
}
self.selectlabel.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-12)
make.top.equalToSuperview().offset(6)
make.width.equalTo(60 * RScreenW())
make.height.equalTo(20)
}
self.countLabel.snp.makeConstraints { make in
make.left.equalTo(0)
make.right.equalTo(0)
make.top.equalTo(self.btnView.snp.bottom).offset(8)
make.height.equalTo(20)
}
}
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .white
setUI()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUI()
}
@objc func sortAction(){
sortCallback()
}
}
......@@ -89,7 +89,7 @@ class HomeVideoDetailCustomHeaderView : UICollectionReusableView {
lazy var moreImageView :UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "ic_cmpress_home_nor")
view.image = UIImage(named: "icon_left_setting_grey")
return view
}()
......@@ -161,15 +161,15 @@ class HomeVideoDetailCustomHeaderView : UICollectionReusableView {
}
self.tipLabel.snp.makeConstraints { make in
make.left.equalTo(self.tipImageView.snp.right).offset(10)
make.width.equalTo(120 * RScreenW())
make.height.equalTo(28)
make.top.equalToSuperview().offset(5)
make.width.equalTo(150 * RScreenW())
make.height.equalTo(22)
make.top.equalToSuperview().offset(15)
}
self.tipDetailLabel.snp.makeConstraints { make in
make.left.equalTo(self.tipImageView.snp.right).offset(10)
make.width.equalTo(150 * RScreenW())
make.height.equalTo(23)
make.top.equalTo(self.tipLabel.snp.bottom).offset(4)
make.height.equalTo(18)
make.top.equalTo(self.tipLabel.snp.bottom).offset(0)
}
self.moreImageView.snp.makeConstraints { make in
......
......@@ -195,7 +195,7 @@ class PhotoDataManager {
// 照片数据
semaphore.wait()
Print("正在截图")
Print("正在处理其他")
PhotoAndVideoMananger.mananger.dealImageAssetData { data in
var dataArray : [String] = []
for item in data {
......@@ -214,71 +214,6 @@ class PhotoDataManager {
}
}
// PhotoAndVideoMananger.mananger.fetXSOther { array in
//
// let dispatchGroup = DispatchGroup()
//
// dispatchGroup.enter()
// PhotoSimilarityFinder.processSimilarPhotoGroups(simalr:1,assetGroups: array) { array,fileSize in
//
// model1.assets = array
// model1.allFileSize = fileSize
//
// resultModel(allModel)
//
// dispatchGroup.leave()
// }
//
// dispatchGroup.enter()
// PhotoSimilarityFinder.processSimilarPhotoGroups(assetGroups: array) {array,fileSize in
//
// model2.assets = array
// model2.allFileSize = fileSize
//
// resultModel(allModel)
//
// dispatchGroup.leave()
// }
// dispatchGroup.enter()
// model2.assets = [ResourceManager.manager.getAllVideo()]
// dispatchGroup.leave()
//
// dispatchGroup.enter()
// PhotoAndVideoMananger.mananger.fetXSVideo { array in
//
// PhotoSimilarityFinder.processSimilarVideoGroups(videoGroups: array) {ids in
//
// model4.assets = ids
//
// resultModel(allModel)
//
// dispatchGroup.leave()
// }
// }
//
//
//
//
//
// dispatchGroup.notify(queue: .main) {
// print("所有异步操作都已完成")
//
// if model1.assets.count != 0 || model2.assets.count != 0 || model3.assets.count != 0 {
//
// PhotoDataManager.manager.saveToFileSystem(model: allModel)
// resultModel(allModel)
// }
//
// }
// }
}
}
......
//
// HomePhotosDetailCollectionCell.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import Foundation
import Photos
class HomePhotosDetailCollectionCell : UICollectionViewCell {
var cellCallBack : (String,Int)->Void = {ident,order in}
var currentMediaType : Int = 0
var resourceIdent : String = "" {
didSet{
DispatchQueue.global().async {
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: [self.resourceIdent], options: nil)
let assetsArray = fetchResult.objects(at: IndexSet(0..<fetchResult.count))
let options = PHImageRequestOptions()
options.isNetworkAccessAllowed = true
options.isSynchronous = false
PHImageManager.default().requestImage(for: assetsArray.first!, targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFill, options: options) { (image, info) in
DispatchQueue.main.async {
if let image = image {
self.backImageView.image = image
}
}
}
}
}
}
var currentOrder : Int = 0
lazy var backImageView: UIImageView = {
let view = UIImageView()
view.clipsToBounds = true
view.layer.masksToBounds = true
view.layer.cornerRadius = 12
view.backgroundColor = .gray
view.contentMode = .scaleAspectFill
view.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(cellClick))
view.addGestureRecognizer(tap)
return view
}()
@objc func cellClick(){
cellCallBack(self.resourceIdent,self.currentOrder)
}
override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(imageClick))
self.addGestureRecognizer(tap)
self.addSubview(self.backImageView)
self.backImageView.snp.makeConstraints { make in
make.left.right.height.width.equalToSuperview()
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func imageClick(){
}
}
......@@ -10,9 +10,63 @@ import Photos
class HomeVideoDetailCell : UICollectionViewCell {
var clickCallBack : (Bool,Int)->Void = {choose,order in}
var cellCallBack : (String,Int)->Void = {ident,order in}
var currentMediaType : Int = 0
var resourceIdent : String = "" {
didSet{
// 定义请求选项来获取视频的第一帧
let options = PHImageRequestOptions()
// 获取当前版本的照片或视频
options.version = .current
// 尽可能快地提供结果
options.deliveryMode = .opportunistic
// 允许从iCloud请求
options.isNetworkAccessAllowed = true
// 异步请求
options.isSynchronous = true
// 从 PHAsset 获取 AVAsset
if let videoAsset = PhotoAndVideoMananger.mananger.getPHAsssetwithID(ids: [resourceIdent]){
// 使用requestImageForAsset方法请求视频的第一帧图片
PHImageManager.default().requestImage(for: videoAsset, targetSize: CGSize(width: 400, height: 400), contentMode: PHImageContentMode.aspectFit, options: options) { image, _ in
// 处理获取到的图片
if let thumbnailImage = image {
// 图片大小
let resources = PHAssetResource.assetResources(for: videoAsset)
var assetSize : Int = 0
for resource in resources {
if let fileSize = resource.value(forKey: "fileSize") as? Int64 {
assetSize += Int(fileSize)
}
}
DispatchQueue.main.async {
// 确保在主线程更新UI
self.backImageView.image = thumbnailImage
let sizeKB : Double = Double(assetSize / 1024)
if sizeKB < 1024{
self.saveSizeLabel.text = String(format: "%.2f KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{
self.saveSizeLabel.text = String(format: "%.2f MB" ,sizeKB/1024)
}else{
self.saveSizeLabel.text = String(format: "%.2f GB" ,sizeKB/(1024 * 1024))
}
}
} else {
print("无法获取图片")
}
}
}
}
}
var currentOrder : Int = 0
var choose : Bool = false {
didSet{
if choose {
......@@ -31,10 +85,26 @@ class HomeVideoDetailCell : UICollectionViewCell {
view.clipsToBounds = true
view.layer.masksToBounds = true
view.layer.cornerRadius = 12
view.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.addTarget(self, action: #selector(cellClick))
view.addGestureRecognizer(tap)
return view
}()
lazy var playImageView: UIImageView = {
let view = UIImageView()
view.backgroundColor = .clear
view.image = UIImage(named: "btn_play_home")
view.isUserInteractionEnabled = true
return view
}()
lazy var saveSizeView: UIView = {
let view = UIView()
view.layer.masksToBounds = true
......@@ -48,7 +118,7 @@ class HomeVideoDetailCell : UICollectionViewCell {
view.textAlignment = .left
view.textColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
view.font = UIFont.systemFont(ofSize: 12, weight: .regular)
view.text = "Save 1.3MB"
view.text = "0.0MB"
return view
}()
......@@ -75,6 +145,11 @@ class HomeVideoDetailCell : UICollectionViewCell {
@objc func selectClick(){
self.choose = !self.choose
clickCallBack(self.choose,self.currentOrder)
}
@objc func cellClick(){
cellCallBack(self.resourceIdent,self.currentOrder)
}
......@@ -88,6 +163,7 @@ class HomeVideoDetailCell : UICollectionViewCell {
self.addGestureRecognizer(tap)
self.addSubview(self.backImageView)
self.backImageView.addSubview(self.playImageView)
self.addSubview(self.saveSizeView)
self.saveSizeView.addSubview(self.saveSizeLabel)
self.saveSizeView.addSubview(self.moreImageView)
......@@ -96,6 +172,10 @@ class HomeVideoDetailCell : UICollectionViewCell {
self.backImageView.snp.makeConstraints { make in
make.left.right.height.width.equalToSuperview()
}
self.playImageView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.height.equalTo(43)
}
self.saveSizeView.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.bottom.equalToSuperview().offset(-12)
......@@ -120,7 +200,6 @@ class HomeVideoDetailCell : UICollectionViewCell {
make.height.width.equalTo(24)
}
}
......
......@@ -312,6 +312,7 @@ class PhotoAndVideoMananger {
let targetSize = CGSize(width: 400, height: 400)
let options = PHImageRequestOptions()
options.isSynchronous = true
options.isNetworkAccessAllowed = true
imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: options) { result, _ in
image = result
}
......@@ -687,6 +688,7 @@ class PhotoAndVideoMananger {
imageRequestOptions.deliveryMode = .highQualityFormat
imageRequestOptions.isSynchronous = true
imageRequestOptions.resizeMode = .exact
imageRequestOptions.isNetworkAccessAllowed = true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment