-
Notifications
You must be signed in to change notification settings - Fork 104
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
Conversation
… done in viewDidLoad because drawing.size has not been initialized at that point
Drawsana Demo/ViewController.swift
Outdated
@@ -199,6 +199,22 @@ class ViewController: UIViewController { | |||
drawingView.userSettings.fontName = "Marker Felt" | |||
applyUndoViewState() | |||
} | |||
|
|||
override func viewDidLayoutSubviews() { |
There was a problem hiding this comment.
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
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 |
Because the aspect ratio of the added shapes gets messed up until the first user interaction when it suddenly corrects. |
OK, that sounds like a bug rather than something to add to the docs. :-) What happens if you replace the code in your super.viewDidLayoutSubviews()
drawingView.redrawAbsolutelyEverything() My hypothesis here is that |
Yep, that works but |
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. |
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. |
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! |
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.