如何使用ProMotion-Menu?
How to use ProMotion-Menu?
我只用 Promotion-Menu's Readme 中显示的代码做了一个新项目。我有这个:
# app_delegate.rb
class AppDelegate < PM::Delegate
def on_load(app, options)
@menu = open MenuDrawer
end
def show_menu
@menu.show :left
end
end
#menu_drawer.rb
class MenuDrawer < PM::Menu::Drawer
def setup
self.center = HomeScreen.new(nav_bar: true)
self.left = NavigationScreen
self.to_show = [:pan_bezel, :pan_nav_bar]
self.transition_animation = :swinging_door
self.max_left_width = 250
self.shadow = false
end
end
#navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'OVERWRITE THIS METHOD',
action: :swap_center_controller,
arguments: HomeScreen
}]
}]
end
def swap_center_controller(screen_class)
app_delegate.menu.center_controller = screen_class
end
end
我的应用程序是 运行,但没有侧边栏,您可以在此处看到:
我是不是漏掉了什么?
没有。你有什么应该工作。您必须平移边框或导航栏以显示左侧控制器(首次打开应用程序时隐藏)。我一直在考虑在示例中添加一个菜单按钮,以使其更加清晰。这可能是这样工作的:
# home_screen.rb
class HomeScreen < PM::Screen
title "Home"
def on_load
set_nav_bar_button :right, title: "Menu", action: :open_menu
end
def open_menu
app_delegate.show_menu
end
end
# navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'HomeScreen',
action: :swap_center_controller,
arguments: HomeScreen.new(nav_bar: true)
},{
title: 'HelpScreen',
action: :swap_center_controller,
arguments: HelpScreen.new(nav_bar: true)
}]
}]
end
def swap_center_controller(screen)
app_delegate.menu.center_controller = screen
app_delegate.menu.hide
end
end
您的 AppDelegate
和 MenuDrawer
将保持不变。
我只用 Promotion-Menu's Readme 中显示的代码做了一个新项目。我有这个:
# app_delegate.rb
class AppDelegate < PM::Delegate
def on_load(app, options)
@menu = open MenuDrawer
end
def show_menu
@menu.show :left
end
end
#menu_drawer.rb
class MenuDrawer < PM::Menu::Drawer
def setup
self.center = HomeScreen.new(nav_bar: true)
self.left = NavigationScreen
self.to_show = [:pan_bezel, :pan_nav_bar]
self.transition_animation = :swinging_door
self.max_left_width = 250
self.shadow = false
end
end
#navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'OVERWRITE THIS METHOD',
action: :swap_center_controller,
arguments: HomeScreen
}]
}]
end
def swap_center_controller(screen_class)
app_delegate.menu.center_controller = screen_class
end
end
我的应用程序是 运行,但没有侧边栏,您可以在此处看到:
我是不是漏掉了什么?
没有。你有什么应该工作。您必须平移边框或导航栏以显示左侧控制器(首次打开应用程序时隐藏)。我一直在考虑在示例中添加一个菜单按钮,以使其更加清晰。这可能是这样工作的:
# home_screen.rb
class HomeScreen < PM::Screen
title "Home"
def on_load
set_nav_bar_button :right, title: "Menu", action: :open_menu
end
def open_menu
app_delegate.show_menu
end
end
# navigation_screen.rb
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'HomeScreen',
action: :swap_center_controller,
arguments: HomeScreen.new(nav_bar: true)
},{
title: 'HelpScreen',
action: :swap_center_controller,
arguments: HelpScreen.new(nav_bar: true)
}]
}]
end
def swap_center_controller(screen)
app_delegate.menu.center_controller = screen
app_delegate.menu.hide
end
end
您的 AppDelegate
和 MenuDrawer
将保持不变。