关闭

UIPopoverController

标签: ipad控件ios
122人阅读 评论(0) 收藏 举报

MIN(A,B):
大小取决于B, 但最大不超过A, chaoguoA则其值为A
UIpopoverController是只适用于IPad的空间, 需要在devices中将设备改为IPad, 该控件适用于iOS3.2 ~ 9.0版本
效果图:
如图

  1. 签协议, UIPopoverControllerDelegate,
@property(nonatomic, strong)UIPopoverController *popOver;

初始化内容视图:

    UIViewController *contentVC = [[UIViewController alloc] init];

上代码:

//  初始化方法
    self.popOver = [[UIPopoverController alloc] initWithContentViewController:contentVC];
    self.popOver.popoverContentSize = CGSizeMake(300, 600);
    self.popOver.delegate = self;

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(BarButtonAction:)];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"button" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor purpleColor];
    button.frame = CGRectMake(100, 100, 100, 50);
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *Abutton = [UIButton buttonWithType:UIButtonTypeSystem];
    [Abutton setTitle:@"Abutton" forState:UIControlStateNormal];
    Abutton.backgroundColor = [UIColor purpleColor];
    Abutton.frame = CGRectMake(300, 100, 100, 50);
    [self.view addSubview:Abutton];
    [Abutton addTarget:self action:@selector(AbuttonAction:) forControlEvents:UIControlEventTouchUpInside];

    //  点击数组内的视图, 弹出窗口不会消失
    self.popOver.passthroughViews = @[Abutton];

方法:

#pragma mark    - popOverDelegate
//  发生改变的时候
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing  _Nonnull *)view {
    NSLog(@"变形");
}
//  消失
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    NSLog(@"消失");
}
//  点击空白消失, 默认为YES
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
    NSLog(@"~消失");
    return YES;
}

- (void)buttonAction:(UIButton *)button {

    //  第二种显示方法
    [self.popOver presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

- (void)BarButtonAction:(UIBarButtonItem *)button {

    //  第一种显示方法
    [self.popOver presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22473次
    • 积分:1193
    • 等级:
    • 排名:千里之外
    • 原创:98篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条