Help with moving button to subview
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.
I should clarify. The view button is to become a button in the scroll view so that it scrolls with them.
cvp 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')```
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.