Skip to content

Commit 96225be

Browse files
author
wz
committed
update magview
1 parent cfcab51 commit 96225be

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

Cliptest/ZYQuadRangleClip/ZYMaginifierglass.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class ZYMaginifierglass : UIView {
130130
guard magnifiedView != nil else { return }
131131

132132
magnifiedPoint = point
133+
133134
layer.setNeedsDisplay()
134135
}
135136

@@ -145,15 +146,15 @@ public class ZYMaginifierglass : UIView {
145146

146147
/// Renders magnification glass
147148
public override func draw(_ rect: CGRect) {
148-
guard let context = UIGraphicsGetCurrentContext() else { return }
149+
removeFromSuperview()
149150

151+
guard let context = UIGraphicsGetCurrentContext() else { return }
152+
150153
context.translateBy(x: radius, y: radius)
151154
context.scaleBy(x: scale, y: scale)
152155
context.translateBy(x: -magnifiedPoint.x, y: -magnifiedPoint.y)
153-
154-
removeFromSuperview()
155156
magnifiedView?.layer.render(in: context)
156157
magnifiedView?.addSubview(self)
158+
// print(" frame = \(self.frame) ")
157159
}
158-
159160
}

Cliptest/ZYQuadRangleClip/ZYQuadRangleClipView.swift

+30-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ extension ZYQuadRangleClipView {
3636

3737
open class ZYQuadRangleClipView: UIView {
3838

39+
40+
open var magView: UIView?
41+
3942
open var lineStrokeColor: UIColor! = UIColor(red: 72/255.0, green: 34/255.0, blue: 236/255, alpha: 1)
4043

4144
open var outCircleWidth: CGFloat = 30, innerCircleWidth: CGFloat = 20
@@ -47,6 +50,11 @@ open class ZYQuadRangleClipView: UIView {
4750
open var linePath = UIBezierPath()
4851
open var magnifierglass: ZYMaginifierglass!
4952

53+
/// 剪切范围是否合法
54+
open var isCropPathValid: Bool {
55+
return self.isLinePathValidate
56+
}
57+
5058
/// 剪切范围变化了
5159
open var cropChange: (() -> Void)?
5260

@@ -183,7 +191,26 @@ open class ZYQuadRangleClipView: UIView {
183191

184192
@objc func panGes(ges: UIPanGestureRecognizer) {
185193
var point = ges.location(in: self)
186-
let imagpoin = ges.location(in: self.superview)
194+
var imagpoin = ges.location(in: self.magView)
195+
let convertRect = self.convert(self.bounds, to: self.magView)
196+
print("mag point= \(imagpoin)- converntframe = \(convertRect) ")
197+
198+
if imagpoin.x < convertRect.minX {
199+
imagpoin.x = convertRect.minX
200+
}
201+
202+
if imagpoin.x > convertRect.maxX {
203+
imagpoin.x = convertRect.maxX
204+
}
205+
206+
if imagpoin.y < convertRect.minY {
207+
imagpoin.y = convertRect.minY
208+
}
209+
210+
if imagpoin.y > convertRect.maxY {
211+
imagpoin.y = convertRect.maxY
212+
}
213+
187214
if point.x <= 0 {
188215
point.x = 0
189216
}
@@ -219,7 +246,8 @@ open class ZYQuadRangleClipView: UIView {
219246

220247
switch ges.state {
221248
case .began:
222-
magnifierglass.magnifiedView = self.superview
249+
magnifierglass.magnifiedView = self.magView
250+
// magnifierglass.testView = self
223251
magnifierglass.magnify(at: imagpoin)
224252
case .changed:
225253
magnifierglass.magnify(at: imagpoin)

clipdemo.gif

-19.8 MB
Loading

0 commit comments

Comments
 (0)