Using only the landscape in lens C?

I have a video application, but I would like it to remain only in landscape orientation.

When in a landscape it looks like this:

enter image description here

But when I turn around, he selects the portrait orientation and looks like this:

enter image description here

he would have stayed only in landscape orientation, had already tried and tried many things that I saw, and nothing worked, did someone help me?

[UPDATE]

You only need the view not to use the PORTRAIT orientation, did someone already have this problem?

Does anyone have any other ideas? nothing worked here

[UPDATE] → 09/30/2015

my decision:

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 a landscape, I used it (videoViewController.m):

in viewDidLoad

[self restrictRotation:YES];

        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

and add a method:

-(void) restrictRotation:(BOOL) restriction
{
    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    appDelegate.restrictRotation = restriction;
}

remember if #import "AppDelegate.h" in videoViewController.h

, , :

in viewDidLoad:

[self restrictRotation:YES];

:

-(void) restrictRotation:(BOOL) restriction
    {
        AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
        appDelegate.restrictRotation = restriction;
    }

! all

+4
3

.

1.) enter image description here

2.)

-(BOOL)shouldAutorotate{
return YES;

}
-(NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
}

NavigationController , , -, NavigationBar.

, ViewController

+2

/ , .

, .

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)];

    }
}

, .

- (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)];
    }

}

}

0

AppDelegate.m :

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskLandscape;
}

, , , (UIInterfaceOrientationMaskLandscape), . AppDelegate.m.

, , AppDelegate.m:

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return UIInterfaceOrientationMaskAll;
}

Video VC:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

, , VC, :

[self presentViewController:videoVC animated:YES completion:nil];
0

Source: https://habr.com/ru/post/1609459/


All Articles