iPad

iPad开发中的弹框接口UIPopoverController

2016-11-01  本文已影响82人  黑羽肃霜

iPad特有的弹框接口

UIPopoverController用来实现弹框,有两种方式。
UIPopoverController是一个弹出框,弹出的内容,是一个UIViewController

直接通过代码创建

    UIStoryboard *stb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    DIYViewCtrl *vc   = [stb instantiateViewControllerWithIdentifier:@"DIY"];
    
    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:vc];
    [pop presentPopoverFromRect:self.button.bounds
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionUp
                       animated:YES];
-(void)presentPopoverFromRect:(CGRect)rect
                       inView:(UIView *)view
     permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
                     animated:(BOOL)animated;
1
* rectinView如上提示
* permittedArrowDirections 表示弹出框的箭头方向。比如说 directionup,就表示从当前这个锚点向下弹出

直接在storyboard上通过拖曳添加

直接上图说明

混合使用

我们可以在Storyboard中去新建一个1x1大小的UIView作为弹框的锚点供代码创建时使用。
代码创建会繁琐一些,但是我们在需要传递那个popover所容纳的viewcontroller时可以传递我们需要的消息给viewcontroller。这一点是用storyboard无法实现的。
除此之外,简单的创建弹框提示板,还是可以直接用故事板做的。

上一篇 下一篇

猜你喜欢

热点阅读