Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landscape Mode? #70

Closed
inadeem opened this issue Aug 5, 2015 · 10 comments
Closed

Landscape Mode? #70

inadeem opened this issue Aug 5, 2015 · 10 comments
Labels

Comments

@inadeem
Copy link

inadeem commented Aug 5, 2015

Any way to implement Landscape mode?

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

@mamaral
Copy link
Owner

mamaral commented Aug 5, 2015

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
Copy link
Author

inadeem commented Aug 5, 2015

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

@mamaral
Copy link
Owner

mamaral commented Aug 5, 2015

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
Copy link
Author

inadeem commented Aug 5, 2015

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
Copy link
Owner

mamaral commented Aug 5, 2015

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

@inadeem
Copy link
Author

inadeem commented Aug 5, 2015

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
Copy link
Owner

mamaral commented Aug 5, 2015

You need to create a UINavigationController subclass, not UIViewController.

@mamaral
Copy link
Owner

mamaral commented Aug 5, 2015

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
Copy link
Author

inadeem commented Aug 5, 2015

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

@inadeem
Copy link
Author

inadeem commented Aug 7, 2015

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
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants