开发者

Using a tint on a split view controller's master pane

I have a navigation controller in the master pane of a split view controller. It has a tint set on the navigation bar. When this navigation controller is displayed in the split view's popover, the popover does not show the navigation items in the black popover-style but instead the layout is kind of screwed up and it uses the tint that was set before:

The tint:

alt text http://img6.imageshack.us/img6/2650/tint.png

When displayed in the popover:

alt text http://img707.imageshack.us/img707/9725/screwedup.png

I tried handling willPresentViewController etc. to clear the tint before displaying in the popover, and restoring th开发者_Go百科e tint when going back. This almost works but when transitioning back to landscape mode the standard iPad tint is visible during the animation before changing back, and the tint on some of the navigation items is not set back correctly:

Clearing the tint before showing the popover works:

alt text http://img38.imageshack.us/img38/3237/betterfq.png

But on the way back the buttons are left in an inconsistent state:

alt text http://img802.imageshack.us/img802/1937/inconsistent.png

Calling setNeedsDisplay etc. does not work.

Surely there's an easier way?

EDIT:

Apple has responded and this is a bug, filed as 8276014 on bugreport.apple.com. It should be fixed in 4.2 (from beta 2 onwards).


I think that you've found a very obscure bug in the SDK :) - You should file a bug report with Apple

I build a test app and got it to reproduce your problem :

  • Create a split pane project
  • Set the tint of the toolbar in the master pane (in DetailView) (to red)
  • Set the tint of the navigation item (to blue)
  • Add a few bar button items to check that the layout was OK
  • Ran the app

This showed the layout being wrong (as in your screenshots above)

Then I build another and it was absolutely fine :( The only difference between creating these apps was me not ever setting the tint of the navigation item in the popup view.

I tried setting the tint of the navigation item in my original project back to 'default' to see what happened and the layout bug was still there so whatever setting the tint does is irriversible as far as I can see.

I'd get in touch with Apple :)

Sam

PS I know this isn't really an answer but it's the best I have - I'm going to keep playing with it to see what's going on :)


OK, I've had a play around and can see what's happening - even though I'm not 100% sure I understand it.

I used git to take a snapshot of my working second project (the one with a tint on the master view toolbar but a working layout on the popup).

Then I broke it by setting the tint on the popup's navigation bar.

Then, I ran git diff and the only changes were (in my MainWindow.xib file)

    <bool key="IBUIClipsSubviews">YES</bool>
    <bool key="IBUIMultipleTouchEnabled">YES</bool>
    <string key="targetRuntimeIdentifier">IBIPadFramework</string>
+     <object class="NSColor" key="IBUITintColor">
+      <int key="NSColorSpace">1</int>
+      <bytes key="NSRGB">MSAwLjg4NTI1MDE4NjEgMC42NDExMjQ4OTI1AA</bytes>
+     </object>
    </object>

This is the new tint color added to the definition of my navigation controller and is what's breaking the layout.

I then went into interface builder an set the style of my popup's navigation bar to be 'Default' - the tint went back to default and when I ran the app it was fixed again.

Sure enough, when I did another git diff I found that the lines added above had been removed.

I then tried playing with the styles - I set the style to be 'Black Opaque' and ran the app - it stoll worked fine. This is because setting the style doesn't set a black tint, instead it adds this line to the xib :

+   <int key="IBUIBarStyle">1</int>

This tells me that you could either fix it by either

1) setting the style in interface builder

2) edit your xib file by hand to remove the lines that specify the tint

3) Setting the barStyle property in your code (but I'm not 100% sure this one would work)

Hope that's helpful, thank's for a challenge,

Sam


my last answer was completely on the wrong track!

This code removes the tint after a rotation to a portrait mode and sets the tint before a rotation to a landscape mode :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:orientation duration:duration];

    if (orientation == UIInterfaceOrientationLandscapeLeft ||
        orientation == UIInterfaceOrientationLandscapeRight) {
        [bar setTintColor:[UIColor redColor]];  
    }
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIInterfaceOrientationPortrait ||
        orientation == UIInterfaceOrientationPortraitUpsideDown) {
        [bar setTintColor:nil];
    } 
}

This is in the main view controller (the one that contains the split pane view) and shows a red bar in landscape and a correctly formatted black one in portrait modes.

You say that you've tried it in the willPresentViewController and it didnt work - this seems to work for me putting it in these two methods.


As it turns out, this was a bug that was confirmed by apple (8276014 on bugreport.apple.com) and fixed in iOS 4.2. I was never able to find any acceptable workarounds.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜