From 29b38eeac8dfed2b485410f86e348cf7555b98f1 Mon Sep 17 00:00:00 2001 From: longitachi Date: Thu, 4 Jul 2024 10:41:25 +0800 Subject: [PATCH] format code --- Sources/Edit/ZLClipImageViewController.swift | 24 +++++++-------- Sources/Edit/ZLClipOverlayView.swift | 32 +++++++++++++++++--- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Sources/Edit/ZLClipImageViewController.swift b/Sources/Edit/ZLClipImageViewController.swift index e6bb3332..b824b14a 100644 --- a/Sources/Edit/ZLClipImageViewController.swift +++ b/Sources/Edit/ZLClipImageViewController.swift @@ -295,16 +295,16 @@ class ZLClipImageViewController: UIViewController { if let animateImageView { cancelClipAnimateFrame = clipBoxFrame - UIView.animate(withDuration: 0.25, animations: { + UIView.animate(withDuration: 0.25) { animateImageView.frame = self.clipBoxFrame self.bottomToolView.alpha = 1 self.rotateBtn.alpha = 1 self.clipRatioColView.alpha = self.showRatioColView ? 1 : 0 - }) { _ in - UIView.animate(withDuration: 0.1, animations: { + } completion: { _ in + UIView.animate(withDuration: 0.1) { self.mainScrollView.alpha = 1 self.overlayView.alpha = 1 - }) { _ in + } completion: { _ in animateImageView.removeFromSuperview() } } @@ -325,7 +325,7 @@ class ZLClipImageViewController: UIViewController { mainScrollView.frame = view.bounds - layoutInitialImage(aniamte: false) + layoutInitialImage(animate: true) bottomToolView.frame = CGRect(x: 0, y: view.bounds.height - ZLClipImageViewController.bottomToolViewH, width: view.bounds.width, height: ZLClipImageViewController.bottomToolViewH) bottomShadowLayer.frame = bottomToolView.bounds @@ -343,7 +343,7 @@ class ZLClipImageViewController: UIViewController { let ratioColViewX = rotateBtn.frame.maxX + 15 clipRatioColView.frame = CGRect(x: ratioColViewX, y: ratioColViewY, width: view.bounds.width - ratioColViewX, height: 70) - if clipRatios.count > 1, let index = clipRatios.firstIndex(where: { $0 == self.selectedRatio }) { + if showRatioColView, let index = clipRatios.firstIndex(where: { $0 == self.selectedRatio }) { clipRatioColView.scrollToItem(at: IndexPath(row: index, section: 0), at: .centeredHorizontally, animated: false) } } @@ -429,7 +429,7 @@ class ZLClipImageViewController: UIViewController { } } - private func layoutInitialImage(aniamte: Bool) { + private func layoutInitialImage(animate: Bool) { mainScrollView.minimumZoomScale = 1 mainScrollView.maximumZoomScale = 1 mainScrollView.zoomScale = 1 @@ -466,7 +466,7 @@ class ZLClipImageViewController: UIViewController { mainScrollView.zoomScale = zoomScale mainScrollView.contentSize = CGSize(width: editImage.size.width * zoomScale, height: editImage.size.height * zoomScale) - changeClipBoxFrame(newFrame: frame, animate: aniamte, updateInset: animate) + changeClipBoxFrame(newFrame: frame, animate: animate, updateInset: animate) if (frame.size.width < scaledSize.width - CGFloat.ulpOfOne) || (frame.size.height < scaledSize.height - CGFloat.ulpOfOne) { var offset = CGPoint.zero @@ -564,7 +564,7 @@ class ZLClipImageViewController: UIViewController { editImage = originalImage calculateClipRect() imageView.image = editImage - layoutInitialImage(aniamte: true) + layoutInitialImage(animate: true) let toFrame = view.convert(containerView.frame, from: mainScrollView) animateFakeImageView { @@ -618,7 +618,7 @@ class ZLClipImageViewController: UIViewController { } imageView.image = editImage - layoutInitialImage(aniamte: true) + layoutInitialImage(animate: true) let toFrame = view.convert(containerView.frame, from: mainScrollView) let transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) @@ -922,7 +922,7 @@ class ZLClipImageViewController: UIViewController { offset.x = max(-clipRect.minX, offset.x) offset.y = max(-clipRect.minY, offset.y) - self.changeClipBoxFrame(newFrame: clipRect, animate: true, updateInset: false, endEditing: true) + changeClipBoxFrame(newFrame: clipRect, animate: true, updateInset: false, endEditing: true) UIView.animate(withDuration: 0.25) { if scale < 1 - CGFloat.ulpOfOne || scale > 1 + CGFloat.ulpOfOne { self.mainScrollView.zoomScale *= scale @@ -1019,7 +1019,7 @@ extension ZLClipImageViewController: UICollectionViewDataSource, UICollectionVie calculateClipRect() configFakeAnimateImageView() - layoutInitialImage(aniamte: true) + layoutInitialImage(animate: true) let toFrame = view.convert(containerView.frame, from: mainScrollView) animateFakeImageView { diff --git a/Sources/Edit/ZLClipOverlayView.swift b/Sources/Edit/ZLClipOverlayView.swift index 36c92ce3..f50a6ace 100644 --- a/Sources/Edit/ZLClipOverlayView.swift +++ b/Sources/Edit/ZLClipOverlayView.swift @@ -4,6 +4,25 @@ // // Created by long on 2024/6/28. // +// Copyright (c) 2020 Long Zhang <495181165@qq.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import UIKit @@ -167,20 +186,25 @@ class ZLClipOverlayView: UIView { private func getGridLinesLayerPath() -> UIBezierPath { let path = UIBezierPath() + let r = cropRect.width / 2 + var diff: CGFloat = 0 + if isCircle && ZLPhotoConfiguration.default().editImageConfiguration.dimClippedAreaDuringAdjustments { + diff = r - sqrt(pow(r, 2) - pow(r / 3, 2)) + } // 画竖线 let dw = cropRect.width / 3 for i in 1...2 { let x = CGFloat(i) * dw + cropRect.minX - path.move(to: CGPoint(x: x, y: cropRect.minY)) - path.addLine(to: CGPoint(x: x, y: cropRect.maxY)) + path.move(to: CGPoint(x: x, y: cropRect.minY + diff)) + path.addLine(to: CGPoint(x: x, y: cropRect.maxY - diff)) } // 画横线 let dh = cropRect.height / 3 for i in 1...2 { let y = CGFloat(i) * dh + cropRect.minY - path.move(to: CGPoint(x: cropRect.minX, y: y)) - path.addLine(to: CGPoint(x: cropRect.maxX, y: y)) + path.move(to: CGPoint(x: cropRect.minX + diff, y: y)) + path.addLine(to: CGPoint(x: cropRect.maxX - diff, y: y)) } return path