orientation is not working in ios 5 and it is work

2019-08-08 10:07发布

问题:

in my tabbar controller application i have many views. so i sub classed my tabbar controller like this.

   -(BOOL)shouldAutorotate
 {

   return [[self.viewControllers lastObject] shouldAutorotate];
  }

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

  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
   {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
   }

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation            { 
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (UIInterfaceOrientationMaskAll);


}

and in my view controller also

 - (BOOL)shouldAutorotate
{
return YES;
 }

 - (NSUInteger)supportedInterfaceOrientations
{
   return (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight);

//OR return (UIInterfaceOrientationMaskAll);
 }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation          {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (UIInterfaceOrientationMaskAll);



  }
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
 {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{

}
else
{

}
   }

my problem is orientation is working in ios 6 and not working in ios 5. thank you.

回答1:

You should write this function in every tab bar page

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation          {

return YES;

}

//use this only if needed

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

//your view changing code

}


回答2:

Add this code in your view controller, for ios 5

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return  UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortrait;

}