【问题标题】:SWRevealViewController : Make Starting Background View Grey with custom animationsSWRevealViewController : 使用自定义动画使启动背景视图变为灰色
【发布时间】:2015-01-02 13:58:21
【问题描述】:

我对 iOS 还很陌生。我试图查找此内容,但无法找到以下问题的明确答案。

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

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

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

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

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

【问题讨论】:

  • 在页面加载之前你需要动画

标签: ios swrevealviewcontroller setbackground


【解决方案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];
}

【讨论】:

  • 非常感谢您的快速回答,但这并没有改变任何东西。可能是因为我的 Firstpage.h 的定义方式吗? @interface FirstPage : UIViewController
  • 你是否在 didFinishLaunchingWithOptions 中设置了 SWRevealViewController 的委托。
  • 我在您提供的函数中尝试了简单的 NSLog,似乎它从未被调用过.. :-/
  • 在didFinishLaunchingWithOptions中设置它revealController.delegate = self;
  • 我实际上没有 AppDelegate.h 的revealController,我是否也需要创建该属性?
猜你喜欢
  • 2015-09-30
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 2011-02-06
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
相关资源
最近更新 更多