2
votes

I am making an app which would be in both modes portrait as well as landscape. For iOS 5.0 I am adding views by following way i.e.

 -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation

{
   if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
    productname.frame=CGRectMake(240, 97, 106, 20);
            self.view = landscapeView;

}

else if

(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
          (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
    productname.frame=CGRectMake(153, 151, 106, 20);

    self.view = portraitView;

}

   return YES;

}

But for iOS 6.0 I got following two methods for orientation,

  • (NSUInteger)supportedInterfaceOrientations
  • (BOOL)shouldAutorotate

I actually need a method which must fire during rotation of device. If anyone has an idea please let me know. I already wasted alot of time on it.

Thanks a lot in advance.

2
I don't believe there is any method called during the rotation; only before and after.trojanfoe
Then what should I do for rotation. How the views will be change during rotation?Sudha Tiwari
What you have to do is in your root view controller (which does get notified) place a method that invokes the "rotate yourself" method in the top view controller. Really ugly, but apparently Apple wants to coerce people to use autolayout.Hot Licks

2 Answers

1
votes

I'm using UINavigationController subclass with following code:

    - (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if (self.topViewController.presentedViewController) {
        return self.topViewController.presentedViewController.supportedInterfaceOrientations;
    }
    return self.topViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.topViewController.preferredInterfaceOrientationForPresentation;
}

and it's work perfect for me

and in AppDelegate.m file:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [UIDevice isIpad] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
0
votes

use

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration