6

enter image description hereI have created category for view rotation, And added views on controllers view as well as on window(for showing custom indicator). My code is working fine up to 7.X with xCode 5.X as well as xCode6-beta6. But is not proper with IOS 8 beta. Its seems like windows rotation is not working with ios 8 beta same like older ios.

Can you please suggest me.... Thanks a lot in advance.

My code is look like

- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
 if(!self.isIpad)
{

    [menu.view rotateViewToOrientation:newStatusBarOrientation animated:YES];
    if(newStatusBarOrientation==UIInterfaceOrientationPortrait || newStatusBarOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(0, 518, 320, 50);
        } else {
            menu.view.frame= CGRectMake(0, 430, 320, 50);
        }

    }  else if(newStatusBarOrientation==UIInterfaceOrientationLandscapeLeft) {

        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(270,0,50,568);
        } else {
            menu.view.frame= CGRectMake(270,0,50,480);
        }

    } else {

        if (IS_IPHONE_5) {
            menu.view.frame= CGRectMake(0,0,50,568);
        } else {
            menu.view.frame= CGRectMake(0,0,50,480);
        }
    }
    [menu reloadMenu];
  }
}


//Method of Menu Class for orientation change setup
- (void)rotateViewToOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
CGPoint center = self.center;
CGRect bounds = self.bounds;
CGAffineTransform transform = CGAffineTransformIdentity;
int intOri=orientation;
switch (intOri) {
    case UIInterfaceOrientationPortraitUpsideDown:
        transform = CGAffineTransformMakeRotation(M_PI);
        break;
    case UIInterfaceOrientationLandscapeLeft:
        transform = CGAffineTransformMakeRotation(-M_PI_2);
        break;
    case UIInterfaceOrientationLandscapeRight:
        transform = CGAffineTransformMakeRotation(M_PI_2);
        break;
    case UIInterfaceOrientationPortrait:
        transform = CGAffineTransformMakeRotation(0);
        break;

}
if (animated) {
    [UIView beginAnimations:nil context:nil];
}
self.transform = transform;
bounds = CGRectApplyAffineTransform(bounds, transform);
self.bounds = CGRectMake(0, 0, bounds.size.width, bounds.size.height);
self.center = center;
 if (animated) {
    [UIView commitAnimations];
 }
}
Kanjariya-IOS
  • 652
  • 1
  • 5
  • 17
  • paste some code and show how you getting problem, is there any function is not calling or any things else?? – Jageen Sep 05 '14 at 11:42
  • in general most of the developer has no idea how a proper view hierarchy should be built up, and that can be the origin of the problem – could you post some code about how you build up yours? – holex Sep 05 '14 at 11:54
  • @Jageen I have added my code, Can you please suggest me any way, What should i follow to make my application ios 8 compatible. – Kanjariya-IOS Sep 05 '14 at 12:21
  • @AshwinKanjariya, I'm not seeing why you need to handle the frame of the view manually. have you heard about the _auto layout_ or _auto resize-masks_? I recommend you to learn about them as soon as you just can humanly. – holex Sep 05 '14 at 12:51
  • @holex Actually its too old code (since IOS 3.X), Around 4 Years. And application is big enough, So I can't go with auto layout or even auto resize-masks for each classes. Hope you can understands. I just want to fix view related issue to support IOS 8. – Kanjariya-IOS Sep 05 '14 at 12:59
  • @AshwinKanjariya, that makes sense, but the regular yearly maintenance should have covered the updates between each major iOS versions and each architectures – but I'm not sure about other developers' update policies, my personal experience is that the app usually collapses if that step is missing. – holex Sep 05 '14 at 13:20
  • @holex, Thanks for your suggestion, But on this application more then 15 developer had worked and moved, Now I'm the one who have to make it IOS-8 compatible. To me it seems that issue related window rotation.. as while i'm adding "Loding..." view to window is also not reflected proper... Can you suggest a better way please. Thanks for all your support and waiting for better solution. :) – Kanjariya-IOS Sep 06 '14 at 04:44

3 Answers3

7

I have tried a lot of fixes... and its working with patch like

{
[self.window setBounds:temp];
[menu.view setFrame:CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50)];
[menu.view removeFromSuperview];
[self.window addSubview:menu.view];
[self.window makeKeyAndVisible];
}

and reseting angle to 0 degree for CGAffineTransformMakeRotation for all kind of device mode., for ios 8.

This is not a proper solution i know, but I don't have any alternate way so waiting for a good answer.

Kanjariya-IOS
  • 652
  • 1
  • 5
  • 17
4

In my case, simply setting the rotation angle to 0 for all orientations fixed the problem. Prior to iOS 8 UIWindow coordinates were always in Portrait orientation, so you had to handle rotation yourself. This is no longer necessary in iOS 8. As to why you would be adding UIViews to a UIWindow, I do this for alerts that I want to display on top of everything else regardless of current view hierarchy.

user1055568
  • 1,349
  • 13
  • 21
1

Had similar problem. Surprisingly the fix was to comment out all the code related to self.window on Appdelegate.

Commented initialising of self.window and its assignment. Set the initial view in storyboard in Attributes inspector by checking "Is Initial View Controller" checkbox.

New Better Solution
Commenting self.window was causing other issues. Instead the below code is best:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification 
    {
         [UIViewController attemptRotationToDeviceOrientation];
    }
Mitech
  • 400
  • 4
  • 6