SWRevealViewController:使用自定义动画创建开始背景视图灰色

时间:2014-11-06 06:30:00

标签: ios swrevealviewcontroller setbackground

我对iOS很新。我试着查看一下,但找不到下面的明确答案。

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

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

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

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

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

1 个答案:

答案 0 :(得分: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];
}