Fellowsoft
Fellowsoft

Reputation: 340

UIView transitions with wrong orientation

I have this code (Book1 is a UIViewController Class)

Book1 *book = [self.storyboard instantiateViewControllerWithIdentifier:@"Book1ID"];    
[UIView transitionFromView:self.view toView:book.view duration:1 options:UIViewAnimationOptionTransitionCurlDown completion:nil];

The ViewController loads but it the orientation is wrong. It loads in Portrait view but I want it to load in Landscape.

I have the following code in Book1 already but once the view is loaded all autorotation seems to fail.

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}

How can I load this view in Landscape?

Upvotes: 0

Views: 1583

Answers (2)

Fellowsoft
Fellowsoft

Reputation: 340

I haven't found the problem with my previous methods but I found another way to do it.

This is how:

book = [self.storyboard instantiateViewControllerWithIdentifier:@"Book1ID"];
book.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:book animated:YES completion:^(void){}];

Special thanks to Aalok Parikh for all your help

Upvotes: 2

The iOSDev
The iOSDev

Reputation: 5267

So Do the things like the below:

First

Supported Device Orientations

Just Select those two orientations as supported device orientations :)

Second

plist file key entry

Now Add the key The Last one in image Initial interface orientation and the value you want either of two landscape values from the list

Third

Now add the below function to all your controller's .m file

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Forth

Just build and run your project :)

That's it now your application is restricted to the landscape mode only

Happy Codding:)

Upvotes: 0

Related Questions