2017-04-05 20:56:22 +00:00
|
|
|
//==============================================================================
|
|
|
|
// This file is part of Master Password.
|
|
|
|
// Copyright (c) 2011-2017, Maarten Billemont.
|
2014-09-23 02:32:31 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// Master Password is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2014-09-23 02:32:31 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// Master Password is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2014-09-23 02:32:31 +00:00
|
|
|
//
|
2017-04-05 20:56:22 +00:00
|
|
|
// You can find a copy of the GNU General Public License in the
|
|
|
|
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
|
|
|
|
//==============================================================================
|
2014-09-23 02:32:31 +00:00
|
|
|
|
|
|
|
#import "MPOverlayViewController.h"
|
|
|
|
|
2014-09-24 05:07:02 +00:00
|
|
|
@implementation MPOverlayViewController {
|
|
|
|
NSMutableDictionary *_dismissSegueByButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)awakeFromNib {
|
|
|
|
|
|
|
|
[super awakeFromNib];
|
2014-09-23 02:32:31 +00:00
|
|
|
|
2014-09-24 05:07:02 +00:00
|
|
|
_dismissSegueByButton = [NSMutableDictionary dictionary];
|
|
|
|
}
|
2014-09-23 02:32:31 +00:00
|
|
|
|
2014-09-26 04:32:07 +00:00
|
|
|
- (void)viewDidLoad {
|
2014-09-23 02:32:31 +00:00
|
|
|
|
2014-09-26 04:32:07 +00:00
|
|
|
[super viewDidLoad];
|
2014-09-23 02:32:31 +00:00
|
|
|
|
2014-09-26 04:32:07 +00:00
|
|
|
[self performSegueWithIdentifier:@"root" sender:self];
|
2014-09-23 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 05:07:02 +00:00
|
|
|
- (UIViewController *)childViewControllerForStatusBarStyle {
|
|
|
|
|
|
|
|
return [self.childViewControllers lastObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIViewController *)childViewControllerForStatusBarHidden {
|
|
|
|
|
|
|
|
return self.childViewControllerForStatusBarStyle;
|
|
|
|
}
|
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController
|
|
|
|
fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {
|
|
|
|
|
|
|
|
return [[MPOverlaySegue alloc] initWithIdentifier:identifier source:fromViewController destination:toViewController];
|
|
|
|
}
|
|
|
|
|
2014-09-27 05:27:05 +00:00
|
|
|
- (UIView *)addDismissButtonForSegue:(MPOverlaySegue *)segue {
|
2014-09-24 05:07:02 +00:00
|
|
|
|
|
|
|
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
[dismissButton addTarget:self action:@selector( dismissOverlay: ) forControlEvents:UIControlEventTouchUpInside];
|
2014-09-27 05:27:05 +00:00
|
|
|
dismissButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5f];
|
|
|
|
dismissButton.alpha = 0;
|
2014-09-24 05:07:02 +00:00
|
|
|
dismissButton.frame = self.view.bounds;
|
|
|
|
dismissButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
_dismissSegueByButton[[NSValue valueWithNonretainedObject:dismissButton]] =
|
|
|
|
[[MPOverlaySegue alloc] initWithIdentifier:@"dismiss-overlay"
|
|
|
|
source:segue.destinationViewController destination:segue.sourceViewController];
|
2014-09-27 05:27:05 +00:00
|
|
|
|
2014-09-24 05:07:02 +00:00
|
|
|
[self.view addSubview:dismissButton];
|
2014-09-27 05:27:05 +00:00
|
|
|
return dismissButton;
|
2014-09-24 05:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismissOverlay:(UIButton *)dismissButton {
|
|
|
|
|
|
|
|
NSValue *dismissSegueKey = [NSValue valueWithNonretainedObject:dismissButton];
|
|
|
|
[((UIStoryboardSegue *)_dismissSegueByButton[dismissSegueKey]) perform];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeDismissButtonForViewController:(UIViewController *)viewController {
|
|
|
|
|
|
|
|
UIButton *dismissButton = nil;
|
|
|
|
for (NSValue *dismissButtonValue in [_dismissSegueByButton allKeys])
|
|
|
|
if (((UIStoryboardSegue *)_dismissSegueByButton[dismissButtonValue]).sourceViewController == viewController) {
|
|
|
|
dismissButton = [dismissButtonValue nonretainedObjectValue];
|
2017-04-01 04:30:25 +00:00
|
|
|
NSAssert( [self.view.subviews containsObject:dismissButton], @"Missing dismiss button in dictionary." );
|
2014-09-24 05:07:02 +00:00
|
|
|
}
|
|
|
|
if (!dismissButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSValue *dismissSegueKey = [NSValue valueWithNonretainedObject:dismissButton];
|
|
|
|
[_dismissSegueByButton removeObjectForKey:dismissSegueKey];
|
|
|
|
|
|
|
|
[UIView animateWithDuration:0.1f animations:^{
|
|
|
|
dismissButton.alpha = 0;
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
[dismissButton removeFromSuperview];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MPOverlaySegue
|
|
|
|
|
2014-09-27 05:27:05 +00:00
|
|
|
+ (instancetype)dismissViewController:(UIViewController *)viewController {
|
|
|
|
|
|
|
|
return [[self alloc] initWithIdentifier:nil source:viewController destination:viewController];
|
|
|
|
}
|
|
|
|
|
2014-09-23 02:32:31 +00:00
|
|
|
- (void)perform {
|
|
|
|
|
|
|
|
UIViewController *sourceViewController = self.sourceViewController;
|
|
|
|
UIViewController *destinationViewController = self.destinationViewController;
|
|
|
|
MPOverlayViewController *containerViewController = self.sourceViewController;
|
2014-09-24 05:07:02 +00:00
|
|
|
while (containerViewController && ![(id)containerViewController isKindOfClass:[MPOverlayViewController class]])
|
2014-09-23 02:32:31 +00:00
|
|
|
containerViewController = (id)containerViewController.parentViewController;
|
|
|
|
NSAssert( [containerViewController isKindOfClass:[MPOverlayViewController class]],
|
|
|
|
@"Not an overlay container: %@", containerViewController );
|
|
|
|
|
|
|
|
if (!destinationViewController.parentViewController) {
|
|
|
|
// Winding
|
|
|
|
[containerViewController addChildViewController:destinationViewController];
|
2014-09-27 05:27:05 +00:00
|
|
|
UIView *dismissButton = [containerViewController addDismissButtonForSegue:self];
|
2014-09-24 05:07:02 +00:00
|
|
|
|
|
|
|
destinationViewController.view.frame = containerViewController.view.bounds;
|
|
|
|
destinationViewController.view.translatesAutoresizingMaskIntoConstraints = YES;
|
|
|
|
destinationViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
2014-09-23 02:32:31 +00:00
|
|
|
[containerViewController.view addSubview:destinationViewController.view];
|
2014-09-26 04:32:07 +00:00
|
|
|
[containerViewController setNeedsStatusBarAppearanceUpdate];
|
2014-09-24 05:07:02 +00:00
|
|
|
|
|
|
|
CGRectSetY( destinationViewController.view.frame, 100 );
|
|
|
|
destinationViewController.view.transform = CGAffineTransformMakeScale( 1.2f, 1.2f );
|
|
|
|
destinationViewController.view.alpha = 0;
|
|
|
|
|
2014-09-26 04:32:07 +00:00
|
|
|
[UIView transitionWithView:containerViewController.view duration:0.3f
|
2014-09-23 02:32:31 +00:00
|
|
|
options:UIViewAnimationOptionAllowAnimatedContent animations:^{
|
2014-09-24 05:07:02 +00:00
|
|
|
destinationViewController.view.transform = CGAffineTransformIdentity;
|
2014-09-23 02:32:31 +00:00
|
|
|
CGRectSetY( destinationViewController.view.frame, 0 );
|
2014-09-24 05:07:02 +00:00
|
|
|
destinationViewController.view.alpha = 1;
|
2014-09-27 05:27:05 +00:00
|
|
|
dismissButton.alpha = 1;
|
2014-09-23 02:32:31 +00:00
|
|
|
} completion:^(BOOL finished) {
|
2014-09-26 04:32:07 +00:00
|
|
|
[destinationViewController didMoveToParentViewController:containerViewController];
|
|
|
|
[containerViewController setNeedsStatusBarAppearanceUpdate];
|
2014-09-23 02:32:31 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Unwinding
|
|
|
|
[sourceViewController willMoveToParentViewController:nil];
|
2014-09-24 05:07:02 +00:00
|
|
|
[UIView transitionWithView:containerViewController.view duration:0.2f
|
2014-09-23 02:32:31 +00:00
|
|
|
options:UIViewAnimationOptionAllowAnimatedContent animations:^{
|
2014-09-24 05:07:02 +00:00
|
|
|
CGRectSetY( sourceViewController.view.frame, 100 );
|
|
|
|
sourceViewController.view.transform = CGAffineTransformMakeScale( 0.8f, 0.8f );
|
|
|
|
sourceViewController.view.alpha = 0;
|
|
|
|
[containerViewController removeDismissButtonForViewController:sourceViewController];
|
2014-09-23 02:32:31 +00:00
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
if (finished) {
|
|
|
|
[sourceViewController.view removeFromSuperview];
|
|
|
|
[sourceViewController removeFromParentViewController];
|
2014-09-24 05:07:02 +00:00
|
|
|
[containerViewController setNeedsStatusBarAppearanceUpdate];
|
2014-09-23 02:32:31 +00:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|