feat(view): 增加 cardify view
增加 cardify view Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
990720f9d3
commit
a296e999c0
@ -7,6 +7,7 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
240EBF09299CFCE900429C8A /* Cardify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 240EBF08299CFCE900429C8A /* Cardify.swift */; };
|
||||||
240EDC3F2998A3B900A46AC9 /* MemorizeApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */; };
|
240EDC3F2998A3B900A46AC9 /* MemorizeApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */; };
|
||||||
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */; };
|
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */; };
|
||||||
240EDC432998A3BA00A46AC9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 240EDC422998A3BA00A46AC9 /* Assets.xcassets */; };
|
240EDC432998A3BA00A46AC9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 240EDC422998A3BA00A46AC9 /* Assets.xcassets */; };
|
||||||
@ -19,6 +20,7 @@
|
|||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
240EBF08299CFCE900429C8A /* Cardify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cardify.swift; sourceTree = "<group>"; };
|
||||||
240EDC3B2998A3B900A46AC9 /* Memorize.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Memorize.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
240EDC3B2998A3B900A46AC9 /* Memorize.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Memorize.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemorizeApp.swift; sourceTree = "<group>"; };
|
240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemorizeApp.swift; sourceTree = "<group>"; };
|
||||||
240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGameView.swift; sourceTree = "<group>"; };
|
240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGameView.swift; sourceTree = "<group>"; };
|
||||||
@ -66,6 +68,7 @@
|
|||||||
24FE51AE299CED6F00798617 /* Pie.swift */,
|
24FE51AE299CED6F00798617 /* Pie.swift */,
|
||||||
24E748FD299944F4009B5FE8 /* AspectVGrid.swift */,
|
24E748FD299944F4009B5FE8 /* AspectVGrid.swift */,
|
||||||
24E748FB29993781009B5FE8 /* Constans.swift */,
|
24E748FB29993781009B5FE8 /* Constans.swift */,
|
||||||
|
240EBF08299CFCE900429C8A /* Cardify.swift */,
|
||||||
245099F22998EAD6000CE9DA /* MemoryGame.swift */,
|
245099F22998EAD6000CE9DA /* MemoryGame.swift */,
|
||||||
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */,
|
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */,
|
||||||
240EDC422998A3BA00A46AC9 /* Assets.xcassets */,
|
240EDC422998A3BA00A46AC9 /* Assets.xcassets */,
|
||||||
@ -154,6 +157,7 @@
|
|||||||
files = (
|
files = (
|
||||||
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */,
|
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */,
|
||||||
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */,
|
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */,
|
||||||
|
240EBF09299CFCE900429C8A /* Cardify.swift in Sources */,
|
||||||
24E748FE299944F4009B5FE8 /* AspectVGrid.swift in Sources */,
|
24E748FE299944F4009B5FE8 /* AspectVGrid.swift in Sources */,
|
||||||
24E748FC29993782009B5FE8 /* Constans.swift in Sources */,
|
24E748FC29993782009B5FE8 /* Constans.swift in Sources */,
|
||||||
24FE51AF299CED6F00798617 /* Pie.swift in Sources */,
|
24FE51AF299CED6F00798617 /* Pie.swift in Sources */,
|
||||||
|
|||||||
30
Memorize/Cardify.swift
Normal file
30
Memorize/Cardify.swift
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Cardify.swift
|
||||||
|
// Memorize
|
||||||
|
//
|
||||||
|
// Created by ching on 2023/2/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct Cardify: ViewModifier {
|
||||||
|
var isFaceUp: Bool
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
ZStack {
|
||||||
|
let shape = RoundedRectangle(cornerRadius: const.DrawingConstants.cornerRadius)
|
||||||
|
if isFaceUp {
|
||||||
|
shape.fill().foregroundColor(.white)
|
||||||
|
shape.strokeBorder(lineWidth: const.DrawingConstants.lineWidth)
|
||||||
|
content
|
||||||
|
} else {
|
||||||
|
shape.fill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
func cadify(isFaceUp: Bool) -> some View {
|
||||||
|
self.modifier(Cardify(isFaceUp: isFaceUp))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ struct const {
|
|||||||
enum DrawingConstants {
|
enum DrawingConstants {
|
||||||
static let cornerRadius: CGFloat = 10
|
static let cornerRadius: CGFloat = 10
|
||||||
static let lineWidth: CGFloat = 3
|
static let lineWidth: CGFloat = 3
|
||||||
static let fontScale: CGFloat = 0.7
|
static let fontScale: CGFloat = 0.6
|
||||||
static let gridWidth: CGFloat = 80
|
static let gridWidth: CGFloat = 80
|
||||||
static let gridAspectRatio: CGFloat = 2 / 3
|
static let gridAspectRatio: CGFloat = 2 / 3
|
||||||
static let matchedCardOpacity: Double = 0
|
static let matchedCardOpacity: Double = 0
|
||||||
|
|||||||
@ -34,21 +34,12 @@ struct CardView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
ZStack {
|
ZStack {
|
||||||
let shape = RoundedRectangle(cornerRadius: const.DrawingConstants.cornerRadius)
|
Pie(startAngle: Angle(degrees: 270),
|
||||||
if card.isFaceUp && !card.isMatched {
|
endAngle: Angle(degrees: 380))
|
||||||
shape.fill().foregroundColor(.white)
|
.padding(const.DrawingConstants.piePadding)
|
||||||
shape.strokeBorder(lineWidth: const.DrawingConstants.lineWidth)
|
.opacity(const.DrawingConstants.pieOpacity)
|
||||||
Pie(startAngle: Angle(degrees: 270),
|
Text(card.content).font(font(in: geometry.size))
|
||||||
endAngle: Angle(degrees: 380))
|
}.cadify(isFaceUp: card.isFaceUp)
|
||||||
.padding(const.DrawingConstants.piePadding)
|
|
||||||
.opacity(const.DrawingConstants.pieOpacity)
|
|
||||||
Text(card.content).font(font(in: geometry.size))
|
|
||||||
} else if card.isMatched {
|
|
||||||
shape.opacity(const.DrawingConstants.matchedCardOpacity)
|
|
||||||
} else {
|
|
||||||
shape.fill()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user