效果:

要想成功顯示一個(gè)UIPopoverController,需要經(jīng)過(guò)下列步驟:
由于UIPopoverController直接繼承自NSObject,不具備可視化的能力,因此UIPopoverController上面的內(nèi)容必須由另外一個(gè)繼承自UIViewController的控制器來(lái)提供,這個(gè)稱(chēng)為“內(nèi)容控制器”
設(shè)置內(nèi)容控制器有三種方法:
在初始化UIPopoverController的時(shí)候傳入一個(gè)內(nèi)容控制器
通過(guò)@property設(shè)置內(nèi)容控制器
animated可以指定設(shè)置內(nèi)容控制器時(shí)要不要帶有動(dòng)畫(huà)效果
1 @interfaceQCLocationButton() <UIPopoverControllerDelegate>2 3 {4 5 UIPopoverController *_popover;6 7 }
// 2.彈出popover(默認(rèn)特性:點(diǎn)擊popover之外的任何地方,popover都會(huì)隱藏) // 2.1.內(nèi)容 QCCityListViewController *cityList = [[QCCityListViewController alloc] init]; // 2.2.將內(nèi)容塞進(jìn)popover中 _popover = [[UIPopoverController alloc] initWithContentViewController:cityList];
顯示出來(lái)占據(jù)多少屏幕空間
設(shè)置內(nèi)容的尺寸有兩種方法:
1 // 2.3.設(shè)置popover的內(nèi)容尺寸2 _popover.popoverContentSize = CGSizeMake(320, 480);
從哪個(gè)地方冒出來(lái)
設(shè)置顯示的位置有兩種方法:
[pop presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[pop presentPopoverFromRect:button.frame inView:button.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
箭頭會(huì)指向某一個(gè)UIBarButtonItem
假如iPad的屏幕發(fā)生了旋轉(zhuǎn),UIPopoverController顯示的位置可能會(huì)改變,那么就需要重寫(xiě)控制器的某個(gè)方法
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
在上面的方法中重寫(xiě)設(shè)置UIPopoverController顯示的位置
1 // 2.5.展示popover2 // self.bounds --- self3 // self.frame --- self.superview4 [_popover presentPopoverFromRect:self.bounds inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
清澈Saup
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注