Sor*_*rig 19 cocoa-touch objective-c ipad uipopovercontroller ios5
我正在创建iOS提供的popover的自定义布局.我已经将UIPopoverBackgroundView子类化,并让它为我的popover正确绘制背景.我的问题是现在UIPopoverController在popover上创建了一个内部阴影,影响了popover的contentViewController.我想删除这个内部阴影,所以只显示我的contentViewController的内容.
这是popover当前的外观,使用UILabel来演示对contentViewController的影响.

有没有办法去除这个内部阴影?
kaj*_*ham 25
通过以下调用在ios6.0中添加了对此的支持:
+ (BOOL)wantsDefaultContentAppearance
链接到文档:http: //developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverBackgroundView_class/Reference/Reference.html
Sor*_*rig 10
由于没有优雅的方法来做到这一点,因为我不想重写整个UIPopoverController只是为了做到这一点,我创建了一个简单的hack,通过遍历UIView结构去除popover上的内部阴影.hack是UIPopoverController上的一个类别,我只是将它放在我的UIPopoverBackgroundView子类的文件中.所以这是代码:
@interface UIPopoverController(removeInnerShadow)
- (void)removeInnerShadow;
- (void)presentPopoverWithoutInnerShadowFromRect:(CGRect)rect 
                                          inView:(UIView *)view 
                        permittedArrowDirections:(UIPopoverArrowDirection)direction 
                                        animated:(BOOL)animated;
- (void)presentPopoverWithoutInnerShadowFromBarButtonItem:(UIBarButtonItem *)item 
                                 permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections 
                                                 animated:(BOOL)animated;
@end
@implementation UIPopoverController(removeInnerShadow)
- (void)presentPopoverWithoutInnerShadowFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)direction animated:(BOOL)animated 
{
    [self presentPopoverFromRect:rect inView:view permittedArrowDirections:direction animated:animated];
    [self removeInnerShadow];
}
- (void)presentPopoverWithoutInnerShadowFromBarButtonItem:(UIBarButtonItem *)item 
                                 permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections 
                                                 animated:(BOOL)animated
{
    [self presentPopoverFromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated];
    [self removeInnerShadow];
}
- (void)removeInnerShadow
{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    for (UIView *windowSubView in window.subviews)
    {
        if ([NSStringFromClass([windowSubView class]) isEqualToString:@"UIDimmingView"])
        {
            for (UIView *dimmingViewSubviews in windowSubView.subviews)
            {
                for (UIView *popoverSubview in dimmingViewSubviews.subviews)
                {
                    if([NSStringFromClass([popoverSubview class]) isEqualToString:@"UIView"]) 
                    {
                        for (UIView *subviewA in popoverSubview.subviews)
                        {
                            if ([NSStringFromClass([subviewA class]) isEqualToString:@"UILayoutContainerView"])
                            {
                                subviewA.layer.cornerRadius = 0;
                            }
                            for (UIView *subviewB in subviewA.subviews)
                            {
                                if ([NSStringFromClass([subviewB class]) isEqualToString:@"UIImageView"] )
                                {
                                    [subviewB removeFromSuperview];
                                }
                            }
                        }
                    }
                }
            }
        } 
    }
}
@end
当我想显示我的popover时,我只是调用presentPopoverWithoutInnerShadowFromRect:和presentPopoverWithoutInnerShadowFromBarButtonItem:方法而不是标准方法.注意:请记住要使#import <QuartzCore/QuartzCore.h>代码生效
小智 10
我为我正在研究的项目创建了自己的版本.
基本上你应该使用你自己的自定义backgroundClasspopover,在这个类中你应该定义:
- (void)willMoveToWindow:(UIWindow *)newWindow {
    [super willMoveToWindow:newWindow];
    if ([UIPopoverBackgroundView respondsToSelector:@selector(wantsDefaultContentAppearance)]) 
        return;
    if (![[self class] wantsDefaultContentAppearance]) {
        for (UIView *view in self.superview.subviews) {
            for (UIView *subview in view.subviews) {
                if (subview.layer.cornerRadius != 0.0) {
                   subview.layer.cornerRadius = 0.0;
                    for (UIView *subsubview in subview.subviews) {
                        if (subsubview.class == [UIImageView class])
                            subsubview.hidden = YES;
                    }
                }
            }
        }
    }
}
应该是iOS更新的防弹.