omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    4
    5
    2143
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Webmaster4o
      Webmaster4o last edited by

      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 inside draw, 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?

      1 Reply Last reply Reply Quote 0
      • Cethric
        Cethric last edited by

        I am not entirely sure what you mean here how ever have you tried overriding the superviews add_subview method?

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • Webmaster4o
            Webmaster4o last edited by

            Huh. Thanks @ccc, the fact that layout is called here is not well documented.

            Phuket2 1 Reply Last reply Reply Quote 0
            • Phuket2
              Phuket2 @Webmaster4o last edited by

              @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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors