如何从底部绘制View Controller

时间:2014-07-18 15:32:24

标签: ios objective-c uiviewcontroller

我正在尝试在Xcode中开发一个应用程序。我是Objective C编程的新手,但到目前为止,我做得很好。今天我遇到了第一个问题。我试图从下往上画一个透明的VC(视图控制器),但我不知道如何实现这一点。我知道iPhone中的绘图从左上角的0,0坐标开始向右和向下。有没有办法欺骗并从底部到顶部70%覆盖屏幕,就像在iOS 7.x.x中在iPhone屏幕上向上滑动时的工具菜单一样

提前致谢。

1 个答案:

答案 0 :(得分:1)

这是一个解决方案:

  1. 将视图创建为此控制器中主视图的子视图。

    self.rolloutView = [[UIView alloc]initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, heightYouWant)];
    
  2. 当用户执行操作时,请调用此函数

    -(void)toggleView:(id)sender
    {   
        __block CGRect frame = self.rolloutView.frame;
         // Check if the frame's origin.y is at the bottom of the screen
        if(self.rolloutView.frame.origin.y == [[UIScreen mainScreen] bounds].size.height){
            // if it is, reduce it by the height of the view you eventually want
             frame.origin.y = [[UIScreen mainScreen] bounds].size.height-heightYouWant ;
        }
        else{
            // else push it down again
            frame.size.height = [[UIScreen mainScreen] bounds].size.height;
        }
        [UIView animateWithDuration:.3
                 animations:^{
                     self.rolloutView.frame = frame;
                 }
                     completion:nil];
    }
    
  3. 我没有编译代码,但它应该让你知道我的建议

相关问题