iPhone模式视图与父视图半可见?
我使用以下代码添加模态视图:iPhone模式视图与父视图半可见?
[self presentModalViewController:phrasesEditor animated:YES];
如何使模态视图半透明,以便超级视图“闪耀”通过?
我的完整方法/函数如下所示:
-(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]; 
} 
编辑:
显然,改变alpha的实用方法不起作用。如何将NIB加载到UIView中并与之交互?
我现在有一个UIViewController。我是否将其转换/修改/更改为UIVIew然后加载它,或者我应该做其他事情?
编辑2:
我试过[self.view addSubview:phrasesEditor.view];,但这让我无法删除子视图。每个视图似乎都有自己的View Controller。
编辑3:
我认为我应该提到superview是一个名为iDecideViewController的视图控制器,而phraseEditor有一个单独的View Controller。
回答:
当你提出一个模式的看法它实际上将卸载以前的观点,这样是不是你想要的所有东西。 UIView有一个名为addSubview的方法,它将把新视图置于其兄弟之上。
相反的:
[self presentModalViewController:phrasesEditor animated:YES]; 做:
[self.view addSubview:phrasesEditor.view]; 这是假设你已经在一个视图控制器子类。
回答:
我有同样的问题,并添加属性和方法2到的UIViewController的一个子类,以模仿presentModalViewController的行为:动画:
如需更多信息,请参见我的博客文章:How to display a transparent modal view controller或看看下面的代码:
#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; 
         }]; 
    } 
} 
以上是 iPhone模式视图与父视图半可见? 的全部内容, 来源链接: utcz.com/qa/266090.html






