diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 74d08c8..321bb33 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -15,13 +15,12 @@ static AppDelegate *sharedAppDelegate = nil; static NSObject *sharedEmulator = nil; NSString *DocumentsChangedNotification = @"documentsChanged"; -@interface AppDelegate () +@interface AppDelegate () @end @implementation AppDelegate { - UISwipeGestureRecognizerDirection modalPanePresentationDirection; } + (instancetype)sharedInstance { @@ -160,97 +159,11 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; #pragma mark - Settings / Insert Disk panels - (void)showSettings:(id)sender { - [self showModalPanel:@"settings" sender:sender]; + [self.window.rootViewController performSelector:@selector(showSettings:) withObject:sender]; } - (void)showInsertDisk:(id)sender { - [self showModalPanel:@"disk" sender:sender]; -} - -- (void)showModalPanel:(NSString*)name sender:(id)sender { - Class classToShow, otherClass; - if ([name isEqualToString:@"settings"]) { - classToShow = [SettingsViewController class]; - otherClass = [InsertDiskViewController class]; - } else { - classToShow = [InsertDiskViewController class]; - otherClass = [SettingsViewController class]; - } - - UIViewController *rootViewController = self.window.rootViewController; - UIViewController *presentedViewController = rootViewController.presentedViewController; - UIViewController *presentedTopViewController = [presentedViewController isKindOfClass:[UINavigationController class]] ? [(UINavigationController*)presentedViewController topViewController] : nil; - - if ([presentedTopViewController isKindOfClass:classToShow]) { - [presentedViewController dismissViewControllerAnimated:YES completion:nil]; - return; - } else if ([presentedTopViewController isKindOfClass:otherClass]) { - // flip - UIViewController *viewController = [rootViewController.storyboard instantiateViewControllerWithIdentifier:name]; - viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; - viewController.modalPresentationStyle = UIModalPresentationFormSheet; - UIView *windowSnapshotView = [self.window snapshotViewAfterScreenUpdates:NO]; - [self.window addSubview:windowSnapshotView]; - UIView *oldPanelSnapshotView = [presentedViewController.view snapshotViewAfterScreenUpdates:NO]; - [viewController.view addSubview:oldPanelSnapshotView]; - [rootViewController dismissViewControllerAnimated:NO completion:^{ - [rootViewController presentViewController:viewController animated:NO completion:^{ - UIView *emptyView = [[UIView alloc] initWithFrame:viewController.view.bounds]; - [windowSnapshotView removeFromSuperview]; - viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; - [UIView transitionFromView:oldPanelSnapshotView - toView:emptyView - duration:0.5 - options:UIViewAnimationOptionTransitionFlipFromRight - completion:^(BOOL finished) { - [emptyView removeFromSuperview]; - }]; - }]; - }]; - } else { - UIViewController *viewController = [rootViewController.storyboard instantiateViewControllerWithIdentifier:name]; - viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; - viewController.modalPresentationStyle = UIModalPresentationFormSheet; - if ([sender isKindOfClass:[UISwipeGestureRecognizer class]] && NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_0) { - modalPanePresentationDirection = [(UISwipeGestureRecognizer*)sender direction]; - viewController.transitioningDelegate = self; - } - [rootViewController presentViewController:viewController animated:YES completion:nil]; - } -} - -- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { - return self; -} - -- (NSTimeInterval)transitionDuration:(id)transitionContext { - return 0.3; -} - -- (void)animateTransition:(id)transitionContext { - UIView *containerView = [transitionContext containerView]; - UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey]; - - [containerView addSubview:toView]; - switch (modalPanePresentationDirection) { - case UISwipeGestureRecognizerDirectionLeft: - toView.transform = CGAffineTransformMakeTranslation(containerView.bounds.size.width, 0); - break; - case UISwipeGestureRecognizerDirectionRight: - toView.transform = CGAffineTransformMakeTranslation(-containerView.bounds.size.width, 0); - break; - case UISwipeGestureRecognizerDirectionDown: - toView.transform = CGAffineTransformMakeTranslation(0, -containerView.bounds.size.height); - break; - default: - toView.transform = CGAffineTransformMakeTranslation(0, containerView.bounds.size.height); - } - - [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ - toView.transform = CGAffineTransformIdentity; - } completion:^(BOOL finished) { - [transitionContext completeTransition:finished]; - }]; + [self.window.rootViewController performSelector:@selector(showInsertDisk:) withObject:sender]; } #pragma mark - Files diff --git a/Mini vMac/Base.lproj/Main.storyboard b/Mini vMac/Base.lproj/Main.storyboard index fc8f1c1..b3b6d95 100644 --- a/Mini vMac/Base.lproj/Main.storyboard +++ b/Mini vMac/Base.lproj/Main.storyboard @@ -10,7 +10,7 @@ - + @@ -34,13 +34,13 @@ - - + + - + @@ -240,20 +240,40 @@ - + - - + + - + - + - + + + + + + + + + + + + + + + + + + + + + @@ -334,26 +354,6 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index cb7b562..b566c7d 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -15,7 +15,7 @@ #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) -@interface ViewController () +@interface ViewController () @end @@ -24,6 +24,7 @@ KBKeyboardView *keyboardView; UISwipeGestureRecognizer *showKeyboardGesture, *hideKeyboardGesture, *insertDiskGesture, *showSettingsGesture; UIControl *pointingDeviceView; + UISwipeGestureRecognizerDirection modalPanePresentationDirection; #ifdef __IPHONE_13_4 UIPointerInteraction* interaction; #endif @@ -57,12 +58,12 @@ - (void)viewDidLoad { [super viewDidLoad]; [self installKeyboardGestures]; - insertDiskGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:[AppDelegate sharedInstance] action:@selector(showInsertDisk:)]; + insertDiskGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showInsertDisk:)]; insertDiskGesture.direction = UISwipeGestureRecognizerDirectionLeft; insertDiskGesture.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:insertDiskGesture]; - showSettingsGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:[AppDelegate sharedInstance] action:@selector(showSettings:)]; + showSettingsGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showSettings:)]; showSettingsGesture.direction = UISwipeGestureRecognizerDirectionRight; showSettingsGesture.numberOfTouchesRequired = 2; [self.view addGestureRecognizer:showSettingsGesture]; @@ -70,6 +71,61 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(emulatorDidShutDown:) name:[AppDelegate sharedEmulator].shutdownNotification object:nil]; } +- (void)showSettings:(id)sender { + [self performSegueWithIdentifier:@"settings" sender:sender]; +} + +- (void)showInsertDisk:(id)sender { + [self performSegueWithIdentifier:@"disk" sender:sender]; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + if ([sender isKindOfClass:[UIGestureRecognizer class]]) { + UISwipeGestureRecognizer *gestureRecognizer = (UISwipeGestureRecognizer*)sender; + modalPanePresentationDirection = gestureRecognizer.direction; + segue.destinationViewController.transitioningDelegate = self; + } else if (self.presentedViewController != nil && [@[@"disk", @"settings"] containsObject:segue.identifier]) { + [self dismissViewControllerAnimated:YES completion:nil]; + } +} + +- (id)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { + return self; +} + +- (NSTimeInterval)transitionDuration:(id)transitionContext { + return 0.3; +} + +- (void)animateTransition:(id)transitionContext { + UIView *containerView = [transitionContext containerView]; + UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey]; + + [containerView addSubview:toView]; + switch (modalPanePresentationDirection) { + case UISwipeGestureRecognizerDirectionLeft: + toView.transform = CGAffineTransformMakeTranslation(containerView.bounds.size.width, 0); + break; + case UISwipeGestureRecognizerDirectionRight: + toView.transform = CGAffineTransformMakeTranslation(-containerView.bounds.size.width, 0); + break; + case UISwipeGestureRecognizerDirectionDown: + toView.transform = CGAffineTransformMakeTranslation(0, -containerView.bounds.size.height); + break; + case UISwipeGestureRecognizerDirectionUp: + toView.transform = CGAffineTransformMakeTranslation(0, containerView.bounds.size.height); + break; + default: + break; + } + + [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ + toView.transform = CGAffineTransformIdentity; + } completion:^(BOOL finished) { + [transitionContext completeTransition:finished]; + }]; +} + - (BOOL)prefersStatusBarHidden { UIScreen *screen = self.view.window.screen; return CGRectEqualToRect(screen.bounds, self.view.window.bounds);