【发布时间】:2013-04-19 15:23:22
【问题描述】:
我认为来自 UINavigationBar 的简单 UIView 幻灯片动画有问题。我有一个带有 UIButton 的 UIView,我想模拟一张幻灯片 通过动画视图高度从导航栏向下/向上效果。问题是视图动画,但任何子视图,例如UIButton 保持固定。
我正在使用 Xamarin (C#) 进行编码,但我确信它对于 Objective-C 编码人员来说足够简单
if (_menuView == null)
{
// set initial frame
_menuView = new MenuView{Frame = Window.Frame};
// store original "expanded" height for later
_expandedMenuHeight = _menuView.Frame.Height;
// set the frame to underneath the NavigationBar
var frame = ((UINavigationController)Window.RootViewController).NavigationBar.Frame;
var y = frame.Bottom;
// Add to Window View
menuView.Frame = new RectangleF(_menuView.Frame.X,y,_menuView.Frame.Width,0);
Window.Add(_menuView);
}
// Toggle View Height - if collapsed, expand, if expanded, collapse
var height = _menuView.Frame.Height == 0 ? _expandedMenuHeight : 0;
// Animate the height
UIView.Transition (_menuView,0.2,UIViewAnimationOptions.CurveEaseIn | UIViewAnimationOptions.LayoutSubviews,() => {
_menuView.Frame = new RectangleF(0,_menuView.Frame.Y,_menuView.Frame.Width,height); },null);
非常感谢任何指针!
【问题讨论】:
-
您可能只需要在相关视图上设置 autoresizesSubviews ......不幸的是,我不知道您将如何在 Xamarin 中执行此操作。在可可中,它是微不足道的:view.autoresizesSubviews = YES。
-
谢谢大卫,最后是 view.clipsToBounds = YES;完成了这项工作。顺便说一句 - 我也有 view.autoresizesSubviews = YES 以防其他人正在看同样的东西。
标签: ios xamarin.ios uiviewanimation