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

Illustrate in demo how to add shapes programatically #56

Closed
wants to merge 3 commits into from

Conversation

max-christian
Copy link
Contributor

It can't be done in viewDidLoad because drawing.size has not been initialized at that point. Took quite a while to work this out.

… done in viewDidLoad because drawing.size has not been initialized at that point
@@ -199,6 +199,22 @@ class ViewController: UIViewController {
drawingView.userSettings.fontName = "Marker Felt"
applyUndoViewState()
}

override func viewDidLayoutSubviews() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add a new shape every time the view lays out its subviews, so it will potentially add infinite shapes.

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621398-viewdidlayoutsubviews

@stevelandeyasana
Copy link
Collaborator

Why does it matter that drawing.size isn't set for you to be able to add a shape?

Drawing.size does have a value on init, it's 320x320. https://github.com/Asana/Drawsana/blob/master/Drawsana/DrawsanaView.swift#L52

@max-christian
Copy link
Contributor Author

Because the aspect ratio of the added shapes gets messed up until the first user interaction when it suddenly corrects.

@stevelandeyasana
Copy link
Collaborator

stevelandeyasana commented May 26, 2020

OK, that sounds like a bug rather than something to add to the docs. :-)

What happens if you replace the code in your viewDidLayoutSubviews implementation with just the code below, and go back to adding your shape in viewDidLoad?

super.viewDidLayoutSubviews()
drawingView.redrawAbsolutelyEverything()

My hypothesis here is that DrawingView needs to re-render itself after layouts that change its size.

@max-christian
Copy link
Contributor Author

What happens if you replace the code in your viewDidLayoutSubviews implementation with just the code below, and go back to adding your shape in viewDidLoad?

super.viewDidLayoutSubviews()
drawingView.redrawAbsolutelyEverything()

Yep, that works but redrawAbsolutelyEverything is private.

@max-christian
Copy link
Contributor Author

Another problem is that the programatically-added TextShape jumps out of place when edited. It seems it's necessary to position it using some complex combination of .transform and .boundingRect.x,y. I've given up trying to make this work for now.

@stevelandeyasana
Copy link
Collaborator

I'll take a look at both issues next week. Your notes give me a lot to go on and I think I can probably fix them.

@stevelandeyasana
Copy link
Collaborator

I found the root cause and fixed it in #58.

It looks like you're adding support for PDF shapes. That's really cool, I'd love to integrate it into the library at some point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants