【问题标题】:Modal View Transparant background - stop lower layer hiding?模态视图透明背景 - 停止底层隐藏?
【发布时间】:2013-11-15 10:01:30
【问题描述】:

我有一个分享页面的简介,其中包括单击分享按钮和显示在顶部的模式视图,其中包含一些分享功能。

我的问题是我希望模态视图的背景是半透明的,因此在下面显示视图。我已经设置了模态层的背景属性,当模态出现时,下面的层是短暂可见的 - 看起来完全符合我的要求 - 但是一旦封面转换完成,背景视图就会隐藏 - 有什么办法吗这个?

(顺便用IOS7)

干杯

更新 - @Tommaso Resti 帮助我尝试解决这个问题 - 解释我到目前为止所做的事情 - 我的主故事板包含一个未链接的 uiview 标识符为“ShareScreenView” -单击按钮时,我想将其作为透明模式添加到我的 mainView 中。我已将按钮链接为 IBAction,并将以下内容添加到我的方法中 -

- (IBAction)shareBtn:(id)sender {


    NSLog(@"clicked");



    /* Create your view off the screen (bottom) */

    /* NEW EDIT */
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"
                                                         bundle: nil];
    UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ShareScreenView"];

    [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)];
 // [myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height])];


 /* Animate it from the bottom */
 [UIView animateWithDuration:.5 animations:^{
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myModalController.view.transform = move;   /* UPDATED HERE */
     NSLog(@"Atrying");
 } completion:^(BOOL finished) {
    NSLog(@"Adid try");
    if(finished) {
        NSLog(@"Animation completed");
    }
 }];

} 

但我在线上遇到错误 -

[myModalController.view setFrame: CGRectMake(0, [[UIScreen mainScreen].bounds.size.height], [[UIScreen mainScreen].bounds.size.width], [[UIScreen mainScreen].bounds.size.height ])];

它只是用指向高度的箭头声明“预期标识符”(见下面的屏幕截图)

所以我尝试按如下方式添加属性 -

 [myModalController.view setFrame:CGRectMake(0, 568, 320, 568)];

现在没有错误 - 但什么也没发生,也没有错误..

【问题讨论】:

    标签: ios objective-c modalviewcontroller


    【解决方案1】:

    我建议使用你自己的方法:

    类似这样的:

    /* Create your view off the screen (bottom) */
    
    /* NEW EDIT */
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle: nil];
    UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyModalController"];
    [myModalController.view setFrame: CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [self.view addSubview: myModalController.view]; /* UPDATED HERE! */
    
    
    /* Animate it from the bottom */
    [UIView animateWithDuration:.5 animations:^{
        CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        myModalController.view.transform = move;   /* UPDATED HERE */
    } completion:^(BOOL finished) {
        if(finished) {
            NSLog(@"Animation completed");
        }
    }];
    

    比用这个动画移除:

    /* Reset animation */
    [UIView animateWithDuration:.5 animations:^{
        CGAffineTransform reset = CGAffineTransformIdentity;
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        myModalController.view.transform = reset;  /* UPDATED HERE */
    } completion:^(BOOL finished) {
        if(finished) {
            NSLog(@"Reset completed");
            [myModalController.view removeFromSuperview];
        }
    }];
    

    --- 已编辑 --- 抱歉,我忘了在 myViewController 之后添加“.view”。 我从不尝试我的代码……我的错;)

    例子更新了!

    【讨论】:

    • 很酷的欢呼 - 我可以在情节提要中使用这种方法吗?我还没用过笔尖!
    • 当然!使用 UIViewController *myModalController = [storyboard instantiateViewControllerWithIdentifier:@"MyModalController"];而不是 UIViewController myModalController = [[UIViewController allor] initWithNibName:@"MyModalController" bundle:[NSBundle mainBundle]];
    • 很酷的欢呼 - 一个问题 - 我收到一条错误消息,指出“在这一行的 UIViewController 上找不到属性转换 - myModalController.transform = move;
    • 您需要在 Interface Builder 中设置一个 ID。按照这个例子stackoverflow.com/questions/13867565/…
    • 嗨舞者,我出去吃午饭了。好的错误发现,代码编辑。只需像这样从 [[UIScreen mainScreen].bounds.size.height] 中删除 '[' 和 ']' -> [UIScreen mainScreen].bounds.size.height
    【解决方案2】:

    您可以创建一个视图,从底部滑入,然后使视图半透明。

    【讨论】:

      【解决方案3】:

      您可以使用 View Container 创建自己的 ModalViewController 并像 @Tommaso Resti 所说的那样做动画

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-24
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 2015-02-24
        相关资源
        最近更新 更多