Forum Archive

ui.NavigationView error?

cg-mag

I use this code.

import ui

def button_tapped(sender):
    v = ui.View()
    v.background_color = 'green'
    v.name = 'Pushed View'
    sender.navigation_view.push_view(v)

root_view = ui.View()
root_view.background_color = 'white'
root_view.name = 'Root View'

button = ui.Button(title='Tap me')
button.action = button_tapped
button.bring_to_front()
button.background_color = 'gray'
root_view.add_subview(button)
nav_view = ui.NavigationView(root_view)
nav_view.present()

When I rotate my Iphone the button is cutting.
https://pp.vk.me/c621928/v621928381/41dd5/LiEgFgmEZBo.jpg
How to fix it? Thanks..

And I have another questions. Can I run some script when user pressed the button 'back' at the navigation view? Thanks.

cg-mag

Any comment?

Gerzer

Patience is a virtue! Does the button partially appear only in landscape? Or does the problem occur in portrait as well?

cg-mag

@Gerzer said:

Patience is a virtue! Does the button partially appear only in landscape? Or does the problem occur in portrait as well?

Start program at portrait. When rotate phone button was partially apearing.

JonB

Experiment with the flex attribute of the button, and perhaps root view and your Navigation view. the nav and rootview probably should be 'wh'.

I will point out that you have not actually set the frame of the button, or root view for that matter, which may be part of the issue.

JonB

Re detecting the back button, here is a method, not ideal but it works:

https://forum.omz-software.com/topic/1324/navigationview-on-screen

cg-mag

@JonB , Thank you!! I'll try.