【问题标题】:slide view from top从顶部滑动视图
【发布时间】:2014-04-12 20:24:22
【问题描述】:

有谁知道我如何单击按钮并从顶部显示面板?

类似于 YouTube 应用在您点击搜索按钮后显示搜索栏的方式。

不确定如何从顶部滑入视图并显示在视图上方。

有什么想法吗?

【问题讨论】:

  • 您需要提供更多信息。您希望菜单如何向下滑动?如果它带有手势,我个人会避免使用这种类型的 UI,因为 Apple 的通知中心会从顶部滑落 - 所以这可能与您的设计冲突。

标签: ios button view


【解决方案1】:

在您的视图中确实 load 将滑动视图的原点 y 值设置为负值(使其刚好离开屏幕顶部)。

然后,当您希望它出现时,将 y 值设置为 0,您可以使用 UIView:animateWithDuration 对动画进行此操作。

如果您愿意,它会出现一个,您可以添加一个平移手势识别器,以便用户可以向上滑动它,或者您可以通过编程触发它向后移动。

【讨论】:

    【解决方案2】:

    做了这样的事情,它似乎可以工作,但在几次点击开始工作后首次启动时并不像我预期的那么顺利

    if (showBanner == false) {
    
         showBanner = true;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
        [UIButton beginAnimations:nil context:nil];
        [UIButton setAnimationDuration:0.5];
        [UIButton setAnimationDelay:0.0];
        [UIButton setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
        scrollView.frame = CGRectMake(0, 0, 320, 100);
        openMenu.frame = CGRectMake(267,101, 47, 30);
    
        [self.view bringSubviewToFront:scrollView];
        [UIView commitAnimations];
    
    }
    else{
    
         showBanner = false;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
        [UIButton beginAnimations:nil context:nil];
        [UIButton setAnimationDuration:0.5];
        [UIButton setAnimationDelay:0.0];
        [UIButton setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
        scrollView.frame = CGRectMake(0, -100, 320, 100);
        openMenu.frame = CGRectMake(262, 20, 47, 30);
    
        [UIView commitAnimations];
    
    }
    

    任何想法为什么这对前几次点击不起作用?

    【讨论】:

      猜你喜欢
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-22
      • 2011-12-08
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多