Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds customizable offset for the selection indicator #48

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
adds customizable offset for the selection indicator
in case the anchorPoint of the superview is different to the default
  • Loading branch information
Sebastian Hellmann committed Apr 21, 2020
commit 481dadb3b86afd1fad0d19244b98b6849282037a
7 changes: 6 additions & 1 deletion Drawsana/DrawsanaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public class DrawsanaView: UIView {
/// You may configure whatever properties you want to to make it look like
/// you want it to look.
public let selectionIndicatorView = UIView()


/// Offset for the selection Indicatior, because it is placed relative to the anchorPoint.
/// You should only have to change this if your anchorPoint is different from the default (0.5, 0.5)
public var selectionIndicatorAnchorPointOffset = CGPoint(x: 0.5, y: 0.5)

/// Layer that backs `DrawsanaView.selectionIndicatorView`. You may set this
/// layer's properties to change its visual apparance. Its `path` and `frame`
Expand Down Expand Up @@ -369,7 +374,7 @@ public class DrawsanaView: UIView {
// figure out where the shape is in space
offset + shape.transform.translation +
// Account for the coordinate system being anchored in the middle
CGPoint(x: -bounds.size.width / 2, y: -bounds.size.height / 2) +
CGPoint(x: -bounds.size.width * selectionIndicatorAnchorPointOffset.x, y: -bounds.size.height * selectionIndicatorAnchorPointOffset.y) +
// We've just moved the CENTER of the selection view to the UPPER LEFT
// of the shape, so adjust by half the selection size:
CGPoint(x: selectionBounds.size.width / 2, y: selectionBounds.size.height / 2)),
Expand Down