Reveal de pantallas
Componente: https://github.com/John-Lluch/SWRevealViewController
1) La view debe tener como controlador SWRevealViewController
2) Hacer un segue a la view que se quiere mostrar. Si se quiere mostrar hacia la izquierda poner la propiedad sw_right en el identifier, si se quiere a la derecha sw_rear
3) En el viewDidLoad de la pantalla que los llama, poner el enlace del botón que dispara el movimiento:
[self.btnFilter addTarget:self.revealViewController action:@selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];
rightRevealToggle o revealToggle
4) En el controlador de la clase que construye el menú:
a) declarar variables
@interface LOMenuViewController () {
UIView *lockingView;
CGFloat fAlpha;
}
b) en viewDidLoad:
//Preparación del reveal para que se pueda mover deslizando el dedo
[self.revealViewController panGestureRecognizer];
self.revealViewController.delegate = self;
lockingView = [UIView new];
lockingView.translatesAutoresizingMaskIntoConstraints = NO;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self.revealViewController action:@selector(revealToggle:)];
[lockingView addGestureRecognizer:tap];
[lockingView setTag:1000];
lockingView.backgroundColor = [UIColor blackColor];
fAlpha = 0;
lockingView.alpha = 0;
lockingView.hidden = YES;
[self.revealViewController.frontViewController.view addSubview:lockingView];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView);
[self.revealViewController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"|[lockingView]|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:viewsDictionary]];
[self.revealViewController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[lockingView]|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:viewsDictionary]];
[lockingView sizeToFit];
c) Delegate:
#pragma mark - SWRevealViewController delegate
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
{
if (revealController.frontViewPosition == FrontViewPositionRight) {
} else {
lockingView.hidden = YES;
}
}
- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress{
lockingView.hidden = NO;
if (progress < 1) {
fAlpha = 0.7*progress;
} else {
fAlpha = 0.7;
}
lockingView.alpha = fAlpha;
}
- (void)revealController:(SWRevealViewController *)revealController animateToPosition:(FrontViewPosition)position {
if (position == FrontViewPositionRight) {
lockingView.hidden = NO;
[UIView animateWithDuration:self.revealViewController.toggleAnimationDuration animations:^{
lockingView.alpha = 0.7;
} completion:nil];
} else {
[UIView animateWithDuration:self.revealViewController.toggleAnimationDuration animations:^{
lockingView.alpha = 0.0;
} completion:^(BOOL completed) {lockingView.hidden = YES;}];
}
}
- (void)revealController:(SWRevealViewController *)revealController willAddViewController:(UIViewController *)viewController
forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated {
if (operation == SWRevealControllerOperationReplaceFrontController) {
[lockingView removeConstraints:lockingView.constraints];
[lockingView removeFromSuperview];
}
}
- (void)revealController:(SWRevealViewController *)revealController didAddViewController:(UIViewController *)viewController forOperation:(SWRevealControllerOperation)operation animated:(BOOL)animated {
if (operation == SWRevealControllerOperationReplaceFrontController) {
fAlpha = 0;
lockingView.alpha = 0;
lockingView.hidden = YES;
[viewController.view addSubview:lockingView];
[self.revealViewController.frontViewController.view addConstraint:[NSLayoutConstraint constraintWithItem:lockingView attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.revealViewController.frontViewController.view
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0]];
[self.revealViewController.frontViewController.view addConstraint:[NSLayoutConstraint constraintWithItem:lockingView attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.revealViewController.frontViewController.view
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0]];
/*
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(lockingView);
[self.revealViewController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"|[lockingView]|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:viewsDictionary]];
[self.revealViewController.frontViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[lockingView]|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:viewsDictionary]];
*/
[lockingView sizeToFit];
}
}