【问题标题】:Animating a 'Slide' iOS UIView but associated SubViews don't move为“幻灯片”iOS UIView 设置动画,但关联的子视图不移动
【发布时间】: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


【解决方案1】:

我对 Xamarin 不是很清楚。但是在objectiveC中,你可以使用,

view.clipsToBounds = YES;

因此,当您尝试降低高度时,子视图也会被隐藏。

【讨论】:

  • 成功了,我知道这很简单!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-10
  • 2012-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多