iphone - resize toolbar in UINavigationController -
i'm adding series of buttons uinavigationbar using:
nsarray *items; items = [nsarray arraywithobjects: fixedspace, refreshstopbarbuttonitem, flexiblespace, self.backbarbuttonitem, flexiblespace, self.forwardbarbuttonitem, flexiblespace, self.actionbarbuttonitem, fixedspace, nil]; uitoolbar *toolbar = [[uitoolbar alloc] initwithframe:cgrectmake(0.0f, 0.0f, toolbarwidth, 44.0f)]; toolbar.items = items; toolbar.tintcolor = [[uicolor whitecolor] colorwithalphacomponent:1.0]; toolbar.autoresizingmask = uiviewautoresizingflexibleheight; self.navigationitem.rightbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:toolbar];
all working well.
however when rotate landscape mode toolbar within uinavigationbar doesn't rotate.
adding code (found on so) causes toolbar resize not buttons within it, partially cropped @ bottom , no longer lines toolbar background
- (void)willanimaterotationtointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration { cgrect navigationtoolbarframe = self.navigationcontroller.navigationbar.frame; cgrect customtoolbarframe = cgrectoffset(navigationtoolbarframe, 0.0, navigationtoolbarframe.size.height); [uiview animatewithduration:duration animations:^{ //self.toolbar.frame = customtoolbarframe; // fails!!! //self.navigationitem.rightbarbuttonitem.toolbar.frame = customtoolbarframe; // fails!!! }]; }
what correct way address toolbar within uinavigationbar? like...
self.toolbar.frame = customtoolbarframe;
or have specify autoresizemask uibarbuttonitems?...
self.backbarbuttonitem.autoresizingmask = uiviewautoresizingflexibleheight;
... trying fails
very curious because code rotates toolbar fine when include in code. no problem rotating toolbar.
i assume view controller responding
shouldautorotatetointerfaceorientation
? include screen snapshot of you're seeing?are doing
uitoolbar
category/subclass eliminate border? (i subclass empty(void)drawrect:(cgrect)rect
rid of border, tried both , standarduitoolbar
, both rotated fine.) anyway, if you're doing subclass/category ofuitoolbar
, please include code?also, alternatively use ios 5's
rightbarbuttonitems
, bypass toolbar altogether, e.g.self.navigationitem.rightbarbuttonitems = items;
add array of uibarbuttonitem objects navigation bar.this bit of long shot, how view controller being loaded? people try bypassing
presentviewcontrolleranimated
and/orpushviewcontroller
, instead create view controller, grab view, add subview of previous view controller's view. unfortunately, ends disconnect between view controller hierarchy , view hierarchy, , according wwdc 2011 session 102 on view controller containment, can prevent rotation events being transmitted correctly. make sure you're usingpresentviewcontrolleranimated
orpushviewcontroller
if isn't root view controller.
i don't of willanimaterotationtointerfaceorientation
or subsequent code, simple uitoolbar , works fine during rotation, wonder if problem rests elsewhere.
Comments
Post a Comment