UIPopoverController

iPad App里涉及到弹出窗口,经常会用到UIPopoverController。UIPopoverController的使用比较简单。

1、初始化:

- (id)initWithContentViewController:(UIViewController *)viewController;

通过contentVC来初始化popover

示例:

  TXContentViewController * contentVC  = [[TXContentViewController alloc]initWithNibName:nil bundle:nil];

    self.popoverVCA = [[UIPopoverController alloc]initWithContentViewController:contentVC];

2、弹出popover

系统提供了2种方法:

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;

通过指定一块区域弹出popover

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;

通过一个barButtonItem弹出popover

示例:

     [self.popoverVCA presentPopoverFromRect:CGRectMake(200, 200, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES] ;

demo示意图:

重要概念:

1、popover的箭头方向

skd的文档里定义如下:

typedef NS_OPTIONS(NSUInteger, UIPopoverArrowDirection) {

    UIPopoverArrowDirectionUp = 1UL << 0, //向上

    UIPopoverArrowDirectionDown = 1UL << 1, //向下

    UIPopoverArrowDirectionLeft = 1UL << 2, //向左

    UIPopoverArrowDirectionRight = 1UL << 3, //向右

    UIPopoverArrowDirectionAny = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown | UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight, //上下左右

    UIPopoverArrowDirectionUnknown = NSUIntegerMax

};

2、相关属性

@property (nonatomic, retain) UIViewController *contentViewController;

@property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;

@property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection;

@property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);

demo源码见:https://github.com/tingxuan/TXUIPopoverDemo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值