UIPopoverPresentationController 用法

前言

學(xué)習(xí)的時(shí)候遺漏了這個(gè)知識(shí)點(diǎn),最近在做一個(gè)類(lèi)微信牙瓢、支付寶的 "+"號(hào)彈出浮窗的功能,發(fā)現(xiàn)了這個(gè)好用的東西~ 做個(gè)記錄方便日后查閱
NS_CLASS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED //iOS8之后可用 @interface UIPopoverPresentationController : UIPresentationController

基本使用


效果圖

點(diǎn)擊pop按鈕后觸發(fā)的Action代碼如下

/* Present the view controller using the popover style. */

// 每個(gè)viewController,都有一個(gè)modalPresentationStyle屬性
TestViewController * test = [[TestViewController alloc]init];
test.preferredContentSize = CGSizeMake(300, 200);//設(shè)置浮窗的寬高
test.modalPresentationStyle = UIModalPresentationPopover;
 
 /* Get the popover presentation controller and configure it. */

//獲取TestViewController的UIPopoverPresentationController
UIPopoverPresentationController * popover = [test popoverPresentationController];
popover.delegate = self;
popover.permittedArrowDirections = UIPopoverArrowDirectionUp;//設(shè)置箭頭位置
popover.sourceView = self.popViewButton;//設(shè)置目標(biāo)視圖
popover.sourceRect = self.popViewButton.bounds;//彈出視圖顯示位置
popover.backgroundColor = [UIColor redColor];//設(shè)置彈窗背景顏色(效果圖里紅色區(qū)域)
[self presentViewController:test animated:YES completion:nil];

** UIPopoverPresentationControllerDelegate代理方法 **

/* 
For iOS8.0, the only supported adaptive presentation styles 
are UIModalPresentationFullScreen and UIModalPresentationOverFullScreen. */
// 設(shè)置 浮窗彈窗的推出樣式床三,效果圖中設(shè)置style為UIModalPresentationNone
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:
(UIPresentationController *)controller;

// Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the
// dismissal of the view.
// 點(diǎn)擊浮窗背景popover controller是否消失
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;

// Called on the delegate when the user has taken action to dismiss the popover. This is not called when the popover is dimissed programatically.
// 浮窗消失時(shí)調(diào)用
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;


防止點(diǎn)擊UIPopoverController區(qū)域外消失

默認(rèn)情況下
只要UIPopoverController顯示在屏幕上一罩,UIPopoverController背后的所有控件默認(rèn)是不能跟用戶(hù)進(jìn)行正常交互的
點(diǎn)擊UIPopoverController區(qū)域外的控件,UIPopoverController默認(rèn)會(huì)消失
要想點(diǎn)擊UIPopoverController區(qū)域外的控件時(shí)不讓UIPopoverController消失撇簿,解決辦法是設(shè)置passthroughViews屬性
@property (nonatomic, copy) NSArray *passthroughViews;
這個(gè)屬性是設(shè)置當(dāng)UIPopoverController顯示出來(lái)時(shí)聂渊,哪些控件可以繼續(xù)跟用戶(hù)進(jìn)行正常交互。這樣的話四瘫,點(diǎn)擊區(qū)域外的控件就不會(huì)讓UIPopoverController消失了

寫(xiě)在最后


官網(wǎng)對(duì)UIPopoverPresentationController介紹
Human Interface Guidelines——Popovers

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末汉嗽,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子找蜜,更是在濱河造成了極大的恐慌饼暑,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件洗做,死亡現(xiàn)場(chǎng)離奇詭異弓叛,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)诚纸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)撰筷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人畦徘,你說(shuō)我怎么就攤上這事毕籽。” “怎么了井辆?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵关筒,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我杯缺,道長(zhǎng)蒸播,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任萍肆,我火速辦了婚禮廉赔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘匾鸥。我一直安慰自己蜡塌,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布勿负。 她就那樣靜靜地躺著馏艾,像睡著了一般。 火紅的嫁衣襯著肌膚如雪奴愉。 梳的紋絲不亂的頭發(fā)上琅摩,一...
    開(kāi)封第一講書(shū)人閱讀 51,598評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音锭硼,去河邊找鬼房资。 笑死,一個(gè)胖子當(dāng)著我的面吹牛檀头,可吹牛的內(nèi)容都是我干的轰异。 我是一名探鬼主播岖沛,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼搭独!你這毒婦竟也來(lái)了婴削?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤牙肝,失蹤者是張志新(化名)和其女友劉穎唉俗,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體配椭,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡虫溜,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了股缸。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片衡楞。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖乓序,靈堂內(nèi)的尸體忽然破棺而出寺酪,到底是詐尸還是另有隱情,我是刑警寧澤替劈,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布寄雀,位于F島的核電站,受9級(jí)特大地震影響陨献,放射性物質(zhì)發(fā)生泄漏盒犹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一眨业、第九天 我趴在偏房一處隱蔽的房頂上張望急膀。 院中可真熱鬧,春花似錦龄捡、人聲如沸卓嫂。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)晨雳。三九已至,卻和暖如春奸腺,著一層夾襖步出監(jiān)牢的瞬間餐禁,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工突照, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留帮非,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像末盔,于是被迫代替她去往敵國(guó)和親筑舅。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容