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.
Popover for nav bar button
-
I found this code somewhere on the internet heehee.
def menuButton(sender): pv = ui.View() pv.name = 'popover' pv.frame = (0,0,200,200) x = sender.x + sender.width/2 y = sender.superview.titlebar_height + sender.y + sender.height/2 pv.present('popover',popover_location = (x,y))
However this doesn’t work with navbar buttons as they don’t have the location information. How can I get the location info?
-
@robertiii try this
import ui from objc_util import * v = ui.View() v.background_color = 'white' def b_action(sender): vi = ObjCInstance(b).view() r = vi.convertRect_toView_(vi.bounds(),None) # x,y in screen coordinates, not in view x,y,w,h = r.origin.x,r.origin.y,r.size.width,r.size.height po = ui.View() po.frame = (0,0,200,200) po.present('popover',popover_location=(x+w/2,y+h)) b = ui.ButtonItem() b.title = 'popover' b.action = b_action v.right_button_items = (b,) v.present('fullscreen')
-
You can also get position in a view with
import ui from objc_util import * v = ui.View() v.background_color = 'white' def b_action(sender): vi = ObjCInstance(b).view() #r = vi.convertRect_toView_(vi.bounds(),None) r = vi.convertRect_toView_(vi.bounds(),ObjCInstance(v)) # x,y in view coordinates x,y,w,h = r.origin.x,r.origin.y,r.size.width,r.size.height po = ui.View() po.frame = (0,0,200,200) po.present('popover',popover_location=(x+w/2,y+h)) b = ui.ButtonItem() b.title = 'popover' b.action = b_action v.right_button_items = (b,) v.frame = (0,0,300,300) v.present('sheet') #v.present('fullscreen')
-
@cvp AWESOME TY! i was going to need this info for item details in my inventory 🙃