0

我不知道如何实现它,但下图显示了我想要出现的模态大小:

模态视图控制器

我用于推送模态视图的代码是:

CustomerLogin *customerlogin = [[CustomerLogin alloc] initWithNibName:@"CustomerLogin" bundle:nil];
        [self presentModalViewController:customerlogin animated:YES]; 

        [customerlogin release];

编辑 - -

做出如下建议的更改,如下所示:

UIView *overlay = [[UIView alloc] initWithFrame:self.view.bounds];
        overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; // Black color
        [self.navigationController.view addSubview:overlay];

        //Add Login View
        CustomerLogin *loginView = [[CustomerLogin alloc] initWithFrame:CGRectMake(0,0, 200, 300)]; //I guessed a size
        loginView.center = overlay.center; //Center the view
        [overlay addSubview:loginView];

得到3个错误:

CustomerLogin 上不存在属性中心 CustomerLogin 不会响应 initWithFrame 不兼容的指针类型发送 CustomerLogin* 以键入 UIView*

4

3 回答 3

2

您正在尝试呈现模态视图控制器而不是单个视图。

实现这一点的最佳方法是创建一个叠加层(例如黑色,alpha 0.5),然后在它上面显示登录视图。

覆盖层用于防止用户与后台控件交互(如果使用 NavigationViewController,则为后退按钮、按钮、选项卡等...)。

这是一个例子:

UIView *overlay = [[UIView alloc] initWithFrame:self.view.bounds];
overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; // Black color
[self.view addSubview:overlay];

//Add Login View
CustomLoginView *loginView = [[CustomLoginView alloc] initWithFrame:CGRectMake(0,0, 200, 300)]; //I guessed a size
loginView.center = overlay.center; //Center the view
[overlay addSubview:loginView];

请记住,如果您有 TabBarController 或 NavigationController,则应将覆盖应用到它,而不是使用[self.view addSubview:overlay]use[self.tabBarController.view addSubview:overlay][self.navigationController.view addSubview:overlay]

于 2012-04-26T13:28:59.880 回答
1

利用

    -(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
        // grab an image of our parent view
    UIView *parentView = self.presentingViewController.view;

        // For iOS 5 you need to use presentingViewController:
        // UIView *parentView = self.presentingViewController.view;

    UIGraphicsBeginImageContext(parentView.bounds.size);
    [parentView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *parentViewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

        // insert an image view with a picture of the parent view at the back of our view's subview stack...
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageView.image = parentViewImage;
    [imageView setHidden:YES];
    [self.view insertSubview:imageView atIndex:0];
}
-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[self.view.subviews objectAtIndex:0] setHidden:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

        // remove our image view containing a picture of the parent view at the back of our view's subview stack...
    [[self.view.subviews objectAtIndex:0] removeFromSuperview];
}

在您的模态视图控制器中

请记住,您的模态视图需要是全屏的,所以将您想要成为模态视图的内容放在另一个具有透明背景的全屏尺寸视图中

模态视图控制器的视图需要是这个视图

于 2012-04-26T13:24:24.770 回答
1

您可能想查看 TSAlertView。它允许您创建自定义视图,这些视图类似于 UIAlertView 的代码。 https://github.com/TomSwift/TSAlertView

于 2012-04-26T14:31:27.403 回答