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.


    Help with moving button to subview

    Pythonista
    2
    4
    1872
    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.
    • AlanE
      AlanE last edited by

      Might I ask for help please in moving a button to a scroll view?

      On the iPhone I have a standard View which contains buttons, and a scroll view also containing buttons.

      I wish to touch the button on the view, then touch the button in the scroll so that the first button moves to the x,y of the button in the scroll area.

      I am not using a PYUI, all programmatically which I can achieve until the scroll is introduced.

      I can remove the button using #view.remove_subview(buttonVariable) but cannot move it.

      Help appreciated

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

        I should clarify. The view button is to become a button in the scroll view so that it scrolls with them.
        Thanks

        cvp 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @AlanE last edited by

          @AlanE If I correctly understood, try this

          import ui
          
          v = ui.View()
          v.frame = (0,0,500,600)
          
          sv1 = ui.View(name='sv1')
          sv1.background_color = 'white'
          sv1.frame = (0,0,v.width/2,v.height)
          v.add_subview(sv1)
          b1 = ui.Button(name='b1')
          b1.frame = (0,0,100,32)
          b1.border_width = 1
          def b1_tap(sender):
          	print(sender.title)
          	mv = sender.superview.superview
          	sender.superview.remove_subview(sender)
          	mv['sv2'].add_subview(sender)
          b1.action = b1_tap
          b1.title = 'b1'
          sv1.add_subview(b1)
          
          sv2 = ui.ScrollView(name='sv2')
          sv2.background_color = 'yellow'
          sv2.frame = (sv1.width,0,v.width-sv1.width,v.height)
          sv2.content_size = (sv2.width,2*sv2.height)
          v.add_subview(sv2)
          b2 = ui.Button(name='b2')
          b2.frame = (0,50,100,32)
          b2.border_width = 1
          def b2_tap(sender):
          	print(sender.title)
          b2.action = b2_tap
          b2.title = 'b2'
          sv2.add_subview(b2)
          
          
          v.present('sheet')```
          1 Reply Last reply Reply Quote 0
          • AlanE
            AlanE last edited by

            Splendid. Yes indeed, you understood enough of what I sought to be able to demonstrate that add_subview was the answer. I thought that was reserved for initialisation only. Great, thanks for taking the trouble to code that for me.

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