SWRevealViewController - 防止与后视图交互

时间:2016-06-03 13:34:02

标签: ios objective-c swift swrevealviewcontroller

使用SWRevealViewController时,我不想让用户与打开侧边菜单的视图进行交互。侧面菜单打开后,我希望能够与该菜单视图进行交互而不是另一个菜单视图。

任何帮助?

1 个答案:

答案 0 :(得分:2)

我一直在/在SWRevealViewController上工作 所以你需要的是将你的frontViewController添加为SWRevealViewControllerDelegate,然后实现这个功能

func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)

frontViewController转到左侧或前方位置时,您会收到通知

这是Swift代码

在你的frontViewController中

你需要添加

class FrontViewController: UIViewController, SWRevealViewControllerDelegate
 {
override func viewDidLoad() {
super.viewDidLoad()
self.revealViewController().delegate = self;
 }

// 您的代码 //

func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition) {
        if(position == FrontViewPosition.Left)
        {
            self.view.userInteractionEnabled = true;
            self.navigationController?.navigationBar.userInteractionEnabled = true;
        }else
        {
            self.view.userInteractionEnabled = false;
            self.navigationController?.navigationBar.userInteractionEnabled = false;

        }
}

<强> // EDITED

这是Objective C代码

class FrontViewController: UIViewController <SWRevealViewControllerDelegate>

在viewDidLoad中你需要添加

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.revealViewController.delegate = self;
}

// 您的代码 //

- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
    if(position == FrontViewPositionLeft)
    {
        self.view.userInteractionEnabled = NO;
        self.navigationController.navigationBar.userInteractionEnabled = NO;
    }else{
        self.view.userInteractionEnabled = YES;
        self.navigationController.navigationBar.userInteractionEnabled = YES;
    }
}

我希望这可以帮到你