From e21b1c797955a231f2bcf71818e0259fbb6aeba1 Mon Sep 17 00:00:00 2001 From: Runt <qingingrunt2010@qq.com> Date: Fri, 27 Jun 2025 15:57:25 +0000 Subject: [PATCH] 相机权限 --- LiveProject/shape/IconMic.swift | 63 +++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/LiveProject/shape/IconMic.swift b/LiveProject/shape/IconMic.swift index e69de29..91aec35 100644 --- a/LiveProject/shape/IconMic.swift +++ b/LiveProject/shape/IconMic.swift @@ -0,0 +1,63 @@ +// +// IconMic.swift +// LiveProject +// +// Created by 倪路朋 on 6/27/25. +// +import SwiftUI + +struct IconMicShape: Shape { + func path(in rect: CGRect) -> Path { + var path = Path() + + // 计算容器高度(麦克风主体 + 支架 + 底座 + 一点留白) + let micHeight = rect.height * 0.5 + let stemHeight = rect.height * 0.1 + let baseHeight = rect.height * 0.02 + let containerHeight = micHeight + stemHeight + baseHeight + + // 计算顶部偏移量,确保垂直居中 + let topOffset = (rect.height - containerHeight) / 2 + + // 主体:麦克风(居中) + let micWidth = rect.width * 0.3 + let micRect = CGRect( + x: rect.midX - micWidth / 2, + y: topOffset, + width: micWidth, + height: micHeight + ) + path.addRoundedRect(in: micRect, cornerSize: CGSize(width: micWidth / 2, height: micWidth / 2)) + + // 支架 + let stemTop = CGPoint(x: rect.midX, y: micRect.maxY) + let stemBottom = CGPoint(x: rect.midX, y: stemTop.y + stemHeight) + path.move(to: stemTop) + path.addLine(to: stemBottom) + + // 底座 + let baseWidth = rect.width * 0.3 + path.move(to: CGPoint(x: rect.midX - baseWidth / 2, y: stemBottom.y)) + path.addLine(to: CGPoint(x: rect.midX + baseWidth / 2, y: stemBottom.y)) + + return path + } +} +struct IconMic: View { + var color: Color = .white + var size: CGSize = CGSize(width: 20, height:30) + var lineWidth: CGFloat = 2.0 + + var body: some View { + IconMicShape() + .stroke(color, lineWidth: lineWidth) + .frame(width: size.width, height: size.height) + } +} + + +struct IconMic_Previews : PreviewProvider{ + static var previews: some View { + IconMic(color: .black).background(.red) + } +} -- Gitblit v1.9.1