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示意图:

UIPopoverController

重要概念:

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

UIPopoverController

上一篇:POJ 2774 最长公共子串


下一篇:UVA 11374 Airport Express dijkstra