我是 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/