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"
|
|
|
|
|
2017-05-07 22:36:01 +00:00
|
|
|
@interface MPOverlayViewController()
|
|
|
|
|
|
|
|
@property(nonatomic, strong) NSMutableDictionary *dismissSegueByButton;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MPOverlayViewController
|
2014-09-24 05:07:02 +00:00
|
|
|
|
|
|
|
- (void)awakeFromNib {
|
|
|
|
|
|
|
|
[super awakeFromNib];
|
2014-09-23 02:32:31 +00:00
|
|
|
|
2017-05-07 22:36:01 +00:00
|
|
|
self.dismissSegueByButton = [NSMutableDictionary dictionary];
|
2014-09-24 05:07:02 +00:00
|
|
|
}
|
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];
|
2017-04-21 02:29:10 +00:00
|
|
|
dismissButton.visible = NO;
|
2014-09-24 05:07:02 +00:00
|
|
|
dismissButton.frame = self.view.bounds;
|
|
|
|
dismissButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
2017-05-07 22:36:01 +00:00
|
|
|
self.dismissSegueByButton[[NSValue valueWithNonretainedObject:dismissButton]] =
|
2014-09-24 05:07:02 +00:00
|
|
|
[[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];
|
2017-05-07 22:36:01 +00:00
|
|
|
[((UIStoryboardSegue *)self.dismissSegueByButton[dismissSegueKey]) perform];
|
2014-09-24 05:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeDismissButtonForViewController:(UIViewController *)viewController {
|
|
|
|
|
|
|
|
UIButton *dismissButton = nil;
|
2017-05-07 22:36:01 +00:00
|
|
|
for (NSValue *dismissButtonValue in [self.dismissSegueByButton allKeys])
|
|
|
|
if (((UIStoryboardSegue *)self.dismissSegueByButton[dismissButtonValue]).sourceViewController == viewController) {
|
2014-09-24 05:07:02 +00:00
|
|
|
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];
|
2017-05-07 22:36:01 +00:00
|
|
|
[self.dismissSegueByButton removeObjectForKey:dismissSegueKey];
|
2014-09-24 05:07:02 +00:00
|
|
|
|
|
|
|
[UIView animateWithDuration:0.1f animations:^{
|
2017-04-21 02:29:10 +00:00
|
|
|
dismissButton.visible = NO;
|
2014-09-24 05:07:02 +00:00
|
|
|
} 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 );
|
2017-04-21 02:29:10 +00:00
|
|
|
destinationViewController.view.visible = NO;
|
2014-09-24 05:07:02 +00:00
|
|
|
|
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 );
|
2017-04-21 02:29:10 +00:00
|
|
|
destinationViewController.view.visible = YES;
|
|
|
|
dismissButton.visible = YES;
|
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 );
|
2017-04-21 02:29:10 +00:00
|
|
|
sourceViewController.view.visible = NO;
|
2014-09-24 05:07:02 +00:00
|
|
|
[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
|