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.
UI Sheet View, Can you hide the x?
-
Is there any way to hide the name bar with the x on the sheet view? Thanks.
-
View.present
has an optional keyword parameter calledhide_title_bar
(passTrue
). When you present a view with the title bar hidden, you can dismiss it with a two-finger swipe down gesture. -
view.present(style='sheet', hide_title_bar=True)
-
Thanks!
-
Is there a way to stop two-finger swipe down gesture from exiting a view with a hidden title bar?
-
@RoninSage, this:
#coding: utf-8 from ui import * from objc_util import * UILayoutContainerView = ObjCClass('UILayoutContainerView') UISwipeGestureRecognizer = ObjCClass('UISwipeGestureRecognizer') def disable_swipe_to_close(view): v = view.objc_instance while not v.isKindOfClass_(UILayoutContainerView.ptr): v = v.superview() for gr in v.gestureRecognizers(): if gr.isKindOfClass_(UISwipeGestureRecognizer.ptr): gr.setEnabled(False) if __name__ == '__main__': bg = Button(title='Click me') bg.present('fullscreen', hide_title_bar=True) disable_swipe_to_close(bg)
-
@RoninSage, there’s of course also an option of replacing the two-finger swipe with some other gesture.
-
@mikael perfect, that does exactly what I wanted. Combined with guided access mode on the iPad, once the python program starts to run the user shouldn’t be able to leave the view at all.
But if anyone wants to use this code, I have edited the button function so it will eventually let you out, unfortunately I am not as elegant as @mikael
Cheers
#coding: utf-8 import ui, random from ui import * from objc_util import * def button_tapped(sender): rn=random.random() if rn <0.8: sender.title = 'unlucky, click again to close' button.size_to_fit else: view.close() UILayoutContainerView = ObjCClass('UILayoutContainerView') UISwipeGestureRecognizer = ObjCClass('UISwipeGestureRecognizer') def disable_swipe_to_close(view): v = view.objc_instance while not v.isKindOfClass_(UILayoutContainerView.ptr): v = v.superview() for gr in v.gestureRecognizers(): if gr.isKindOfClass_(UISwipeGestureRecognizer.ptr): gr.setEnabled(False) view = ui.View() view.background_color = (0.3,0.31,0.32) button = ui.Button(title='Click this button to close view') button.center = (view.width * 0.5, view.height * 0.5) button.flex = 'LRTB' button.action = button_tapped view.add_subview(button) view.present('fullscreen', hide_title_bar=True) disable_swipe_to_close(view)