对于UIPopoverController的解读(下)

在使用该控制器的时候,下面几个步骤是必须的:
1.UIPopoverController该控制器的内容必须由一个控制器提供;提供方式有三:

  • - (id)initWithContentViewController:(UIViewController *)viewController
  • @property (nonatomic, retain) UIViewController *contentViewController
  • - (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated

2.设置箭头方向:
@property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection

3.设置内容大小:
@property (nonatomic) CGSize popoverContentSize

备注:
<1>.如果从一个导航按钮处呈现,使用:
presentPopoverFromBarButtonItem:permittedArrowDirections:animated:;
如果要从一个视图出呈现,使用:
presentPopoverFromRect:inView:permittedArrowDirections:animated:

<2>.如果设备旋转以后,位置定位错误需要在父视图控制器的下面方法里面重新定位:
didRotateFromInterfaceOrientation:(在这个方法体里面重新设置rect)
然后再次调用:
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated

音乐播放示例:在二级界面进行初始化设置,为了便于第一级界面调用需要封装在一个函数里

- (void)showView:(UIButton*)button
{
    self.popView.popoverContentSize = CGSizeMake(100, 80);
    self.popView = [[UIPopoverController alloc]initWithContentViewController:self];
    [self.popView presentPopoverFromRect:CGRectMake(5, 5, 1, 1) inView:button
                permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    
}
一级界面按钮Button调用
- (void)playMusicBtn:(UIButton*)sender
{
    NSLog(@"the title is %@",title);
    if ([title isEqualToString:@"小青蛙\r"]) {
        self.playMusicController = [[playMusicViewController alloc]init];
        [self.playMusicController showView:sender];
    }
    
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值