Flutter PIP 插件 ---- 為iOS 重構PipController, Demo界面,更好的體驗

接上文 Flutter PIP 插件 ---- 新增PipActivity,Android 11以下支持自動進入PIP Mode

項目地址 PIP, pub.dev也已經同步發布 pip 0.0.3,你的加星和點贊,將是我繼續改進最大的動力

在之前的界面設計中,還原動畫等體驗一直不太好,遂優化一下,現在體驗效果看起來更好了,
唯一一個還沒搞定的是應用內還原的動畫,應用內還原的時候,有一個從小到達逐漸拉伸的效果,猜測可能是和圖片的渲染有關?有大佬能指點一二不?
請添加圖片描述

不再獲取PipViewController

前面也講到這個比較危險,雖然多方求證似乎也沒什么,但還是怕,所以改成查找PipWindow,并在pictureInPictureControllerDidStartPictureInPicture通知中把自渲染View添加到rootView中去

- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {PIP_LOG(@"pictureInPictureControllerDidStartPictureInPicture");#if USE_PIP_VIEW_CONTROLLER// if you use the pipViewController, you must call this every time to bring// the content view to the front, otherwise the content view will not be// visible and covered by the pip host view.if (_pipViewController) {[_pipViewController.view bringSubviewToFront:_contentView];}
#else// TODO @sylar: check if this is the best way to do this, what will happen if// we have multiple windows? what if the root view controller is not a// UIViewController?UIWindow *window = [[UIApplication sharedApplication] windows].firstObject;if (window) {UIViewController *rootViewController = window.rootViewController;UIView *superview = rootViewController.view.superview;[self insertContentViewIfNeeded:superview];} else {PIP_LOG(@"pictureInPictureControllerDidStartPictureInPicture: window is nil");[_pipStateDelegate pipStateChanged:PipStateFailederror:@"Can not find the pip window"];return;}
#endif_isPipActived = YES;[_pipStateDelegate pipStateChanged:PipStateStarted error:nil];
}

遺留項是,這個查找PipWindow的方法靠不靠譜?有其他方法但是看起來也不靠譜

不再每次都將自渲染UIView從PipWindow移除

觀察到一個現象是,如果是依賴PipViewController在 pictureInPictureControllerWillStartPictureInPicture 中添加UIView,還必須得在 pictureInPictureControllerDidStartPictureInPicture 中調用一次 bringSubviewToFront,否則的話你會比系統自動添加的View早添加,導致你的層級在下面;改用通過獲取PipWindow方式后,就不用在bringSubviewToFront,因為不是一個parent了。
在這里插入圖片描述
另外一些場景下可能會創建一個懸空的UIView用來做渲染,這樣的話我們就沒必要每次都把他從PipWindow上移除還原到父parent上,可以在PipWindow顯示的一瞬間就立即看到渲染的內容

- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {PIP_LOG(@"pictureInPictureControllerDidStopPictureInPicture");// restore the content view in// pictureInPictureControllerDidStopPictureInPicture will have the best user// experience.[self restoreContentViewIfNeeded];_isPipActived = NO;[_pipStateDelegate pipStateChanged:PipStateStopped error:nil];
}- (void)restoreContentViewIfNeeded {if (_contentView == nil) {PIP_LOG(@"restoreContentViewIfNeeded: contentView is nil");return;}// do not restore the content view if the original parent view is nil or// the content view is already in the original parent view.// keep the content view in the pip view controller will make the user// experience better, the pip content view will be visible immediately.if (_contentViewOriginalParentView == nil ||[_contentViewOriginalParentView.subviews containsObject:_contentView]) {PIP_LOG(@"restoreContentViewIfNeeded: _contentViewOriginalParentView is nil or "@"contentView is already in the original parent view");return;}[_contentView removeFromSuperview];PIP_LOG(@"restoreContentViewIfNeeded: contentView is removed from the original "@"parent view");if (_contentViewOriginalParentView != nil) {// in case that the subviews of _contentViewOriginalParentView has been// changed, we need to get the real index of the content view.NSUInteger trueIndex = MIN(_contentViewOriginalParentView.subviews.count,_contentViewOriginalIndex);[_contentViewOriginalParentView insertSubview:_contentViewatIndex:trueIndex];PIP_LOG(@"restoreContentViewIfNeeded: contentView is added to the original "@"parent view "@"at index: %lu",trueIndex);// restore the original frame_contentView.frame = _contentViewOriginalFrame;// restore the original constraints[_contentView removeConstraints:_contentView.constraints.copy];[_contentView addConstraints:_contentViewOriginalConstraints];// restore the original translatesAutoresizingMaskIntoConstraints_contentView.translatesAutoresizingMaskIntoConstraints =_contentViewOriginalTranslatesAutoresizingMaskIntoConstraints;// restore the original parent view[_contentViewOriginalParentViewremoveConstraints:_contentViewOriginalParentView.constraints.copy];[_contentViewOriginalParentViewaddConstraints:_contentViewOriginalParentViewConstraints];}
}

支持動態設置PipWindow窗口大小

這個沒什么好說的,修改創建contentSource的時候的sampleBufferDisplayer的大小就可以動態修改PipWindow窗口大小,判斷各種對象都已經有了的話就只修改大小而不用重新創建controller就行了

if (options.preferredContentSize.width > 0 &&options.preferredContentSize.height > 0) {[_pipViewupdateFrameSize:CGSizeMake(options.preferredContentSize.width,options.preferredContentSize.height)];
}

重要的事情說三遍

項目地址 PIP, pub.dev也已經同步發布 pip 0.0.3,你的加星和點贊,將是我繼續改進最大的動力

項目地址 PIP, pub.dev也已經同步發布 pip 0.0.3,你的加星和點贊,將是我繼續改進最大的動力

項目地址 PIP, pub.dev也已經同步發布 pip 0.0.3,你的加星和點贊,將是我繼續改進最大的動力

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/905404.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/905404.shtml
英文地址,請注明出處:http://en.pswp.cn/news/905404.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Ansible】之inventory主機清單

前言 本篇博客主要解釋Ansible主機清單的相關配置知識 一、inventory 主機清單 Inventory支持對主機進行分組,每個組內可以定義多個主機,每個主機都可以定義在任何一個或多個主機組內。 如果是名稱類似的主機,可以使用列表的方式表示各個主機…

基于幾何布朗運動的股價預測模型構建與分析

基于幾何布朗運動的股價預測模型構建與分析 摘要 本文建立基于幾何布朗運動的股價預測模型,結合極大似然估計與蒙特卡洛模擬,推導股價條件概率密度函數并構建動態預測區間。實證分析顯示模型在標普500指數預測中取得89%的覆蓋概率,波動率估…

【前端】【JavaScript】【總復習】四萬字詳解JavaScript知識體系

JavaScript 前端知識體系 📌 說明:本大綱從基礎到高級、從語法到應用、從面試到實戰,分層級講解 JavaScript 的核心內容。 一、JavaScript 基礎語法 1.1 基本概念 1.1.1 JavaScript 的發展史與用途 1. 發展簡史 1995 年:JavaS…

[Java實戰]Spring Boot 3 整合 Apache Shiro(二十一)

[Java實戰]Spring Boot 3 整合 Apache Shiro(二十一) 引言 在復雜的業務系統中,安全控制(認證、授權、加密)是核心需求。相比于 Spring Security 的重量級設計,Apache Shiro 憑借其簡潔的 API 和靈活的擴…

PyTorch API 6 - 編譯、fft、fx、函數轉換、調試、符號追蹤

文章目錄 torch.compiler延伸閱讀 torch.fft快速傅里葉變換輔助函數 torch.func什么是可組合的函數變換?為什么需要可組合的函數變換?延伸閱讀 torch.futurestorch.fx概述編寫轉換函數圖結構快速入門圖操作直接操作計算圖使用 replace_pattern() 進行子圖…

可觀測性方案怎么選?SelectDB vs Elasticsearch vs ClickHouse

可觀測性(Observability)是指通過系統的外部輸出數據,推斷其內部狀態的能力。可觀測性平臺通過采集、存儲、可視化分析三大可觀測性數據:日志(Logging)、鏈路追蹤(Tracing)和指標&am…

機器人廚師上崗!AI在餐飲界掀起新風潮!

想要了解人工智能在其他各個領域的應用,可以查看下面一篇文章 《AI在各領域的應用》 餐飲業是與我們日常生活息息相關的行業,而人工智能(AI)正在迅速改變這個傳統行業的面貌。從智能點餐到食材管理,再到個性化推薦&a…

Linux動態庫靜態庫總結

靜態庫生成 g -c mylib.cpp -o mylib.o ar rcs libmylib.a mylib.o 動態庫生成 g -fPIC -shared mylib.cpp -o libmylib.so -fPIC:生成位置無關代碼(Position-Independent Code),對動態庫必需。 庫文件使用: 靜態庫&…

通過user-agent來源判斷阻止爬蟲訪問網站,并防止生成[ error ] NULL日志

一、TP5.0通過行為&#xff08;Behavior&#xff09;攔截爬蟲并避免生成 [ error ] NULL 錯誤日志 1. 創建行為類&#xff08;攔截爬蟲&#xff09; 在 application/common/behavior 目錄下新建BlockBot.php &#xff0c;用于識別并攔截爬蟲請求&#xff1a; <?php name…

OpenHarmony平臺驅動開發(十五),SDIO

OpenHarmony平臺驅動開發&#xff08;十五&#xff09; SDIO 概述 功能簡介 SDIO&#xff08;Secure Digital Input and Output&#xff09;由SD卡發展而來&#xff0c;與SD卡統稱為MMC&#xff08;MultiMediaCard&#xff09;&#xff0c;二者使用相同的通信協議。SDIO接口…

使用FastAPI和React以及MongoDB構建全棧Web應用03 全棧開發快速入門

一、什么是全棧開發 A full-stack web application is a complete software application that encompasses both the frontend and backend components. It’s designed to interact with users through a web browser and perform actions that involve data processing and …

Coco AI 開源應用程序 - 搜索、連接、協作、您的個人 AI 搜索和助手,都在一個空間中。

一、軟件介紹 文末提供程序和源碼下載 Coco AI 是一個統一的搜索平臺&#xff0c;可將您的所有企業應用程序和數據&#xff08;Google Workspace、Dropbox、Confluent Wiki、GitHub 等&#xff09;連接到一個功能強大的搜索界面中。此存儲庫包含為桌面和移動設備構建的 Coco 應…

CSS經典布局之圣杯布局和雙飛翼布局

目標&#xff1a; 中間自適應&#xff0c;兩邊定寬&#xff0c;并且三欄布局在一行展示。 圣杯布局 實現方法&#xff1a; 通過float搭建布局margin使三列布局到一行上relative相對定位調整位置&#xff1b; 給外部容器添加padding&#xff0c;通過相對定位調整左右兩列的…

# 實時英文 OCR 文字識別:從攝像頭到 PyQt5 界面的實現

實時英文 OCR 文字識別&#xff1a;從攝像頭到 PyQt5 界面的實現 引言 在數字化時代&#xff0c;文字識別技術&#xff08;OCR&#xff09;在眾多領域中發揮著重要作用。無論是文檔掃描、車牌識別還是實時視頻流中的文字提取&#xff0c;OCR 技術都能提供高效且準確的解決方案…

<C#>log4net 的配置文件配置項詳細介紹

log4net 是一個功能強大的日志記錄工具&#xff0c;通過配置文件可以靈活地控制日志的輸出方式、格式、級別等。以下是對 log4net 配置文件常見配置項的詳細介紹&#xff1a; 根元素 <log4net> 這是 log4net 配置文件的根元素&#xff0c;所有配置項都要包含在該元素內…

編譯docker版openresty

使用alpine為基礎鏡像 # 使用Alpine作為基礎鏡像 FROM alpine:3.18# 替換為阿里云鏡像源&#xff0c;并安裝必要的依賴 RUN sed -i s|https://dl-cdn.alpinelinux.org/alpine|https://mirrors.aliyun.com/alpine|g /etc/apk/repositories && \apk add --no-cache \bui…

conda 輸出指定python環境的庫 輸出為 yaml文件

conda 輸出指定python環境的庫 輸出為 yaml文件。 有時為了項目部署&#xff0c;需要匹配之前的python環境&#xff0c;需要輸出對應的python依賴庫。 假設你的目標環境名為 myenv&#xff0c;運行以下命令&#xff1a; conda env export -n myenv > myenv_environment.ym…

[Java][Leetcode middle] 121. 買賣股票的最佳時機

暴力循環 總是以最低的價格買入&#xff0c;以最高的價格賣出: 例如第一天買入&#xff0c;去找剩下n-1天的最高價格&#xff0c;計算利潤 依次計算到n-1天買入&#xff1b; 比較上述利潤 // 運行時間超時。 o(n^2)public int maxProfit1(int[] prices) {int profit 0;for (i…

克隆虛擬機組成集群

一、克隆虛擬機 1. 準備基礎虛擬機 確保基礎虛擬機已安裝好操作系統&#xff08;如 Ubuntu&#xff09;、Java 和 Hadoop。關閉防火墻并禁用 SELinux&#xff08;如適用&#xff09;&#xff1a; bash sudo ufw disable # Ubuntu sudo systemctl disable firewalld # CentO…

記錄一次使用thinkphp使用PhpSpreadsheet擴展導出數據,解決身份證號碼等信息科學計數法問題處理

PhpSpreadsheet官網 PhpSpreadsheet安裝 composer require phpoffice/phpspreadsheet使用composer安裝時一定要下載php對應的版本&#xff0c;下載之前使用php -v檢查當前php版本 簡單使用 <?php require vendor/autoload.php;use PhpOffice\PhpSpreadsheet\Spreadshee…