国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > iOS > 正文

iOS-iPad里有趣的UIPopoverController

2019-11-14 20:43:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 

效果:

 

1.對(duì)UipopoverController的簡(jiǎn)單概述                 

1.1
UIPopoverController是在iPad開(kāi)發(fā)中常用的一個(gè)組件(在iPhone上不允許使用),使用非常簡(jiǎn)單
 
1.2
UIPopoverController也是一個(gè)控制器,跟其他控制器不一樣的是,它直接繼承自NSObject,并非繼承自UIViewController
 
1.3
它只占用部分屏幕空間來(lái)呈現(xiàn)信息,而且顯示在屏幕的最前面,(如上圖所示)
 

 

2.UIPopoverController實(shí)現(xiàn)                       

要想成功顯示一個(gè)UIPopoverController,需要經(jīng)過(guò)下列步驟:

2.2設(shè)置內(nèi)容控制器                                         

由于UIPopoverController直接繼承自NSObject,不具備可視化的能力,因此UIPopoverController上面的內(nèi)容必須由另外一個(gè)繼承自UIViewController的控制器來(lái)提供,這個(gè)稱(chēng)為“內(nèi)容控制器”

 

設(shè)置內(nèi)容控制器有三種方法:

- (id)initWithContentViewController:(UIViewController *)viewController;

在初始化UIPopoverController的時(shí)候傳入一個(gè)內(nèi)容控制器

 

@PRoperty (nonatomic, retain) UIViewController *contentViewController;

通過(guò)@property設(shè)置內(nèi)容控制器

 

- (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated;

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];

 

 

2.3設(shè)置內(nèi)容的尺寸                                         

顯示出來(lái)占據(jù)多少屏幕空間

設(shè)置內(nèi)容的尺寸有兩種方法:

@property (nonatomic) CGSize popoverContentSize;

 

- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated;
 
 
1  // 2.3.設(shè)置popover的內(nèi)容尺寸2     _popover.popoverContentSize = CGSizeMake(320, 480);

 

 

2.4設(shè)置顯示的位置                                           

從哪個(gè)地方冒出來(lái)

設(shè)置顯示的位置有兩種方法:

- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;
這個(gè)方法需要傳入一個(gè)CGRecView的,也就是說(shuō)CGRect以View的左上角為坐標(biāo)原點(diǎn)(0, 0)
 
這個(gè)CGRect的值是相對(duì)于這個(gè)第一種方法是:

[pop presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

(2)第二種方法是:

[pop presentPopoverFromRect:button.frame inView:button.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

 

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated;

箭頭會(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  


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 陇南市| 固始县| 娱乐| 福贡县| 屏东县| 绩溪县| 辽阳县| 乌兰浩特市| 陆丰市| 郸城县| 霍林郭勒市| 庄浪县| 绥滨县| 凌云县| 迁西县| 福建省| 简阳市| 独山县| 武冈市| 太和县| 庆安县| 格尔木市| 庄浪县| 乌兰县| 聊城市| 连云港市| 祁门县| 广西| 武城县| 探索| 嘉荫县| 徐闻县| 城市| 龙海市| 昭苏县| 陵川县| 顺平县| 安乡县| 元氏县| 祁东县| 清河县|