-1

每当用户点击我的应用程序栏上的按钮时,我希望一个窗口从侧面滑入。
我希望那个“窗口”是半透明的,并且像其他实际用作按钮、UILabels 和文本字段的图像一样具有控件。
什么是这样做的好方法?

4

2 回答 2

1

我不确定我是否理解您所说的“并且具有像其他实际用作按钮、UILabels 和文本字段的图像一样的控件”,但我会试一试。

带有控件的半透明窗口应该是这样的:

  • UIView - backgroundColor = clearColor [父视图]
    • UIView - alpha = 0.5 [透明视图]
    • 控件 - 按钮、标签等

基本上,这种布局会给你一个透明的背景视图和可见的控件。只需确保您的控件与透明视图具有相同的父级 [父级视图] 。

要滑入/滑出,您可以使用:

[UIView beginAnimations:nil context:nil]
[UIView setAnimationDuration:0.3];

// move the parent view here

[UIView commitAnimations];

祝你好运 !

于 2012-05-25T07:38:58.813 回答
1

如果我对你的理解正确,你可以通过简单地实现你想要的:

  • 创建你的主视图控制器
  • 创建单独的 UIView 或 UIViewController 并设置其 frame.origin 参数以将其隐藏在 left/right/top/bottom

以 DarkByte 简要解释的方式管理透明度。[例如slidingView.alpha = 0.5;]

要为“滑动”设置动画,我宁愿使用:

[UIView animateWithDuration:animationDuration 
                      delay:wait
                    options: UIViewAnimationCurveEaseOut
                 animations:^{
                     /*Parameter changing code goes heare, for example: */ 
                     view.frame.origin.x = newX; 
                 } 
                 completion:^(BOOL finished){
                     /*Code which will be executed AFTER the animation goes heare*/
                 }];    

我认为它很容易使用,并且设置动画后要执行的代码非常方便。

于 2012-05-25T09:09:30.860 回答