iOS實(shí)現(xiàn)Pad上菜單彈出界面
前言:
此種方式實(shí)現(xiàn)只適用于pad開發(fā),在iPhone上是無效的。
實(shí)現(xiàn):
比如我在界面上有一個(gè)按鈕,點(diǎn)擊按鈕,在按鈕旁邊彈出一個(gè)Pop框。
1、按鈕點(diǎn)擊事件
btn.addTarget(self, action: #selector(self.popShow), for: .touchUpInside)
2、事件處理
/// 彈框選擇條件 /// /// - Parameter sender: <#sender description#> func popShow(sender:UIButton) { let popVC = ExerciseLibPopViewController() popVC.modalPresentationStyle = .popover popVC.preferredContentSize = CGSize(width: 111, height: 2*44.0) popVC.popoverPresentationController?.sourceView = sender popVC.popoverPresentationController?.sourceRect = sender.bounds popVC.popoverPresentationController?.delegate = self self.present(popVC, animated: true, completion: nil) }
其中,popover類有一個(gè)代理:
extension xxxViewController : UIPopoverPresentationControllerDelegate { func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool { print("popoverPresentationControllerShouldDismissPopover") // 處理你要做的 return true } }
類似效果如下:
最后小Tips:
1、如果這里需要把上圖的小箭頭背景色改成其他顏色(和里面顏色一致)
加上這句即可:
popVC.popoverPresentationController?.backgroundColor = UIColor.white
2、如果想改變彈出框位置,修改這句即可:
// 將bounds改成CGRect(x,y,w,h)自己構(gòu)造參數(shù) popVC.popoverPresentationController?.sourceRect = sender.bounds
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS10 widget實(shí)現(xiàn)3Dtouch 彈出菜單
- iOS開發(fā)中ViewController的頁(yè)面跳轉(zhuǎn)和彈出模態(tài)
- android底部彈出iOS7風(fēng)格對(duì)話選項(xiàng)框(QQ對(duì)話框)--第三方開源之IOS_Dialog_Library
- iOS自定義提示彈出框?qū)崿F(xiàn)類似UIAlertView的效果
- 高仿IOS的Android彈出框
- iOS仿簡(jiǎn)書、淘寶等App的View彈出效果
- Android仿IOS底部彈出對(duì)話框
- iOS中自定義彈出pickerView效果(DEMO)
- IOS MenuViewController實(shí)現(xiàn)彈出菜單效果
相關(guān)文章
iOS 實(shí)現(xiàn)簡(jiǎn)單的加載等待動(dòng)畫示例(思路與實(shí)現(xiàn))
本篇文章主要介紹了iOS 實(shí)現(xiàn)簡(jiǎn)單的加載等待動(dòng)畫示例(思路與實(shí)現(xiàn)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05iOS仿微信添加標(biāo)簽效果(shape實(shí)現(xiàn))
微信做的用戶體驗(yàn)非常棒,今天用shape來做下微信的標(biāo)簽功能,非常不錯(cuò),對(duì)ios 仿微信添加標(biāo)簽功能感興趣的朋友一起看看吧2016-11-11IOS 獲取網(wǎng)絡(luò)圖片大小實(shí)例詳解
這篇文章主要介紹了IOS 獲取網(wǎng)絡(luò)圖片大小實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06iOS?GCD之dispatch_group_enter和dispatch_group_leave使用
這篇文章主要為大家介紹了iOS?GCD之dispatch_group_enter和dispatch_group_leave使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03