I am a student and pretty new to programming. I am trying to learn Objective-C/Swift in my spare time. I made a game using spriteKit with swift that has multiple menus/scenes. <
As I can assume, view controller being presented on the screen was instantiated either automatically from main storyboard or by setting app's window.rootViewController
property.
In either case you can set rootViewController
again to be your vc
. To change rootViewController of your app you need to replace this line of code:
self.presentViewController(vc, animated: true, completion: nil)
... with one of the options bellow.
Objective-C
UIWindow *window = (UIWindow *)[[UIApplication sharedApplication].windows firstObject];
window.rootViewController = vc;
Swift
let window = UIApplication.sharedApplication().windows[0] as UIWindow;
window.rootViewController = vc;
Objective-C
UIWindow *window = (UIWindow *)[[UIApplication sharedApplication].windows firstObject];
[UIView transitionFromView:window.rootViewController.view
toView:vc.view
duration:0.65f
options:UIViewAnimationOptionTransitionCrossDissolve // transition animation
completion:^(BOOL finished){
window.rootViewController = vc;
}];
Swift
let window = UIApplication.sharedApplication().windows[0] as UIWindow;
UIView.transitionFromView(
window.rootViewController.view,
toView: vc.view,
duration: 0.65,
options: .TransitionCrossDissolve,
completion: {
finished in window.rootViewController = vc
})
Remarks: Once rootViewController value gets changed your original view controller reference count should became 0 hence it will be removed from the memory!