10

I am using MGSplitViewController library in my app. Till iOS7 it works fine but for iOS8 it is not working as expected because of the change of behaviour of UIPopoverController in iOS8. Attached is the screenshot of running MGSplitView code on iOS8 :

iOS 8 MGSplitView

which is showing the wrong behaviour. It is supposed to be like the following screenshot : enter image description here

I have read somewhere that MGSplitViewController library will not be updated for iOS8 fixes.Does anyone know if we have another library which works fine for iOS8 as well and has similar features as of MGSplitViewController.

XYZ
  • 597
  • 1
  • 7
  • 19

2 Answers2

17

I faced the same issue and found a fix for it. Go to MGSplitViewController.m and find the following lines in -splitViewSizeForOrientation: (around line 261):

width = height;
height = fullScreenRect.size.width;

Make sure it does not run on iOS 8, as iOS 8 will handle sizes properly. Maybe like this.

if (SYSTEM_VERSION_LESS_THAN(@"8.0") && UIInterfaceOrientationIsLandscape(theOrientation)) {
    width = height;
    height = fullScreenRect.size.width;
}

Then find the following line in -reconfigureForMasterInPopover: (around line 614):

[_hiddenPopoverController presentPopoverFromRect:CGRectMake(-2000, -2000, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

And make sure it does not run on iOS 8. Again, maybe like this.

if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
    [_hiddenPopoverController presentPopoverFromRect:CGRectMake(-2000, -2000, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
simonbs
  • 7,932
  • 13
  • 69
  • 115
  • Thanks, this worked for me. For others, I used 'DeviceSystemMajorVersion() < 8' for the iOS version check. – Wade Sep 25 '14 at 18:08
  • I also fixed it using the same changes. I was about to add this to the answers. – XYZ Sep 30 '14 at 13:22
  • @XYZ Then please consider marking my answer as correct to make it easier to find the right solution for other people who may stumble upon this question when experiencing the same issue. – simonbs Sep 30 '14 at 19:12
  • 1
    This thread contains the `SYSTEM_VERSION_LESS_THAN` macro used above: http://stackoverflow.com/a/5337804/1415397 – mwoods Nov 05 '14 at 20:13
  • I needed to make one addition to the code above to get it to work because I ended up with a narrow black / white bar at the bottom of the split view. I needed to surround the `height -= statusBarHeight;` line at the end of `splitViewSizeForOrientation:` with the `SYSTEM_VERSION_LESS_THAN(@"8.0")` check to make it disappear. – mwoods Nov 05 '14 at 20:20
  • you should provide your comments to author of MGSplitViewController on github [link](https://github.com/mattgemmell/MGSplitViewController) – Aston Jan 27 '15 at 16:16
-1

I've modified the MGSplitViewController to deal with issues in the past so this may not solve your problem entirely as other fixes in my copy of the controller could be contributing to the solution.

The problem is that the UIPopoverViewController (used for _hiddenPopoverViewController in the MGSplitViewController) is calling [view removeFromSuperview] on the masterViewController AFTER willAnimateRotationToInterfaceOrientation is called. My current fix to get my app functional again is to alter [MGSplitViewController didRotateFromInterfaceOrientation:] as follows:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
 {
    [self.masterViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [self.detailViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    if([[[UIDevice currentDevice] systemVersion] hasPrefix:@"8"])        {
        [self layoutSubviewsForInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation withAnimation:YES];
    }
}

Unfortunately the masterViewController view is added to the MGSplitViewController view AFTER the rotation so it looks a bit 'clunky', but it does at least work.

Red Nightingale
  • 669
  • 3
  • 19