我用这个好的tutorial来创建一个自定义的UIPopoverBackgroundView类。自定义UIPopoverBackgroundView:没有投影
它运作良好。唯一的问题是我没有得到典型的UIPopoverController阴影,我想要它。我试过在我的UIPopoverBackgroundView实例的层上指定它,但没有成功。我的UIPopoverController实例似乎没有公共视图来操作。将它添加到弹出窗口内容也不起作用。
可能很简单:如何在使用自定义UIPopoverBackgroundView类时添加投影?
// UIPopoverBackgroundView.m
-(id)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
_borderImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"bg-popover.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(CAP_INSET,CAP_INSET,CAP_INSET,CAP_INSET)]];
_arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-popover-arrow.png"]];
[self addSubview:_borderImageView];
[self addSubview:_arrowView];
self.layer.shadowOffset = CGSizeMake(50, 50);
self.layer.shadowColor = [[UIColor blackColor] CGColor];
}
return self;
}
非常感谢你为这个! – 2012-05-26 17:52:55
只是想我会补充说这对我有效,但我有性能问题。栅格化背景图层非常有帮助:'backgroundImageView.layer.shouldRasterize = YES;' – Maurizio 2012-07-04 16:26:22
有趣 - 我没有注意到任何明显的滞后(在iPad 2上),但很好知道。 – 2012-07-04 16:33:02