Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
68c5fd19
Commit
68c5fd19
authored
Apr 22, 2024
by
David黄金龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
保存图片到相册
parent
72637f91
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
28 deletions
+138
-28
YHHKEventViewController.swift
.../Classes/Modules/Home(首页)/C/YHHKEventViewController.swift
+76
-1
YHHomeWebViewController.swift
.../Classes/Modules/Home(首页)/C/YHHomeWebViewController.swift
+58
-0
YHHomeWebViewBottomForSavePicView.swift
...odules/Home(首页)/V/YHHomeWebViewBottomForSavePicView.swift
+3
-26
YHHomePageViewModel.swift
...axy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
+0
-1
YHMyViewController.swift
...alaxy/Classes/Modules/Mine(我的)/C/YHMyViewController.swift
+1
-0
No files found.
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHHKEventViewController.swift
View file @
68c5fd19
...
...
@@ -8,6 +8,7 @@
import
UIKit
import
WebKit
import
Photos
class
YHHKEventViewController
:
YHBaseViewController
{
let
homeViewModel
:
YHHomePageViewModel
=
YHHomePageViewModel
()
...
...
@@ -23,6 +24,17 @@ class YHHKEventViewController: YHBaseViewController {
super
.
viewWillAppear
(
animated
)
loadData
()
}
lazy
var
bottomViewForSavePic
:
YHHomeWebViewBottomForSavePicView
=
{
let
view
=
YHHomeWebViewBottomForSavePicView
()
view
.
isHidden
=
true
return
view
}()
private
var
picUrl
:
String
=
""
}
extension
YHHKEventViewController
{
...
...
@@ -53,6 +65,21 @@ extension YHHKEventViewController {
let
request
=
NSURLRequest
(
url
:
url
!
as
URL
)
// 加载请求
self
.
webview
.
load
(
request
as
URLRequest
)
let
navHeight
=
self
.
navigationController
?
.
navigationBar
.
frame
.
height
//获取状态栏高度
let
statusHeight
=
k_Height_statusBar
()
if
model
.
tag
.
contains
(
"日历"
)
{
picUrl
=
urlString
bottomViewForSavePic
.
isHidden
=
false
// 创建wkwebview
webview
.
frame
=
CGRect
(
x
:
0
,
y
:
statusHeight
+
navHeight
!
+
48
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
-
statusHeight
-
navHeight
!
-
48
-
YHHomeWebViewBottomForSavePicView
.
viewH
)
}
else
{
bottomViewForSavePic
.
isHidden
=
true
webview
.
frame
=
CGRect
(
x
:
0
,
y
:
statusHeight
+
navHeight
!
+
48
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
-
statusHeight
-
navHeight
!
-
48
)
}
}
return
view
}()
...
...
@@ -71,7 +98,55 @@ extension YHHKEventViewController {
// 创建wkwebview
webview
=
WKWebView
(
frame
:
CGRect
(
x
:
0
,
y
:
statusHeight
+
navHeight
!
+
48
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
-
statusHeight
-
navHeight
!
-
48
))
// 添加wkwebview
self
.
view
.
addSubview
(
webview
)
view
.
addSubview
(
webview
)
view
.
addSubview
(
bottomViewForSavePic
)
bottomViewForSavePic
.
snp
.
makeConstraints
{
make
in
make
.
left
.
right
.
bottom
.
equalToSuperview
()
make
.
height
.
equalTo
(
YHHomeWebViewBottomForSavePicView
.
viewH
)
}
bottomViewForSavePic
.
block
=
{
tag
in
self
.
saveImageToPhotoLib
()
}
}
}
extension
YHHKEventViewController
{
func
saveImageToPhotoLib
()
{
var
urlString
=
self
.
picUrl
guard
let
url
=
URL
(
string
:
urlString
)
else
{
YHHUD
.
flash
(
message
:
"参数错误,保存失败"
)
return
}
YHHUD
.
show
(
.
progress
(
message
:
"处理中..."
))
let
task
=
URLSession
.
shared
.
dataTask
(
with
:
url
)
{
data
,
response
,
error
in
DispatchQueue
.
main
.
async
{
YHHUD
.
hide
()
guard
let
data
=
data
,
error
==
nil
else
{
return
YHHUD
.
flash
(
message
:
"保存成功"
)
}
let
image
=
UIImage
(
data
:
data
)
if
let
image
=
image
{
// 保存图片到图库
PHPhotoLibrary
.
shared
()
.
performChanges
({
PHAssetChangeRequest
.
creationRequestForAsset
(
from
:
image
)
},
completionHandler
:
{
success
,
error
in
if
success
{
// 图片保存成功
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"保存成功"
)
}
}
else
if
let
error
=
error
{
// 保存失败
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"保存失败"
)
}
print
(
"保存图片出错:
\(
error
.
localizedDescription
)
"
)
}
})
}
}
}
task
.
resume
()
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHHomeWebViewController.swift
View file @
68c5fd19
...
...
@@ -8,6 +8,7 @@
import
UIKit
import
WebKit
import
Photos
class
YHHomeWebViewController
:
YHBaseViewController
,
WKUIDelegate
,
WKNavigationDelegate
{
...
...
@@ -31,6 +32,9 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
return
view
}()
//有些界面需要保存图片的功能
var
showSavePicBottomFlag
:
Bool
=
false
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -151,6 +155,23 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
bottomView
.
isHidden
=
true
webview
.
frame
=
CGRect
(
x
:
0
,
y
:
statusHeight
+
navHeight
!
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
-
statusHeight
-
navHeight
!
)
}
if
showSavePicBottomFlag
{
bottomViewForSavePic
.
isHidden
=
false
view
.
addSubview
(
bottomViewForSavePic
)
bottomViewForSavePic
.
snp
.
makeConstraints
{
make
in
make
.
left
.
bottom
.
right
.
equalToSuperview
()
make
.
height
.
equalTo
(
YHHomeWebViewBottomForSavePicView
.
viewH
)
}
bottomViewForSavePic
.
block
=
{
tag
in
self
.
saveImageToPhotoLib
()
}
webview
.
frame
=
CGRect
(
x
:
0
,
y
:
statusHeight
+
navHeight
!
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
-
statusHeight
-
navHeight
!
-
YHHomeWebViewBottomForSavePicView
.
viewH
)
}
else
{
bottomViewForSavePic
.
isHidden
=
true
}
getData
()
}
...
...
@@ -239,4 +260,41 @@ class YHHomeWebViewController: YHBaseViewController, WKUIDelegate, WKNavigationD
override
class
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
}
func
saveImageToPhotoLib
()
{
var
urlString
=
self
.
url
guard
let
url
=
URL
(
string
:
urlString
)
else
{
YHHUD
.
flash
(
message
:
"参数错误,保存失败"
)
return
}
YHHUD
.
show
(
.
progress
(
message
:
"处理中..."
))
let
task
=
URLSession
.
shared
.
dataTask
(
with
:
url
)
{
data
,
response
,
error
in
DispatchQueue
.
main
.
async
{
YHHUD
.
hide
()
guard
let
data
=
data
,
error
==
nil
else
{
return
YHHUD
.
flash
(
message
:
"保存成功"
)
}
let
image
=
UIImage
(
data
:
data
)
if
let
image
=
image
{
// 保存图片到图库
PHPhotoLibrary
.
shared
()
.
performChanges
({
PHAssetChangeRequest
.
creationRequestForAsset
(
from
:
image
)
},
completionHandler
:
{
success
,
error
in
if
success
{
// 图片保存成功
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"保存成功"
)
}
}
else
if
let
error
=
error
{
// 保存失败
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"保存失败"
)
}
print
(
"保存图片出错:
\(
error
.
localizedDescription
)
"
)
}
})
}
}
}
task
.
resume
()
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/V/YHHomeWebViewBottomForSavePicView.swift
View file @
68c5fd19
...
...
@@ -25,22 +25,21 @@ class YHHomeWebViewBottomForSavePicView: UIView {
typealias
Block
=
(
Int
)
->
()
var
block
:
Block
?
var
saveButton
:
UIButton
!
// var nextButton: UIButton!
}
private
extension
YHHomeWebViewBottomForSavePicView
{
func
setupUI
()
{
backgroundColor
=
.
white
saveButton
=
{
let
button
=
UIButton
(
type
:
.
custom
)
button
.
backgroundColor
=
UIColor
.
contentBkgColor
button
.
titleLabel
?
.
font
=
UIFont
.
PFSC_M
(
ofSize
:
15
)
button
.
contentHorizontalAlignment
=
.
center
button
.
setTitle
(
"保存图片到相册"
,
for
:
.
normal
)
button
.
setTitleColor
(
UIColor
.
mainText
Color
,
for
:
.
normal
)
button
.
setTitleColor
(
UIColor
.
brandMain
Color
,
for
:
.
normal
)
button
.
layer
.
cornerRadius
=
kCornerRadius6
button
.
layer
.
borderWidth
=
0.5
button
.
layer
.
borderColor
=
UIColor
.
brandMainColor
.
cgColor
button
.
addTarget
(
self
,
action
:
#selector(
save
)
,
for
:
.
touchUpInside
)
return
button
}()
...
...
@@ -51,28 +50,6 @@ private extension YHHomeWebViewBottomForSavePicView {
make
.
top
.
equalTo
(
12
)
make
.
height
.
equalTo
(
44
)
}
// nextButton = {
// let button = UIButton(type: .custom)
// button.titleLabel?.font = UIFont.PFSC_M(ofSize: 15)
// button.contentHorizontalAlignment = .center
// button.setTitle("保存清单图", for: .normal)
// button.setTitleColor(.white, for: .normal)
// button.layer.cornerRadius = kCornerRadius6
// button.clipsToBounds = true
// button.addTarget(self, action: #selector(submit), for: .touchUpInside)
// return button
// }()
// addSubview(nextButton)
// nextButton.snp.makeConstraints { make in
// make.right.equalTo(-kMargin)
// make.top.equalTo(8)
// make.height.equalTo(44)
// make.left.equalTo(kMargin)
// }
//
// nextButton.layoutIfNeeded()
// nextButton.addYinHeGradualLayer()
}
@objc
func
save
()
{
...
...
galaxy/galaxy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
View file @
68c5fd19
...
...
@@ -49,7 +49,6 @@ extension YHHomePageViewModel {
/*
firstPageFlag true - 首页 false - 更多
*/
func
getHomeNewsList
(
firstPageFlag
:
Bool
,
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
var
params
:
[
String
:
Any
]
=
[
"page"
:
curPageIndex
,
"page_size"
:
page_Size
]
...
...
galaxy/galaxy/Classes/Modules/Mine(我的)/C/YHMyViewController.swift
View file @
68c5fd19
...
...
@@ -275,6 +275,7 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
printLog
(
"我的测评码"
)
let
vc
=
YHHomeWebViewController
()
vc
.
vcTitle
=
"我的测评码"
vc
.
showSavePicBottomFlag
=
true
vc
.
url
=
"https://cdn-public.galaxy-immi.com/app/cepingma.png"
self
.
navigationController
?
.
pushViewController
(
vc
)
// todo: 黄金龙
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment