Reputation: 165
I have a video app,but I would like it to stay only in landscape orientation
When in landscape it looks like this:
But when I turn around, it picks Portrait orientation and looks like this:
it would only stay in the Landscape orientation, already tried and tried many things I have seen and nothing has worked, someone help me?
[UPDATE]
Need only a view not use the orientation PORTRAIT, somebody already had this problem?
Does anyone have any other ideas? nothing worked here
[UPDATE] -> 30/09/2015
my solution:
in AppDelegate.m I use this:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation == YES)
return UIInterfaceOrientationMaskLandscape;
else
return UIInterfaceOrientationMaskAll;
}
AppDelegate.h :
@property () BOOL restrictRotation;
where I want to stay only landscape I used it (videoViewController.m) :
in viewDidLoad
[self restrictRotation:YES];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
and add method:
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
remember if the #import "AppDelegate.h" in videoViewController.h
and the views that you do not want is locked in landscape add:
in viewDidLoad:
[self restrictRotation:YES];
and method:
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
Problem SOLVED! thx all
Upvotes: 4
Views: 1155
Reputation: 404
You can set transform angle for player screen/Player parent view to show always in landscape mode.
Add this block of code in view did load method to show in landscape mode.
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
[[self view] setBounds:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
CGFloat radians = atan2f(self.view.transform.b, self.view.transform.a);
if (radians!=M_PI / 2) {
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
}
}
and add this method to always show in landscape mode on device rotation.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
[[self view] setBounds:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
CGFloat radians = atan2f(self.view.transform.b, self.view.transform.a);
if (radians!=M_PI / 2) {
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
}
}else{
[[self view] setBounds:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGFloat radians = atan2f(self.view.transform.b, self.view.transform.a);
if (radians!=M_PI*2) {
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI*2)];
}
}
}
Upvotes: 0
Reputation: 685
In your AppDelegate.m add this method :
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
This method determines which interface orientations are supported application wide , so if you return (UIInterfaceOrientationMaskLandscape) the app will work only in landscape mode regardless of the supported orientations in any content View Controller , and the supported orientations in any content View Controller should only be a subset of the supported ones in AppDelegate.m.
if you want the landscape orientation to be forced in one View Controller only , then in AppDelegate.m :
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
and in the Video VC :
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
and finally present the Video VC using :
[self presentViewController:videoVC animated:YES completion:nil];
Upvotes: 0
Reputation: 1003
You can do this in 2 possible way
2.) By programmatically
-(BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
This you need to do in you NavigationController
Class it looks you are using NavigationBar
.
If not then use it in your ViewController
Upvotes: 2