【问题标题】:Modal form sheet view controller on iPad - fade to blackiPad上的模态表单视图控制器 - 淡入黑色
【发布时间】:2012-06-25 11:36:41
【问题描述】:

当在 iPad 上呈现模态表单视图控制器时,未被表单占据的屏幕的其余部分会变暗(但保持透明)。有什么办法让它一直变暗到黑色(即变得不透明)?

谢谢。

【问题讨论】:

    标签: ios ipad uiviewcontroller background modal-dialog


    【解决方案1】:

    不,dim 始终带有 alpha,要执行您需要的操作,您必须实现自己的模态转换表

    【讨论】:

      【解决方案2】:

      你可以用一张图片来做:

      - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
          UIImage *backgroundImage = [UIImage imageNamed:@"testimage.png"];    
          backgroundImage = [backgroundImage stretchableImageWithLeftCapWidth:20 topCapHeight:40];
          CGSize theSize = actionSheet.frame.size;
          // draw the background image and replace layer content  
          UIGraphicsBeginImageContext(theSize);    
          [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
          theImage = UIGraphicsGetImageFromCurrentImageContext();    
          UIGraphicsEndImageContext();
          [[actionSheet layer] setContents:(id)backgroundImage.CGImage];
      }
      

      或者这样做:

      CGSize mySize = myActionSheet.bounds.size;
      CGRect myRect = CGRectMake(0, 0, mySize.x, mySize.y);
      UIImageView *blackView = [[[UIImageView alloc] initWithFrame:myRect] autorelease];
      [redView setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
      [self.view insertSubview:blackView atIndex:0];
      

      你也可以改变actionSheetStyle

      MyActionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque;
      MyActionSheet.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
      

      【讨论】:

      • 谢谢。有没有办法在 iPad 上以表单样式使用模态视图控制器?
      【解决方案3】:

      考虑到似乎没有一个很好的解决方案,可以通过在 prepareForSegue() 中的 presentingViewController 顶部插入一个黑色背景的子视图来完成简单的 hack。然后在关闭表单之前,获取presentingViewController (self.presentingViewController) 并移除添加的视图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-29
        • 1970-01-01
        • 2011-01-20
        • 2013-03-30
        相关资源
        最近更新 更多