您好,登錄后才能下訂單哦!
這篇文章主要介紹“iOS閱讀器與直播的控件重疊滑動(dòng)交互怎么實(shí)現(xiàn)”,在日常操作中,相信很多人在iOS閱讀器與直播的控件重疊滑動(dòng)交互怎么實(shí)現(xiàn)問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”iOS閱讀器與直播的控件重疊滑動(dòng)交互怎么實(shí)現(xiàn)”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
進(jìn)行一個(gè)閱讀器項(xiàng)目的開發(fā)時(shí),遇到了一個(gè)問題,
需要在點(diǎn)擊綠色區(qū)域時(shí)彈出一個(gè)菜單,因此在該區(qū)域加了一個(gè)View,
然而,當(dāng)在這個(gè)區(qū)域滑動(dòng)時(shí),滑動(dòng)手勢(shì)被綠色區(qū)域攔截,手勢(shì)無法傳遞到下面的 UIPageViewController 的 View 上
描述
閱讀器上方,搖啊搖,出來一個(gè)綠色的菜單
要求可以點(diǎn),也可以拖動(dòng)
拖動(dòng)是下方 UIPageViewController
的事情。
手勢(shì)被綠色視圖擋住了,需要一個(gè)透?jìng)?/p>
思路:
把綠色視圖的 hitTest View ,交給正在看的閱讀器,那一頁
這樣拖動(dòng)綠色視圖,也可以滑動(dòng)
class GreenView: UIView{ override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { var afterThat = next while afterThat != nil{ if let tmp = afterThat as? ViewController{ if let target = tmp.pagedController.viewControllers?.first{ return target.view } } else{ afterThat = afterThat?.next } } return nil } }
同時(shí)要捕捉綠色視圖的點(diǎn)擊事件,
通過閱讀頁面的視圖控制器,來捕捉
class ContentCtrl: UIViewController { override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { if let touch = touches.first, greenFrame.contains(touch.location(in: view)){ NotificationCenter.default.post(name: .hitGreen, object: nil) } } }
用戶在直播室,吃瓜
來了一條重要的消息,必須要用戶處理,
用戶退出直播室,也要展示,
同時(shí)不影響用戶給主播送禮物
如上圖,用戶看到消息,也可以滑動(dòng)閱讀器
( 在消息的區(qū)域,滑動(dòng)無效 )
思路肯定是 window,
脫離控制器,也能展示
實(shí)現(xiàn)一,創(chuàng)建新的 window
class MsgWindow: UIWindow { init() { let originX: CGFloat = 50 let width = UIScreen.main.bounds.width - originX * 2 // 窗口大小固定 super.init(frame: CGRect(x: originX, y: 100, width: width, height: 150)) clipsToBounds = true layer.cornerRadius = 8 backgroundColor = UIColor.cyan // 提升 zIndex windowLevel = UIWindow.Level.statusBar + 100 isHidden = true } func show(){ // 展現(xiàn)的必要配置 if windowScene == nil, let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene{ windowScene = scene } isHidden = false } }
實(shí)現(xiàn) 2,使用老的 window 和 View
class MsgView: UIView { init() { let originX: CGFloat = 50 let width = UIScreen.main.bounds.width - originX * 2 super.init(frame: CGRect(x: originX, y: 100, width: width, height: 150)) clipsToBounds = true layer.cornerRadius = 8 backgroundColor = UIColor.cyan // 設(shè)置 z Index layer.zPosition = CGFloat.infinity isHidden = true } func show(){ // 找到 key window, // 把視圖,添加上去 let scenes = UIApplication.shared.connectedScenes for sce in scenes{ if let windowScene = sce as? UIWindowScene, windowScene.activationState == .foregroundActive , let win = windowScene.windows.first{ isHidden = false win.addSubview(self) return } } } }
用戶在直播室,吃瓜
來了一條重要的消息,必須要用戶處理,
用戶退出直播室,也要展示,
同時(shí)不影響用戶給主播送禮物
這條消息,很長(zhǎng)
( 在消息的區(qū)域,滑動(dòng)有效 )
思路, 擴(kuò)展場(chǎng)景 2 的第 2 種實(shí)現(xiàn)
一句話,限定了響應(yīng)范圍,
重寫了 func point(inside
class MsgView: UIView { let rect : CGRect = { let originX: CGFloat = 50 let width = UIScreen.main.bounds.width - originX * 2 return CGRect(x: originX, y: 100, width: width, height: 400) }() let btnRect = CGRect(x: 10, y: 10, width: 50, height: 50) init() { super.init(frame: rect) clipsToBounds = true layer.cornerRadius = 8 backgroundColor = UIColor.clear layer.zPosition = CGFloat.infinity isHidden = true let bg = UIView(frame: CGRect(origin: .zero, size: rect.size)) bg.backgroundColor = UIColor.cyan bg.alpha = 0.5 addSubview(bg) let btn = UIButton(frame: btnRect) btn.backgroundColor = UIColor.red btn.layer.cornerRadius = 8 btn.backgroundColor = UIColor.white addSubview(btn) btn.addTarget(self, action: #selector(hide), for: .touchUpInside) } @objc func hide(){ isHidden = true } override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { return btnRect.contains(point) } }
到此,關(guān)于“iOS閱讀器與直播的控件重疊滑動(dòng)交互怎么實(shí)現(xiàn)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。