iOS:为什么我的模态视图上有白色圆angular?

我有一个模式的视图popup在我的iPad应用程序,由于某种原因,它有白色的圆angular。

可能值得注意的是我在故事板中build立了这个模型视图,而不是以编程方式。 但是,在我的viewWillAppear方法中,我正在设置像这样的angular落半径…

- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.view.layer.cornerRadius = 6.0f; } 

当我设置6以上的值时,白色的angular落变得可见。 如何在没有这些白色圆angular的情况下将价值更高?

非常感谢您的智慧!

你的问题是你的视图控制器使用什么types的演示文稿含糊不清,所以我会假设你正在使用一个表单。 解决方法是将[UIColor clearColor]视图的背景颜色设置为[UIColor clearColor]以防止出现半透明背景:

 - (void) viewDidAppear:animated { [super viewDidAppear:animated]; self.view.layer.cornerRadius = 10; self.view.layer.masksToBounds = YES; self.view.superview.backgroundColor = [UIColor clearColor]; } 

在设置backgroundColor之前:

之前

设置backgroundColor

后

尝试

 [self.view superview].layer.cornerRadius = 21.0f; [self.view superview].layer.masksToBounds = YES; 

我意识到这是一个老问题,但值得回答…

在iPad上,Modal视图(使用UIModalPresentationFormSheet)有一个默认的背景,它是一个带有白色狗angular的白色边框图像。 无论如何,如果您的模态视图背景具有圆形或透明的angular落,默认的背景将显示。

我花了一些时间试图弄清楚如何让我的背景视图显示没有默认的背景显示。 诀窍是使超级视图比你的观点更小:

 vc.view.clipsToBounds = NO; vc.view.superview.bounds = CGRectMake(vc.view.superview.bounds.origin.x, vc.view.superview.bounds.origin.y, 300, 480); 

注意:vc是你正在呈现的视图。 不要让视图太小,否则你的触摸事件将不起作用。

这很奇怪。 尝试self.view.layer.masksToBounds = YES; 如果有效的话。 尽pipe你可能会失去你的观点的阴影。

想想看,白色的东西可能来自导航栏下方的视图。

尝试在应用程序委托: [[self window] setBackgroundColor:[UIColor blackColor]];

我是我的情况,白色的东西隐藏在投影的背景颜色的阴影的视图。 通过改变背景来清除颜色解决:

 //Monotouch code View.Superview.Layer.BackgroundColor = UIColor.Red.CGColor; 

如果它没有摆脱白色的angular落继续search,请记住查看视图,SuperView和BackgroundViews的一些属性:

  • 背景颜色
  • 图层的背景颜色
  • 图层的边框宽度和颜色
  • 标题
  • 剪辑到界限

注意:DropShadow在ViewWillApper视图的SuperView中ViewWillApper

我同意@PeterPurple的回答,但是花了我一些时间想出实际工作的代码。 我的例子显示一个水平居中的模式视图,但更多地放在屏幕的顶部,所以视图不会阻塞键盘。 当然,我可以在键盘显示时将视图向上移动,但我很懒。 无论如何,这是我是如何做到的。

我创build了一个自定义的模态segue,在那个segue中,我覆盖了perform:方法,如下所示:

 @implementation CustomSegue static const CGFloat TOP_MARGIN = 40; static const CGFloat SUPER_VIEW_GAP = 10; - (void)perform { UIView *destView = [self.destinationViewController view]; [self.destinationViewController setModalPresentationStyle:UIModalPresentationPageSheet]; [self.destinationViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [[self sourceViewController] presentViewController:[self destinationViewController] animated:YES completion:nil]; CGFloat x, y, width, height, yCenter; CGSize contentSize = [self.destinationViewController contentSizeForViewInPopover]; x = destView.superview.frame.origin.x; y = destView.superview.frame.origin.y; width = contentSize.width; height = contentSize.height; yCenter = (height / 2.0) + TOP_MARGIN; destView.superview.frame = CGRectMake(x + SUPER_VIEW_GAP, y + SUPER_VIEW_GAP, width - (SUPER_VIEW_GAP * 2), height - (SUPER_VIEW_GAP * 2)); destView.superview.autoresizingMask = UIViewAutoresizingNone; destView.superview.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin; destView.superview.center = CGPointMake([[self.sourceViewController view] center].x, yCenter); destView.frame = CGRectMake(-SUPER_VIEW_GAP, -SUPER_VIEW_GAP, width, height); } 

为了使模式视图透明,并使视图出现之前发生的透明度是从viewDidAppear移动self.view.superview.backgroundColor = [UIColor clearColor]如下:

  • (void)viewWillLayoutSubviews {[super viewWillLayoutSubviews];

    self.view.superview.backgroundColor = [UIColor clearColor]; }

如果您使用popoverpresentationcontroller来显示您的视图控制器,请尝试设置popoverpresentationcontroller的backgroundcolor清除

  examplePopUpController = exampleViewController.popoverPresentationController! examplePopUpController?.backgroundColor = UIColor.clear