1

我对iOS相当陌生。我试图查找此内容,但找不到以下问题的明确答案。

我有一个 SWRevealViewController 来处理我的 FirstPage 的侧边菜单栏。

单击 btn_Menu(或向左滑动)后出现 SWReveal 时,我希望 FirstPage 变为灰色且无法使用。

我看到在 FirstPage 中我们必须执行以下操作:

[btn_Menu addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];

我需要以某种方式更改revealToggle方法,或者在FirstPage中编写一个新的选择器,首先将其变暗,然后调用revealToggle?我不确定完成这项工作的最佳和最简单的方法是什么。非常感谢。

4

1 回答 1

1

在您的 FirstPage viewDidLoad 中执行此代码。

- (void)viewDidLoad
{
SWRevealViewController *  revealController=[[SWRevealViewController alloc]init];
    revealController = [self revealViewController];
    [self.view addGestureRecognizer:revealController.panGestureRecognizer];
       revealController.delegate=self;
    [revealController panGestureRecognizer];

    [revealController tapGestureRecognizer];
    [btnSideMenu addTarget:revealController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];

}

之后将 SWRevealViewController 的这个委托方法添加到您的 FirstPage 中。

- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
{
    if (revealController.frontViewPosition == FrontViewPositionRight)
    {
        UIView *lockingView = [UIView new];
        lockingView.translatesAutoresizingMaskIntoConstraints = NO;

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:revealController action:@selector(revealToggle:)];
        [lockingView addGestureRecognizer:tap];
        [lockingView addGestureRecognizer:revealController.panGestureRecognizer];
        [lockingView setTag:1000];
        [revealController.frontViewController.view addSubview:lockingView];


        lockingView.backgroundColor=[UIColor grayColor];

        NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView);

        [revealController.frontViewController.view addConstraints:
         [NSLayoutConstraint constraintsWithVisualFormat:@"|[lockingView]|"
                                                 options:0
                                                 metrics:nil
                                                   views:viewsDictionary]];
        [revealController.frontViewController.view addConstraints:
         [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[lockingView]|"
                                                 options:0
                                                 metrics:nil
                                                   views:viewsDictionary]];
        [lockingView sizeToFit];
    }
    else
        [[revealController.frontViewController.view viewWithTag:1000] removeFromSuperview];
}
于 2014-11-06T06:34:17.350 回答