0

hey guys i have seen many similar question but could not reach to any solution. I am creating an universal app using storyboard and having a navigation controller which is having root view controller v1, so initially top view controller is v1. And on clicking a button on v1 it push view controller v2. Now i want that app should rotate in all direction for all view controllers except view controller v2. I have checked all device directions in deployment info and also tried to create category of uinavigationcontroller

#import <UIKit/UIKit.h>

@interface UINavigationController (autorotation)
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end

#import "UINavigationController+autorotation.h"
#import "AboutViewController.h"

@implementation UINavigationController (autorotation)

-(NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
{
   return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

MY problem is that app is rotating for all screens but i want to stop rotation for view controller v2 as described above. I really have my two days please help me

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Archive
  • 249
  • 4
  • 14
  • this [link](http://stackoverflow.com/questions/19422373/how-to-set-one-of-the-screens-in-landscape-mode-in-iphone) will be helpful to you as I tested it and it worked. Don't forget to vote up and ticking my answer! – nikhil84 May 07 '14 at 10:30

2 Answers2

0
- (BOOL)shouldAutorotate
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[v2 class]])
        return NO;

    return YES;
}

//add this method in your code and tell me its work or not.

Rushabh
  • 3,208
  • 5
  • 28
  • 51
  • Rushabh thanks for fast reply, I have already written this method in v1 as well as in v2. still not working – Archive May 07 '14 at 09:23
  • Rushabh, one more question when and how many times this method should be called? Sorry for silly question – Archive May 07 '14 at 09:31
0

This is a useful link i used once it does the oposit of what you asked but still, you can use it.

Another way will be to put this in your view that you don`t want to rotate

- (BOOL) shouldAutorotate {
return NO; }

Don't forget to rotate the view to appropriate InterfaceOrientation, something like this

[self willAnimateRotationToInterfaceOrientation:1 duration:1];

you can put this in viewWillApear;

sken3r.MI
  • 478
  • 3
  • 11