父视图半可见的iPhone模态视图?

父视图半可见的iPhone模态视图?,iphone,modal-dialog,Iphone,Modal Dialog,我使用以下代码添加模态视图: [自我呈现Modalviewcontroller:phrasesEditor动画:是] 如何使模态视图半透明,以便superview“发光”通过 我的完整方法/函数如下所示: -(IBAction)showEditPhrases:(id)sender{ PhrasesViewController *phrasesEditor = [[PhrasesViewController alloc] initWithNibName:@"PhrasesViewContr

我使用以下代码添加模态视图:

[自我呈现Modalviewcontroller:phrasesEditor动画:是]

如何使模态视图半透明,以便superview“发光”通过

我的完整方法/函数如下所示:

-(IBAction)showEditPhrases:(id)sender{
    PhrasesViewController *phrasesEditor = [[PhrasesViewController alloc] initWithNibName:@"PhrasesViewController" bundle:nil];
    phrasesEditor.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [phrasesEditor.view setAlpha: 0.5];
    [phrasesEditor.view setBackgroundColor: [UIColor clearColor]];
    [self presentModalViewController:phrasesEditor animated:YES];
    [phrasesEditor release];
}
编辑:

显然,改变阿尔法的务实方法是行不通的。如何将NIB加载到UIView并与之交互

我现在有一个UIViewController。我是将其转换/修改/更改为UIVIew然后加载它,还是应该执行其他操作

编辑2:

我尝试了
[self.view addSubview:phrasesEditor.view],但这使我无法删除子视图。每个视图似乎都有自己的视图控制器

编辑3:


我想我应该提到superview在一个名为iDecideViewController的视图控制器中,而phrasesEditor有一个单独的视图控制器。

当您呈现一个模式视图时,它实际上会卸载上一个视图,所以这根本不是您想要的。UIView有一个名为addSubview的方法,它将把新视图放在它的同级视图之上

而不是:

[self presentModalViewController:phrasesEditor animated:YES];
做:


这是假设您已经在ViewController子类中。

当您呈现一个模态视图时,它实际上会卸载上一个视图,因此这根本不是您想要的。UIView有一个名为addSubview的方法,它将把新视图放在它的同级视图之上

而不是:

[self presentModalViewController:phrasesEditor animated:YES];
做:


这是假设您已经在ViewController子类中。

我遇到了相同的问题,并向UIViewController的子类添加了一个属性和两个方法,以模拟presentModalViewController的行为:动画:

有关mor信息,请参阅我的博文:或查看以下代码:

#pragma mark - Transparent Modal View
-(void) presentTransparentModalViewController: (UIViewController *) aViewController 
                                     animated: (BOOL) isAnimated 
                                    withAlpha: (CGFloat) anAlpha{

    self.transparentModalViewController = aViewController;
    UIView *view = aViewController.view;

    view.opaque = NO;
    view.alpha = anAlpha;
    [view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        UIView *each = obj;
        each.opaque = NO;
        each.alpha = anAlpha;
    }];

    if (isAnimated) {
        //Animated
        CGRect mainrect = [[UIScreen mainScreen] bounds];
        CGRect newRect = CGRectMake(0, mainrect.size.height, mainrect.size.width, mainrect.size.height);


        [self.view addSubview:view];
        view.frame = newRect;

        [UIView animateWithDuration:0.8
                         animations:^{
                             view.frame = mainrect;
                         } completion:^(BOOL finished) {
                             //nop
                         }];

    }else{
        view.frame = [[UIScreen mainScreen] bounds];
        [self.view addSubview:view];
    }






}

-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{

    if (animated) {
        CGRect mainrect = [[UIScreen mainScreen] bounds];
        CGRect newRect = CGRectMake(0, mainrect.size.height, mainrect.size.width, mainrect.size.height);
        [UIView animateWithDuration:0.8
                         animations:^{
                             self.transparentModalViewController.view.frame = newRect;
                         } completion:^(BOOL finished) {
                             [self.transparentModalViewController.view removeFromSuperview];
                             self.transparentModalViewController = nil;
                         }];
    }


}

我也遇到了同样的问题,在UIViewController的子类中添加了一个属性和两个方法,以模拟presentModalViewController的行为:动画:

有关mor信息,请参阅我的博文:或查看以下代码:

#pragma mark - Transparent Modal View
-(void) presentTransparentModalViewController: (UIViewController *) aViewController 
                                     animated: (BOOL) isAnimated 
                                    withAlpha: (CGFloat) anAlpha{

    self.transparentModalViewController = aViewController;
    UIView *view = aViewController.view;

    view.opaque = NO;
    view.alpha = anAlpha;
    [view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        UIView *each = obj;
        each.opaque = NO;
        each.alpha = anAlpha;
    }];

    if (isAnimated) {
        //Animated
        CGRect mainrect = [[UIScreen mainScreen] bounds];
        CGRect newRect = CGRectMake(0, mainrect.size.height, mainrect.size.width, mainrect.size.height);


        [self.view addSubview:view];
        view.frame = newRect;

        [UIView animateWithDuration:0.8
                         animations:^{
                             view.frame = mainrect;
                         } completion:^(BOOL finished) {
                             //nop
                         }];

    }else{
        view.frame = [[UIScreen mainScreen] bounds];
        [self.view addSubview:view];
    }






}

-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{

    if (animated) {
        CGRect mainrect = [[UIScreen mainScreen] bounds];
        CGRect newRect = CGRectMake(0, mainrect.size.height, mainrect.size.width, mainrect.size.height);
        [UIView animateWithDuration:0.8
                         animations:^{
                             self.transparentModalViewController.view.frame = newRect;
                         } completion:^(BOOL finished) {
                             [self.transparentModalViewController.view removeFromSuperview];
                             self.transparentModalViewController = nil;
                         }];
    }


}

从phrasesEditor上的SuperView移除。视图我不确定。它有一个独立于短语编辑器的视图控制器,并导致EXC_BAD_ACCESSEDIT:我想出来了。我当时
[phraseEditor release]
太早了。所以现在我正在泄漏内存,必须处理好。处理好。我决定坚持使用
[自我呈现模式控制器:短语编辑器动画:是]并通过UIImage将背景图像应用于该图像。问题解决了。在短语编辑器上从SuperView移除。视图我对此不确定。它有一个独立于短语编辑器的视图控制器,并导致EXC_BAD_ACCESSEDIT:我想出来了。我当时
[phraseEditor release]
太早了。所以现在我正在泄漏内存,必须处理好。处理好。我决定坚持使用
[自我呈现模式控制器:短语编辑器动画:是]并通过UIImage将背景图像应用于该图像。问题解决了。