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/IconCamera.swift | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-) diff --git a/LiveProject/shape/IconCamera.swift b/LiveProject/shape/IconCamera.swift index e69de29..2bd8d01 100644 --- a/LiveProject/shape/IconCamera.swift +++ b/LiveProject/shape/IconCamera.swift @@ -0,0 +1,60 @@ +// +// IconCamera.swift +// LiveProject +// +// Created by 倪路朋 on 6/27/25. +// + +import SwiftUI + +struct IconCameraShape: Shape { + func path(in rect: CGRect) -> Path { + var path = Path() + + // 比例参数 + let cornerRadius = rect.height * 0.1 + let bodyInset = rect.height * 0.1 + let lensDiameter = rect.height * 0.3 + let flashSize = CGSize(width: rect.width * 0.08, height: rect.height * 0.08) + + // 相机机身(主圆角矩形) + let bodyRect = rect.insetBy(dx: 0, dy: bodyInset) + path.addRoundedRect(in: bodyRect, cornerSize: CGSize(width: cornerRadius, height: cornerRadius)) + + // 镜头(中间大圆) + let lensOrigin = CGPoint( + x: rect.midX - lensDiameter / 2, + y: rect.midY - lensDiameter / 2 + ) + let lensRect = CGRect(origin: lensOrigin, size: CGSize(width: lensDiameter, height: lensDiameter)) + path.addEllipse(in: lensRect) + + // 闪光灯(机身内的小圆点) + let flashOrigin = CGPoint( + x: bodyRect.maxX - flashSize.width * 1.5, + y: bodyRect.minY + flashSize.height * 1.5 + ) + let flashRect = CGRect(origin: flashOrigin, size: flashSize) + path.addEllipse(in: flashRect) + + return path + } +} + +struct IconCamera: View { + var color: Color = .white + var size: CGSize = CGSize(width: 20, height:20) + var lineWidth: CGFloat = 2.0 + + var body: some View { + IconCameraShape() + .stroke(color, lineWidth: lineWidth) + .frame(width: size.width, height: size.height) + } +} + +struct IconCamera_Previews : PreviewProvider{ + static var previews: some View { + IconCamera(color: .black).background(.red) + } +} -- Gitblit v1.9.1