iPad上的模态表单视图控制器 - 淡入黑色

时间:2012-06-25 11:36:42

标签: ios ipad uiviewcontroller background modal-dialog

在iPad上展示模态表单视图控制器时,表单未占用的屏幕剩余部分会变暗(但仍保持透明)。有没有办法让它一直变暗(即变暗)?

感谢。

3 个答案:

答案 0 :(得分:0)

不,昏暗总是带着alpha,做你需要的,你必须实现你自己的模态转换表

答案 1 :(得分:0)

您可以使用图片执行此操作:

- (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;

答案 2 :(得分:0)

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