我实现了一个自定义的分割视图控制器,它原则上工作得很好。然而UIToolbar的动画调整大小在iOS上剪裁背景<5.1
还有就是,做不工作预计一个方面,这是iOS上的工具栏5.1版本之前的调整大小的动画 - 如果存在的话:
继承后UIToolbar覆盖其layoutSubviews
方法,动画更改我的主要内容区域的宽度会导致工具栏项目按预期移动。工具栏的背景 - 但是 - 如预期的那样,不是动画。
相反,其宽度会立即更改为新值,导致在增加宽度时显示背景。
这里是什么,我认为我使用的代码的相关部分 - 都相当标准的东西,如小魔/两轮牛车地:
// From the implementation of my Split Layout View Class:
- (void)setAuxiliaryViewHidden:(BOOL)hide animated:(BOOL)animated completion:(void (^)(BOOL isFinished))completion
{
auxiliaryViewHidden_ = hide;
if (!animated)
{
[self layoutSubviews];
if (completion)
completion(YES);
return;
}
// I've tried it with and without UIViewAnimationOptionsLayoutSubviews -- didn't change anything...
UIViewAnimationOptions easedRelayoutStartingFromCurrentState = UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState;
[UIView animateWithDuration:M_1_PI delay:0.0 options:easedRelayoutStartingFromCurrentState animations:^{
[self layoutSubviews];
} completion:completion];
}
- (void)layoutSubviews
{
[super layoutSubviews];
// tedious layout work to calculate the frames for the main- and auxiliary-content views
self.mainContentView.frame = mainContentFrame; // <= This currently has the toolbar, but...
self.auxiliaryContentView.frame = auxiliaryContentFrame; // ...this one could contain one, as well.
}
// The complete implementation of my UIToolbar class:
@implementation AnimatableToolbar
static CGFloat sThresholdSelectorMargin = 30.;
- (void)layoutSubviews
{
[super layoutSubviews];
// walk the subviews looking for the views that represent toolbar items
for (UIView *subview in self.subviews)
{
NSString *className = NSStringFromClass([subview class]);
if (![className hasPrefix:@"UIToolbar"]) // not a toolbar item view
continue;
if (![subview isKindOfClass:[UIControl class]]) // some other private class we don't want to f**k around with…
continue;
CGRect frame = [subview frame];
BOOL isLeftmostItem = frame.origin.x <= sThresholdSelectorMargin;
if (isLeftmostItem)
{
subview.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
continue;
}
BOOL isRightmostItem = (CGRectGetMaxX(self.bounds) - CGRectGetMaxX(frame)) <= sThresholdSelectorMargin;
if (!isRightmostItem)
{
subview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
continue;
}
subview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
}
}
@end
我已经设置了类工具栏的InterfaceBuilder下和我知道一个事实,就是这个代码被调用,就像我说的,在iOS 5.1上,一切正常。
我不得不开始支持4.2版本的iOS,但...
任何帮助/提示为我缺少什么,我都非常感谢。
拍摄,我忘记评论布局子视图:我正在布局我的工具栏项目视图,否则 - 不会顺利地生成动画,但也跳到他们的新位置。 – danyowdee 2012-05-18 06:36:07
我不确定我完全理解您的评论,对不起...我的提示帮助? – sergio 2012-05-18 08:16:16
我的'layoutSubviews'不是用来移动工具栏的_background_。它只是减轻了设置工具栏框架时的问题 - 即使在UIViewAnimation(块)内 - 工具栏项目也会跳转到它们的新位置。在iOS <5.1中插入一个静态渲染的图像作为子视图将是一个有点可接受的解决方法,尽管我希望这个解决方案不那么黑客。 – danyowdee 2012-05-18 10:01:45