Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Jul 4, 2024
1 parent eae55ce commit 29b38ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
24 changes: 12 additions & 12 deletions Sources/Edit/ZLClipImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
32 changes: 28 additions & 4 deletions Sources/Edit/ZLClipOverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
//
// Created by long on 2024/6/28.
//
// Copyright (c) 2020 Long Zhang <[email protected]>
//
// 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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 29b38ee

Please sign in to comment.