And*_*kov 10 ios ios5 uipopoverbackgroundview
Apple缺少有关如何使用UIPopoverBackgroundViewiOS5中引入的类的文档.有人有例子吗?
我试图将其子类化,但我的Lion上的XCode 4.2缺失了 UIPopoverBackgroundView.h
编辑:不出所料,它应该被导入为#import <UIKit/UIPopoverBackgroundView.h>
jrt*_*ton 13
要添加到另一个,仅链接的答案,这是如何完成的.
在您的界面中声明以下内容:
+(UIEdgeInsets)contentViewInsets;
+(CGFloat)arrowHeight;
+(CGFloat)arrowBase;
@property(nonatomic,readwrite) CGFloat arrowOffset;
@property(nonatomic,readwrite) UIPopoverArrowDirection arrowDirection;
Run Code Online (Sandbox Code Playgroud)类方法很简单:contentViewInsets返回边框的宽度(不包括箭头),arrowHeight是箭头的高度,arrowBase是箭头的基础.
[self setNeedsLayout].layoutSubviews.在这里,根据arrowDirection和arrowOffset属性,您必须调整背景视图和箭头视图的框架.
self.bounds插入arrowHeightarrowOffset远离中心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];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11178 次 |
| 最近记录: |