当我调整模态视图控制器时,我有阴影的错误

时间:2012-11-24 20:54:23

标签: ios presentmodalviewcontroller uimodalpresentationstyle

我想调整大小并重新定位模态视图。调整大小效果很好。重新定位不起作用。有阴影的bug。请看截图二。是否可以降低阴影?

-(IBAction) onModal:(id)sender
{
 UINavigationController *nav = [[UINavigationController alloc] init];
 nav.modalPresentationStyle = UIModalPresentationFormSheet;
 [self presentViewController:nav animated:YES completion:nil];

 nav.view.superview.bounds = CGRectMake(0, 0, 200, 200);    
}

enter image description here

nav.view.superview.bounds = CGRectMake(0, -200, 200, 200); 

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以通过设置视图图层的shadowPath属性来移动阴影。

// be sure to include this and to link your app against it.
#import <QuartzCore/QuartzCore.h>
...

// UIBezierPath has nice convenience methods for creating rounded rectangles.
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0.f, 0.f, 200.f, 200.f) cornerRadius:4.f];

// Transform the path to your heart's content
[shadowPath applyTransform:CGAffineTransformMakeTranslation(0.f, 200.f)];

// use the CGPath method to get a CGPathRef for the layer's shadowPath
nav.view.superview.layer.shadowPath = shadowPath.CGPath;

注意:或者你可以用你需要的偏移创建UIBezierPath,而不是转换为第二步。