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
6e258771
Commit
6e258771
authored
Dec 12, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// AI
parent
116605e5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
13 deletions
+139
-13
YHAIPictureMessageCell.swift
...dules/AI/AI-Dialogue(AI对话)/V/YHAIPictureMessageCell.swift
+117
-13
Contents.json
...ssets/AI-Chat/ai_chat_img_download.imageset/Contents.json
+22
-0
Group 2033196882@2x.png
...hat/ai_chat_img_download.imageset/Group 2033196882@2x.png
+0
-0
Group 2033196882@3x.png
...hat/ai_chat_img_download.imageset/Group 2033196882@3x.png
+0
-0
No files found.
galaxy/galaxy/Classes/Modules/AI/AI-Dialogue(AI对话)/V/YHAIPictureMessageCell.swift
View file @
6e258771
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
import
UIKit
import
UIKit
import
SDWebImage
import
SDWebImage
import
Photos
import
PhotosUI
class
YHAIPictureMessageCell
:
UITableViewCell
{
class
YHAIPictureMessageCell
:
UITableViewCell
{
...
@@ -68,16 +70,6 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -68,16 +70,6 @@ class YHAIPictureMessageCell: UITableViewCell {
ratio
=
img
.
size
.
width
/
img
.
size
.
height
ratio
=
img
.
size
.
width
/
img
.
size
.
height
}
}
imgH
=
imgW
/
ratio
imgH
=
imgW
/
ratio
// if imgH > 476 {
// imgH = 476
// imgW = imgH*ratio
//
// } else {
// imgW = 220
// imgH = imgW/ratio
// }
return
CGSizeMake
(
imgW
,
imgH
)
return
CGSizeMake
(
imgW
,
imgH
)
}
}
...
@@ -86,10 +78,17 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -86,10 +78,17 @@ class YHAIPictureMessageCell: UITableViewCell {
return
v
return
v
}()
}()
lazy
var
downloadBtn
:
UIButton
=
{
let
btn
=
UIButton
()
btn
.
setImage
(
UIImage
(
named
:
"ai_chat_img_download"
),
for
:
.
normal
)
btn
.
addTarget
(
self
,
action
:
#selector(
didDownloadBtnClicked
)
,
for
:
.
touchUpInside
)
btn
.
layer
.
cornerRadius
=
6.0
btn
.
YH_clickEdgeInsets
=
UIEdgeInsets
(
top
:
16
,
left
:
16
,
bottom
:
16
,
right
:
16
)
return
btn
}()
lazy
var
whiteContentView
:
UIView
=
{
lazy
var
whiteContentView
:
UIView
=
{
let
v
=
UIView
()
let
v
=
UIView
()
v
.
layer
.
cornerRadius
=
12.0
v
.
clipsToBounds
=
true
let
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
didMessageClicked
)
)
let
tap
=
UITapGestureRecognizer
(
target
:
self
,
action
:
#selector(
didMessageClicked
)
)
v
.
addGestureRecognizer
(
tap
)
v
.
addGestureRecognizer
(
tap
)
return
v
return
v
...
@@ -109,6 +108,11 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -109,6 +108,11 @@ class YHAIPictureMessageCell: UITableViewCell {
setupUI
()
setupUI
()
}
}
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
roundCorners
(
keepTopLeft
:
true
)
}
func
setupUI
()
{
func
setupUI
()
{
selectionStyle
=
.
none
selectionStyle
=
.
none
...
@@ -117,6 +121,7 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -117,6 +121,7 @@ class YHAIPictureMessageCell: UITableViewCell {
contentView
.
addSubview
(
shadowView
)
contentView
.
addSubview
(
shadowView
)
contentView
.
addSubview
(
whiteContentView
)
contentView
.
addSubview
(
whiteContentView
)
whiteContentView
.
addSubview
(
imgView
)
whiteContentView
.
addSubview
(
imgView
)
whiteContentView
.
addSubview
(
downloadBtn
)
whiteContentView
.
snp
.
makeConstraints
{
make
in
whiteContentView
.
snp
.
makeConstraints
{
make
in
make
.
left
.
equalTo
(
20
)
make
.
left
.
equalTo
(
20
)
...
@@ -130,6 +135,13 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -130,6 +135,13 @@ class YHAIPictureMessageCell: UITableViewCell {
make
.
edges
.
equalToSuperview
()
make
.
edges
.
equalToSuperview
()
}
}
downloadBtn
.
snp
.
makeConstraints
{
make
in
make
.
width
.
equalTo
(
26
)
make
.
height
.
equalTo
(
26
)
make
.
left
.
equalTo
(
16
)
make
.
bottom
.
equalTo
(
-
16
)
}
shadowView
.
snp
.
makeConstraints
{
make
in
shadowView
.
snp
.
makeConstraints
{
make
in
make
.
edges
.
equalTo
(
whiteContentView
)
make
.
edges
.
equalTo
(
whiteContentView
)
}
}
...
@@ -139,6 +151,98 @@ class YHAIPictureMessageCell: UITableViewCell {
...
@@ -139,6 +151,98 @@ class YHAIPictureMessageCell: UITableViewCell {
UIApplication
.
shared
.
yhKeyWindow
()?
.
endEditing
(
true
)
UIApplication
.
shared
.
yhKeyWindow
()?
.
endEditing
(
true
)
YHPictureReviewManager
.
shared
.
showNetWorkPicturs
(
curIndex
:
0
,
arrPicturs
:
[
imgInfo
.
imageUrl
])
YHPictureReviewManager
.
shared
.
showNetWorkPicturs
(
curIndex
:
0
,
arrPicturs
:
[
imgInfo
.
imageUrl
])
}
}
@objc
func
didDownloadBtnClicked
()
{
if
imgInfo
.
imageType
==
YHAIImageType
.
url
.
rawValue
{
// 尝试从缓存中获取图片
let
cachedImage
=
SDImageCache
.
shared
.
imageFromCache
(
forKey
:
imgInfo
.
imageUrl
)
downloadImage
(
cachedImage
,
urlString
:
imgInfo
.
imageDownloadUrl
)
}
else
if
imgInfo
.
imageType
==
YHAIImageType
.
local
.
rawValue
{
let
img
=
UIImage
(
named
:
imgInfo
.
localImageName
)
downloadImage
(
img
,
urlString
:
imgInfo
.
imageDownloadUrl
)
}
}
func
downloadImage
(
_
img
:
UIImage
?,
urlString
:
String
)
{
if
let
img
=
img
{
saveImage
(
img
)
return
}
guard
let
url
=
URL
(
string
:
urlString
)
else
{
YHHUD
.
flash
(
message
:
"保存失败"
)
return
}
let
task
=
URLSession
.
shared
.
dataTask
(
with
:
url
)
{
[
weak
self
]
data
,
response
,
error
in
DispatchQueue
.
main
.
async
{
guard
let
self
=
self
else
{
return
}
guard
let
data
=
data
else
{
YHHUD
.
flash
(
message
:
"保存失败"
)
return
}
let
image
=
UIImage
(
data
:
data
)
if
let
image
=
image
{
self
.
saveImage
(
image
)
}
}
}
task
.
resume
()
}
func
saveImage
(
_
image
:
UIImage
)
{
// 确保应用有权访问相册
PHPhotoLibrary
.
requestAuthorization
{
status
in
if
status
==
.
authorized
{
// 保存图片到相册
DispatchQueue
.
main
.
async
{
UIImageWriteToSavedPhotosAlbum
(
image
,
nil
,
nil
,
nil
)
YHHUD
.
flash
(
message
:
"保存成功"
)
}
}
else
{
DispatchQueue
.
main
.
async
{
YHHUD
.
flash
(
message
:
"保存失败,请检查系统权限"
)
}
}
}
}
func
roundCorners
(
keepTopLeft
:
Bool
)
{
let
path
=
UIBezierPath
()
let
radius
:
CGFloat
=
6.0
// 圆角半径
// 设置路径
path
.
move
(
to
:
CGPoint
(
x
:
keepTopLeft
?
0
:
radius
,
y
:
0
))
// 从左上角开始,视情况决定是否切圆角
// 左上角
if
keepTopLeft
{
path
.
addLine
(
to
:
CGPoint
(
x
:
0
,
y
:
0
))
// 不切左上角
}
else
{
path
.
addArc
(
withCenter
:
CGPoint
(
x
:
radius
,
y
:
radius
),
radius
:
radius
,
startAngle
:
.
pi
,
endAngle
:
.
pi
*
1.5
,
clockwise
:
true
)
}
// 右上角
path
.
addLine
(
to
:
CGPoint
(
x
:
self
.
bounds
.
width
,
y
:
0
))
path
.
addArc
(
withCenter
:
CGPoint
(
x
:
self
.
bounds
.
width
-
radius
,
y
:
radius
),
radius
:
radius
,
startAngle
:
.
pi
*
1.5
,
endAngle
:
0
,
clockwise
:
true
)
// 右下角
path
.
addLine
(
to
:
CGPoint
(
x
:
self
.
bounds
.
width
,
y
:
self
.
bounds
.
height
))
path
.
addArc
(
withCenter
:
CGPoint
(
x
:
self
.
bounds
.
width
-
radius
,
y
:
self
.
bounds
.
height
-
radius
),
radius
:
radius
,
startAngle
:
0
,
endAngle
:
.
pi
/
2
,
clockwise
:
true
)
// 左下角
path
.
addLine
(
to
:
CGPoint
(
x
:
0
,
y
:
self
.
bounds
.
height
))
path
.
addArc
(
withCenter
:
CGPoint
(
x
:
radius
,
y
:
self
.
bounds
.
height
-
radius
),
radius
:
radius
,
startAngle
:
.
pi
/
2
,
endAngle
:
.
pi
,
clockwise
:
true
)
path
.
close
()
// 关闭路径
// 创建 CAShapeLayer
let
maskLayer
=
CAShapeLayer
()
maskLayer
.
path
=
path
.
cgPath
self
.
whiteContentView
.
layer
.
mask
=
maskLayer
// 设置 UIView 的 mask
}
}
}
galaxy/galaxy/Res/Assets.xcassets/AI-Chat/ai_chat_img_download.imageset/Contents.json
0 → 100644
View file @
6e258771
{
"images"
:
[
{
"idiom"
:
"universal"
,
"scale"
:
"1x"
},
{
"filename"
:
"Group 2033196882@2x.png"
,
"idiom"
:
"universal"
,
"scale"
:
"2x"
},
{
"filename"
:
"Group 2033196882@3x.png"
,
"idiom"
:
"universal"
,
"scale"
:
"3x"
}
],
"info"
:
{
"author"
:
"xcode"
,
"version"
:
1
}
}
galaxy/galaxy/Res/Assets.xcassets/AI-Chat/ai_chat_img_download.imageset/Group 2033196882@2x.png
0 → 100644
View file @
6e258771
829 Bytes
galaxy/galaxy/Res/Assets.xcassets/AI-Chat/ai_chat_img_download.imageset/Group 2033196882@3x.png
0 → 100644
View file @
6e258771
1.06 KB
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