Forum Archive

Resize a View that is already presented

robertiii

I am presenting a view as a popover. I want to resize the popover and add a tableview. The problem is not adding a tableview but how to go about resizing a view that is already being presented? Any work around or ideas. I would include code but I really haven’t got any! Hee Hee

cvp

@robertiii I think you can't resize à presented view. A workaround is to prepare your TableView as hidden and when you need to show it, to hide the whole main view by a semi-transparent shield view. Thus your popover view is not really presented but made visible.
Here a quick and dirty example.
The label is only there to show it will be covered by the shield.
The shield is a button so if you tap it, you simulate you tap outside the popover
The buttonItem is there to activate the TableView.
Of course, it is not a real popover thus you would have to compute the position

import ui

v = ui.View()
v.background_color = 'white'

l = ui.Label()
l.text = 'label'
l.frame = (10,40,200,32)
v.add_subview(l)

shield = ui.Button()
shield.frame = v.frame
shield.flex = 'wh'
shield.background_color = (1,1,1, 0.5)
shield.hidden = True

v.add_subview(shield)


tv = ui.TableView()
tv.frame = (100,50,200,50)
tv.row_height = 32
tv.data_source = ui.ListDataSource(items=[])
tv.hidden = True
v.add_subview(tv)

b = ui.ButtonItem()
b.title = 'popover'
def popover(sender):
    shield.hidden = False
    tv.data_source.items.append(str(1+len(tv.data_source.items)))
    tv.height = len(tv.data_source.items)*tv.row_height
    tv.hidden = False
    tv.bring_to_front()
b.action = popover  
v.right_button_items = (b,)
def popover_end(sender):
    shield.hidden = True
    tv.hidden =True
shield.action = popover_end

v.present('fullscreen') 
robertiii

So I have it presented with an arrow pointing to a menu bar buttonitem.

robertiii

```
def menuButton(sender):
pv = ui.load_view('menuPopOver')
pv.name = 'Menu'
pv.frame = (0,0,400,149)

x = sender.x + sender.width/2

y = sender.superview.titlebar_height + sender.y + sender.height/2

pv.present('popover',popover_location = (44.5,50))

```

robertiii

So I think I should somehow be able to use Transform..... but.... It only scales the view inside the Popup not the bounds of the the Popup itself.

JonB

You could perhaps turn off clips to bounds.

cvp

@robertiii said:

So I have it presented with an arrow pointing to a menu bar buttonitem.

I know that but as you can't resize a presented view, what I propose is only a workaround where you can always resize a non presented view.
If you want you can also simulate the triangle of the popover by a path and you simulate the presentation by un hiding the view. And you position your view under a button.
It is easy and you stay the master of the process: present=unhide close=hide

cvp

@robertiii I show you an example of how I use it in a script.
I have a view that is visible when I tap the "geometry" button. It is shown under the button like a popover presented view. All the other objects are hidden by a semi-transparent view, so you only can close the popover view by tapping outside or tap inside it.

If I tap a element in the popover view, its size is modified by inserting other infos.

And, if you want, you could draw a little triangle between the button and the popover view to simulate a real popover. I had preferred this way of using the borders to show the link between the two objects.

And so on for other menu buttons...you see the popover view height changing in function of what you tap in it

robertiii

I think I’m starting to follow. Sorry I do enough programming to understand little. HAHA

mikael

@cvp, looks like a fun app!

cvp

@mikael yes but never finished, I'm sorry to say it, but already far