Closed inadeem closed 9 years ago
No landscape support. In the past I've subclassed UINavigationController and added the following:
#import "NonRotatingNavigationController.h"
@interface NonRotatingNavigationController ()
@end
@implementation NonRotatingNavigationController
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
@end
Thanks! any clue on how to do it with Swift?
Swift could should be virtually identical to this, other than the minor syntax differences. Just implement those two methods and return those two values in a subclassed navigation controller.
Not sure what header files to import, or even if I have to. hmm
I used a lot of the code from Seanicus' repo. He forked yours. No header files in that one.
What header files do you need to import for what, specifically?
I'm looking at your code and I see that you imported some header files.
I created a new View controller, and subclassed it as UIViewController. Not sure how to link up the onBoard walkthrough pages..Created a new Swift file and this is the boilerplate code that comes with the file.
You need to create a UINavigationController
subclass, not UIViewController
.
Then, in your app delegate, you want something like this:
OnboardingContentViewController *firstPage = [OnboardingContentViewController contentWithTitle:title body:body image:image buttonText:buttonText action:^{
// action if you want one
}];
OnboardingContentViewController *secondPage = [OnboardingContentViewController contentWithTitle:title body:body image:image buttonText:buttonText action:^{
// action if you want one
}];
OnboardingContentViewController *thirdPage = [OnboardingContentViewController contentWithTitle:title body:body image:image buttonText:buttonText action:^{
// action if you want one
}];
OnboardingViewController *onboardingVC = [OnboardingViewController onboardWithBackgroundImage:image contents:@[firstPage, secondPage, thirdPage]];
NonRotatingNavigationController *nc = [[NonRotatingNavigationController alloc] initWithRootViewController:onboardingVC];
self.window.rootViewController = nc;
Porting that to swift should be easy and this should be enough to get you started. If you need any more help, I'd advise going through the demo project and learning how it works, there are multiple examples there, and like I said swift is similar enough to objective-c that you should be able to figure it out by looking at the examples.
Yea, realized I had used ViewController rather than Navigation. I will take a look at the code. Thanks.
This is what I used to get it to go to Landscape mode. Added this code in the onBoardingViewController.Swift file! Still a bit bugy but it seems to be OK for right now.
//**
override func viewWillAppear(animated: Bool)
{
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
override func shouldAutorotate() -> Bool {
// Lock autorotate
return false
}
override func supportedInterfaceOrientations() -> Int {
// Only allow Portrait
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
// Only allow Portrait
return UIInterfaceOrientation.Portrait
}
//**********
Any way to implement Landscape mode?
Alternatively, how would I "wrap it in a subclassed UINavigationController that only supports portrait"