我对来自 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);
任何指针都非常感谢!