Solved

xcode orientation

Posted on 2014-04-17
3
987 Views
Last Modified: 2014-04-21
I have an app I am creating in portrate mode.

I am using storyboard and one one view controller I created a new view controller class for one view controller in my story board.

The view controller I want to force it to be in landscape mode. How do I do that? The purpose is to play a YouTube video on this view.

AlorVideo.h
#import "ViewController.h"
#import "AlorVideo.h"

@interface AlorVideo : ViewController

@property (weak, nonatomic) IBOutlet UIWebView *AlorVideo;


@end

Open in new window


AlorVideo.m
#import "AlorVideo.h"

@interface AlorVideo ()


@end

@implementation AlorVideo

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    

    
    // Alor Video
    //UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 241, 198)];
    
    [webView setMediaPlaybackRequiresUserAction:NO];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Alor_Player" ofType:@"html"] isDirectory:NO]]];
    [self.AlorVideo addSubview:webView];
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

Open in new window


See screen shot from UI designer.
2014-04-17-10-03-49.png
0
Comment
Question by:Robert Saylor
3 Comments
 
LVL 14

Accepted Solution

by:
Hamidreza Vakilian earned 500 total points
ID: 40008463
Hi,

Add this snippet to your viewController.m:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
    else
        return YES;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}

Open in new window

0
 
LVL 12

Expert Comment

by:satsumo
ID: 40010264
Why are you creating an app in portrait if you want it to be landscape? Anyway, in the project settings disable the portrait orientations, and possibly one landscape orientation if you don't want to support both.

In your view controller, implement supportedInterfaceOrientations to return UIInterfaceOrientationMaskLandscape (Left or Right).

That should be enough to make it work, rotation can be tricky.
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 40012291
Thank you! Your code lead me to the solution.

I made these changes:

In viewcontroller.m (force portrait)
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    //return UIInterfaceOrientationMaskLandscape;
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
    else
        return YES;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    //return UIInterfaceOrientationLandscapeRight;
    return UIInterfaceOrientationPortrait;
}

Open in new window


in AlorVideo.m (landscape)
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
    else
        return YES;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}

Open in new window


Now, the pages I want in portrait stays in portrait and those I want in landscape stays in landscape.

The reason for this, our content is dive related material and the main pages look good in portrait where when we play a destination video is looks better in landscape.

Thank you for your help!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I download music to my iPad from iTunes? 14 145
InTunes and IOS issue 5 193
iOS Upgrade to 9.3.5 failing 7 59
How to uninstall icloud from my windows 7 PC! 4 109
Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question