简体   繁体   English

动画“幻灯片”iOS UIView但关联的子视图不会移动

[英]Animating a 'Slide' iOS UIView but associated SubViews don't move

I'm having a problem with what I thought was a simple UIView slide animation from a UINavigationBar. 我遇到的问题是我认为是UINavigationBar的简单UIView幻灯片动画。 I have a UIView with a UIButton and I would like to simulate a slide down/up effect from the Navigation Bar by animating the View height. 我有一个带有UIButton的UIView,我想通过设置View高度来模拟导航栏中的向下滑动效果。 The problem is the View animates but any SubViews eg UIButton stay fixed. 问题是查看动画,但任何子视图,例如UIButton保持固定。

I'm coding in Xamarin (C#) but I'm sure it's simple enough to read for Objective-C coders 我在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);

Any pointers are greatly appreciated! 任何指针都非常感谢!

UIView和子SubViews没有动画

I am not so clear with Xamarin. 我对Xamarin不太清楚。 But in objectiveC, you could use, 但是在objectiveC中,你可以使用,

view.clipsToBounds = YES;

So when you are trying to reduce the height the subviews would also be hidden. 因此,当您尝试降低高度时,子视图也会被隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM