ios - SWRevealViewController : Make Starting Background View Grey with custom animations

标签 ios swrevealviewcontroller setbackground

我是 iOS 的新手。我试图查找此内容,但找不到以下内容的明确答案。

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

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

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

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

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

最佳答案

在您的 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 的委托(delegate)方法添加到您的 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];
}

关于ios - SWRevealViewController : Make Starting Background View Grey with custom animations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26773077/

相关文章:

ios - 将 cornerRadius 和 setbackgroundimage 设置为 UIButton

ios - 在 Swift 中将输入字段字符串转换为 Int

swift - SWreveal - 如何返回到我开始使用的 View Controller

java - 奇怪的 setBackground() 错误 - Java Swing

ios - 如何在 iPad SplitViewController 中使用 SWRevealViewController

ios - SWRevealViewController 使侧边栏按钮静态并使 rearView 出现在 frontView 的顶部

java - 面板中的背景颜色不会改变

ios - xib文件中的uiview大小不正常

ios - 注册多个设备时为参数 'deviceNumber' 提供了无效值

ios - CoreBluetooth 反复断开连接