Apple 缺少有关如何使用UIPopoverBackgroundView
iOS5 中引入的类的文档。有人有例子吗?
我试图对其进行子类化,但我在 Lion 上的 XCode 4.2 丢失了UIPopoverBackgroundView.h
编辑:不出所料,它应该被导入为#import <UIKit/UIPopoverBackgroundView.h>
Apple 缺少有关如何使用UIPopoverBackgroundView
iOS5 中引入的类的文档。有人有例子吗?
我试图对其进行子类化,但我在 Lion 上的 XCode 4.2 丢失了UIPopoverBackgroundView.h
编辑:不出所料,它应该被导入为#import <UIKit/UIPopoverBackgroundView.h>
要添加到其他仅链接的答案,这是如何完成的。
在您的界面中声明以下内容:
+(UIEdgeInsets)contentViewInsets;
+(CGFloat)arrowHeight;
+(CGFloat)arrowBase;
@property(nonatomic,readwrite) CGFloat arrowOffset;
@property(nonatomic,readwrite) UIPopoverArrowDirection arrowDirection;
类方法很简单:contentViewInsets
返回所有边框的宽度(不包括箭头),arrowHeight
是箭头的高度,arrowBase
是箭头的底部。
[self setNeedsLayout]
.layoutSubviews
。在这里,根据arrowDirection
和arrowOffset
属性,您必须调整背景视图和箭头视图的框架。
self.bounds
,arrowHeight
在箭头所在的任何边缘插入arrowOffset
远离中心self
(根据轴正确)。如果箭头方向不向上,您必须更改图像方向,但我的弹出框只会向上,所以我没有这样做。这是layoutSubviews
我的 Up-only 子类的方法:
-(void)layoutSubviews
{
if (self.arrowDirection == UIPopoverArrowDirectionUp)
{
CGFloat height = [[self class] arrowHeight];
CGFloat base = [[self class] arrowBase];
self.background.frame = CGRectMake(0, height, self.frame.size.width, self.frame.size.height - height);
self.arrow.frame = CGRectMake(self.frame.size.width * 0.5 + self.arrowOffset - base * 0.5, 1.0, base, height);
[self bringSubviewToFront:self.arrow];
}
}
另一个链接仅回答,但UIPopoverBackgroundView
鉴于可用的文档有限,定制工作比您可能意识到的要多,而且这个 github 项目有一个完整的工作示例,为我节省了大量时间:https ://github.com/GiK/GIKPopoverBackgroundView
进入您自己的项目相当简单。最繁琐的部分是为您使用的任何自定义图像调整帽子插图。我建议您在项目中就地进行自定义,因为在将其迁移到您自己的项目之前,很容易验证所有弹出框方向/方向用例在模拟器中正确显示。