Robert Saylor
asked on
xcode orientation
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
AlorVideo.m
See screen shot from UI designer.
2014-04-17-10-03-49.png
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
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
See screen shot from UI designer.
2014-04-17-10-03-49.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! Your code lead me to the solution.
I made these changes:
In viewcontroller.m (force portrait)
in AlorVideo.m (landscape)
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!
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;
}
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;
}
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!
In your view controller, implement supportedInterfaceOrientat
That should be enough to make it work, rotation can be tricky.