在使用该控制器的时候,下面几个步骤是必须的:
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];
}
}