开发者

How implement splitview for iphone os 4.2?

开发者 https://www.devze.com 2023-01-24 12:43 出处:网络
I have use the custom splitview in the my application. custom splitview .h file @interface CustomUISplitViewController :UISplitViewController {

I have use the custom splitview in the my application.

custom splitview .h file

@interface CustomUISplitViewController :UISplitViewController {

BOOL keepMasterInPortraitMode;
BOOL  keepMasterInPortraitMode1;
 }

and .m file is

-(void) viewWillAppear:(BOOL)animated {

    keepMasterInPortraitMode1=keepMasterInPortraitMode;
    if(keepMasterInPortraitMode1 == NO) {
        if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            UIViewController* master = [self.viewControllers objectAtIndex:0];
            UIViewController* detail = [self.viewControllers objectAtIndex:1];
            [self setupPortraitMode:master detail:detail];      
        }
    }

    if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        UIViewController* master = [self.viewControllers objectAtIndex:0];
        UIViewController* detail = [self.viewControllers objectAtIndex:1];
        [self setupPortraitMode:master detail:detail];
      } 
     }
}

 - (void)setupPortraitMode:(UIViewController*)master detail:(UIViewController*)detail {
    //adjust master view
    CGRect f = master.view.frame;
    f.size.width = 220;
    f.size.height = 1024;
    f.origin.x = 0;
    f.origin.y 开发者_JS百科=0;

    [master.view setFrame:f];

    //adjust detail view
    f = detail.view.frame;
    f.size.width = 548;
    f.size.height = 1024;
    f.origin.x = 221;
    f.origin.y = 0;

    [detail.view setFrame:f];
}

This works correctly under iOS4.0 but under 4.2 I see only one view when the app runs. What could change between OS versions?


I was having the same issue and I believe this to be an Apple bug (I filed it a month ago with no response from them.) For me, it was specifically the "detail" view that was blank when the app started at orientation UIInterfaceOrientationLandscapeRight (3). It would look like this: http://d.pr/cGcU. This would occur when I restricted one of the two view controllers (say, the RootViewController) to landscape-only:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

With this in place, the following would occur during the detail view's initialization:

2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] firstDetailViewController willAnimateRotationToInterfaceOrientation: 3 (landscape)
2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] self.view.hidden is: 0
2010-11-15 20:17:47.799 MultipleDetailViews[96250:207] rotating...
2010-11-15 20:17:47.848 MultipleDetailViews[96250:207] firstDetailViewController didRotateFromInterfaceOrientation
2010-11-15 20:17:47.849 MultipleDetailViews[96250:207] self.view.hidden is: 1

For some reason the detail view would mysteriously become hidden during rotation to orientation 3. Until Apple fixes this bug (it doesn't occur in 3.2), my workaround is currently to override the following method in the detail view controller, re-displaying the view after rotation has completed:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    self.view.hidden = NO;
}

EDIT: If your detail view isn't a direct subview of splitViewController.view (e.g. you are using a UINavigationController), you will need to set hidden on the topmost view on the detail side within the UISplitViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    // Make sure you set splitViewController via an outlet or get it via your AppDelegate
    for (UIView *splitViewChild in splitViewController.view.subviews)
        splitViewChild.hidden = NO;
}


I have had the exact same problem with my applications. I had used the same Subclassing technique to have the Master and Detail visible in both Portrait and Landscape modes. Worked great until 4.2 which, unfortunately I didn't test for when the Beta releases were available.

I recommend trying the excellent MGSplitViewController (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad). It is an open-source implementation of the UISplitViewController. It's only drawback is that it isn't quite as easy to use in Interface Builder, but it includes a sample project. Visually it is identical to UISplitViewController, but adds support for several extras such as dragging the split position at runtime.

Just implement it exactly as your UISplitViewController but add the following line somewhere:

[splitViewController setShowsMasterInPortrait:YES];

This is very similar to the Private API that Apple prohibits using with their version.

//[splitViewController setHidesMasterViewInPortrait:NO];  // Naughty, Naughty, Not allowed by the Apple police
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号