0

Hi how i can disable the autorotation for a view in a tabview controller??

i have testet to disable in a navigationclass, but thats not possible.

Thats my didFinishLaunching in the AppDelegate.m.

I hope everyone have an idea??

Thanks!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
// Set the application defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"YES"
                                                        forKey:@"myKeyName"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];

[self setupFetchedResultsController];

if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
    NSLog(@"!!!!! ~~> There's nothing in the database so defaults will be inserted");
    [self importCoreDataDefaultRoles];
    [self importCoreDataDefaultMaterials];
    [self importCoreDataDefaultPersons];
}
else {
    NSLog(@"There's stuff in the database so skipping the import of default data");
}

// TAB BAR
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

    NSLog(@"I'm an iPad");

    // *** Set up the Persons Split Views (2-Way Delegation & Pass Managed Object Context) *** //

    // Set up SPLIT VIEW for Persons
    UISplitViewController *splitViewController = [[tabBarController viewControllers] objectAtIndex:0];

    // Set up Split View MASTER view for Persons
    UINavigationController *personsMasterTVCnav = [splitViewController.viewControllers objectAtIndex:0];
    splitViewController.delegate = (id)personsMasterTVCnav.topViewController;
    PersonsTVC *personsTVC = [[personsMasterTVCnav viewControllers] objectAtIndex:0];
    personsTVC.managedObjectContext = self.managedObjectContext;

    // Set up Split View DETAIL view for Persons
    UINavigationController *personsDetailTVCnav = [splitViewController.viewControllers objectAtIndex:1];
    PersonDetailTVC *personDetailTVC = [personsDetailTVCnav.viewControllers objectAtIndex:0];

    // Set up MASTER and DETAIL delegation so we can send messages between views
    personsTVC.delegate = personDetailTVC;
    personDetailTVC.delegate = personsTVC;

    // *** Set up the Roles Views *** (Pass Managed Object Context)//
    UINavigationController *rolesTVCnav = [[tabBarController viewControllers] objectAtIndex:1];
    RolesTVC *rolesTVC = [[rolesTVCnav viewControllers] objectAtIndex:0];
    rolesTVC.managedObjectContext = self.managedObjectContext;

    // *** Set up the Materials Views *** (Pass Managed Object Context)//
    UINavigationController *materialsTVCnav = [[tabBarController viewControllers] objectAtIndex:2];
    MaterialsTVC *materialsTVC = [[materialsTVCnav viewControllers] objectAtIndex:0];
    materialsTVC.managedObjectContext = self.managedObjectContext;

    // Set delegate for splitViewController
    splitViewController.delegate = personDetailTVC;


}
else
{
    NSLog(@"I'm an iPhone or iPod Touch");

    // The Two Navigation Controllers attached to the Tab Bar (At Tab Bar Indexes 0 and 1)
    UINavigationController *personsTVCnav = [[tabBarController viewControllers] objectAtIndex:0];
    UINavigationController *rolesTVCnav = [[tabBarController viewControllers] objectAtIndex:1];
    UINavigationController *materialsTVCnav = [[tabBarController viewControllers] objectAtIndex:2];
    // The Persons Table View Controller (First Nav Controller Index 0)
    PersonsTVC *personsTVC = [[personsTVCnav viewControllers] objectAtIndex:0];
    personsTVC.managedObjectContext = self.managedObjectContext;


    // The Roles Table View Controller (Second Nav Controller Index 0)
    RolesTVC *rolesTVC = [[rolesTVCnav viewControllers] objectAtIndex:0];
    rolesTVC.managedObjectContext = self.managedObjectContext;

    // The Materials Table View Controller (Third Nav Controller Index 0)
    MaterialsTVC *materialsTVC = [[materialsTVCnav viewControllers] objectAtIndex:0];
    materialsTVC.managedObjectContext = self.managedObjectContext;
}

return YES;
}
  • Can you please explain further what you mean by "disable the autorotation for a view in a tableview controller"? Are you trying to disable a tableview controller from rotating its views while still supporting rotation in the rest of the app? – Aaron Chinault Jul 11 '14 at 20:28
  • Oh sorry, I like to disable the autorotation for a view in a tabview controller. All the other views need to rotate. – user3731232 Jul 11 '14 at 21:21

2 Answers2

1

Disabling entire UIViewController auto-rotation

A UIViewController embedded in a UITabBarController is relying upon that last controller to handle the -supportedInterfaceOrientations messages. It is not ; basically the same problem as in this post: iOS 6 rotations: supportedInterfaceOrientations doesn´t work?

You must subclass your UITabBarController, and add this code to query each tab:

// In UITabBarController subclass
- (BOOL)shouldAutorotate;
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController * top;
    UIViewController * tab = self.selectedViewController;
    if([tab isKindOfClass:
        ([UINavigationController class])]) {
        top = [((UINavigationController *)tab)
                 topViewController];
    }

    if ([top respondsToSelector:@selector(supportedInterfaceOrientations)])
        return [top supportedInterfaceOrientations];
    else
        return [super supportedInterfaceOrientations];
}

Of course, you must still respect the general auto-rotation rules and set the flags in the plist.

For each UIViewController subclass you want to prevent orientation changes, respond to supportedInterfaceOrientations as so:

// In UIViewController subclass
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
    // Or whatever orientation you support
}

See this post for further details: Handling autorotation for one view controller in iOS7

Community
  • 1
  • 1
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • Thanks for help, i have tested but that's not possible. – user3731232 Jul 12 '14 at 10:19
  • i have added this in the AppDelegate: -(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if ([[window.rootViewController presentedViewController] isKindOfClass:[UIViewController class]]) { return UIInterfaceOrientationMaskPortrait; } else { //return UIInterfaceOrientationMaskAllButUpsideDown; return UIInterfaceOrientationMaskPortrait; } } but now rotate no view. i like thats dont rotate only one view. – user3731232 Jul 12 '14 at 16:29
0

Rotating a UIViewController except one or more subviews

Use this method:

-(void)counterRotateView:(UIView *)view
    toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    duration:(NSTimeInterval)duration
{
    NSParameterAssert(view);

    CALayer* layer = view.layer;
    CABasicAnimation* animation;
    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    CGFloat tau = 0;
    switch (toInterfaceOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
            tau = 0.5; break;
        case UIInterfaceOrientationLandscapeRight:
            tau = -0.5; break;
        case UIInterfaceOrientationPortraitUpsideDown:
            tau = 1; break;
        case UIInterfaceOrientationPortrait:
        default:
            break;
    }
    animation.toValue = [NSNumber numberWithFloat:tau * M_PI];

    animation.duration = duration;
    animation.cumulative = YES;
    animation.repeatCount = 1;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;

    [layer addAnimation:animation forKey:@"transform.rotation.z"];
}

And invoke it from here:

-(void) willRotateToInterfaceOrientation:
    (UIInterfaceOrientation)toInterfaceOrientation
    duration:(NSTimeInterval)duration
{
    [self counterRotateView:someView
        toInterfaceOrientation:toInterfaceOrientation
        duration:duration];
}
Community
  • 1
  • 1
SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • where i need to implement this code? i have added this in my App Delegate but after this i become a error: Property 'backButton' not found on Object of type... if i implement this in my InfoVC.m same error. – user3731232 Jul 12 '14 at 17:02
  • ca you look over teamviewer please? i think that's easier. – user3731232 Jul 12 '14 at 17:08