我已经按如下方式实现了这个类:
#import "JKBackgroundView.h"
@implementation JKBackgroundView
static CGFloat jkArrowBase = 26.0;
static CGFloat jkArrowHeight = 16.0;
// Background image insets
static CGFloat jkBackgroundTopInset = 68.0f;
static CGFloat jkBackgroundLeftInset = 16.0f;
static CGFloat jkBackgroundBottomInset = 16.0f;
static CGFloat jkBackgroundRightInset = 34.0f;
// Content view insets
static CGFloat jkContentTopInset = 40.0f;
static CGFloat jkContentLeftInset = 6.0f;
static CGFloat jkContentBottomInset = 8.0f;
static CGFloat jkContentRightInset = 7.0f;
+(CGFloat)arrowBase {
return jkArrowBase;
}
-(UIPopoverArrowDirection)arrowDirection {
return UIPopoverArrowDirectionUp;
}
-(CGFloat)arrowOffset {
return 0.0f;
}
+(CGFloat)arrowHeight {
return jkArrowHeight;
}
+(UIEdgeInsets)contentViewInsets {
return UIEdgeInsetsMake(jkContentTopInset, jkContentLeftInset, jkContentBottomInset, jkContentRightInset);
}
-(void)drawRect:(CGRect)rect {
UIEdgeInsets popoverInsets = UIEdgeInsetsMake(jkBackgroundTopInset, jkBackgroundLeftInset, jkBackgroundBottomInset, jkBackgroundRightInset);
UIImage *popoverImage = [[UIImage imageNamed:@"popover_stretchable.png"] resizableImageWithCapInsets:popoverInsets];
[popoverImage drawInRect:rect];
}
-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
-(void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
// Do nothing
}
@end
我使用以下代码将其添加到我的 UIPopoverView (不是子类)中:
_logoutPopover.popoverBackgroundViewClass = [JKBackgroundView class];
但是,当我运行该项目时,我收到一条疯狂的错误消息,如下所示:
*由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIPopoverBackgroundView”
§lå] 必须由子类实现。
有谁知道它认为我没有实施什么方法?看起来只是一堆胡言乱语。谢谢!
Edit看起来我忘记实现 setArrowOffset: 。添加后就可以工作了。苹果的错误信息只是乱码。
根据UIPopoverBackgroundView 的文档 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverBackgroundView_class/Reference/Reference.html#//apple_ref/occ/cl/UIPopoverBackgroundView您还需要为以下属性实现设置器UIPopoverBackgroundView
(i.e. arrowDirection
and arrowOffset
.) 你刚刚在你的实现中得到了吸气剂。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)