Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Where to put dynamic statements about position in custom UI view?
-
In a custom UI view, I have a statement
self.y = 50*len(self.superview.subviews)
. This is intended to be called as soon as the view is added as a subview. It allows the view to adjust its position based on how many subviews the superview has. However, if I place this statement inside__init__
, I get an AttributeError, because I define the view before it is added as a subview (I don't see a way around pre-declaration). If I place the statement in question insidedraw
, multiple views are in the same place, because I add the subviews before I present the view. Is there any way around this besides defining subviews after the parent view is presented? -
I am not entirely sure what you mean here how ever have you tried overriding the superviews
add_subview
method? -
I would recommend that you put your resizing logic in the
layout()
of your custom ui view. It will get called in between the time when you call present() but before your ui is visible to the user. It will also be called when the user rotates the device between landscape and portrait. I used to avoid using layout but now I do it almost all the time. -
Huh. Thanks @ccc, the fact that layout is called here is not well documented.
-
@Webmaster4o , a long time I had a problem with layout getting called as it should in a custom view class. One of the guys suggested I use self.flex = 'WH'.
I am not sure if you still have to do it. Just mentioning in case