【发布时间】:2015-09-06 03:15:57
【问题描述】:
ios 应用程序编码新手在这里,任何帮助将不胜感激。
我有一个应用程序,当旋转到横向时会自动打开一个侧边菜单,我需要它来禁用 navigationController 子视图中的菜单按钮。这是我的代码。
导航控制器
import Foundation
class GDNavigationController:UINavigationController{
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//Send notification when the device is rotated.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
func rotated(){
/*
Put the code here to access the menu button
*/
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
//disable the menu button here
self.revealViewController().setFrontViewPosition(FrontViewPosition.Right, animated: false)
}
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
//enable the menu button here
self.revealViewController().setFrontViewPosition(FrontViewPosition.Left, animated: false)
}
}
}
我的 ViewController 代码
import Foundation
class LocalCollectionController: UICollectionViewController{
@IBOutlet var MenuViewButton: UIBarButtonItem!
override func viewDidLoad() {
MenuViewButton.target = self.revealViewController()
MenuViewButton.action = Selector("revealToggle:")
}
}
根据选择的菜单项,我有不同的导航控制器加载不同的视图控制器。不同的导航控制器共享同一个子类,但我不知道加载了哪个视图控制器,这是我需要找出的以及如何访问该视图控制器中的按钮。
谁能帮忙?
【问题讨论】:
标签: swift ios8 uinavigationcontroller swrevealviewcontroller