mamaral / Onboard

An iOS framework to easily create a beautiful and engaging onboarding experience with only a few lines of code.
MIT License
6.46k stars 765 forks source link

Landscape Mode? #70

Closed inadeem closed 9 years ago

inadeem commented 9 years ago

Any way to implement Landscape mode?

Alternatively, how would I "wrap it in a subclassed UINavigationController that only supports portrait"

mamaral commented 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
inadeem commented 9 years ago

Thanks! any clue on how to do it with Swift?

mamaral commented 9 years ago

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.

inadeem commented 9 years ago

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.

mamaral commented 9 years ago

What header files do you need to import for what, specifically?

inadeem commented 9 years ago

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.

screen shot 2015-08-04 at 10 53 25 pm

mamaral commented 9 years ago

You need to create a UINavigationController subclass, not UIViewController.

mamaral commented 9 years ago

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.

inadeem commented 9 years ago

Yea, realized I had used ViewController rather than Navigation. I will take a look at the code. Thanks.

inadeem commented 9 years ago

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
}

//**********