日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)IOS教程:為你的MacApp選擇一個用戶界面習慣用法

概覽

用 Mac Catalyst 構建的 Mac App 可以使用 UIUserInterfaceIdiom.padUIUserInterfaceIdiom.mac 用戶界面習慣用法運行。要選擇 App 運行時的習慣用法,請在 Xcode 項目中打開 Mac Catalyst,然后從以下選項中進行選擇:

成都創(chuàng)新互聯(lián)專注于市中企業(yè)網(wǎng)站建設,成都響應式網(wǎng)站建設公司,商城網(wǎng)站建設。市中網(wǎng)站建設公司,為市中等地區(qū)提供建站服務。全流程按需求定制設計,專業(yè)設計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務

Scale Interface to Match iPad (縮放界面以匹配 iPad)

使用 UIUserInterfaceIdiom.pad 習慣用法運行你的 App。選擇這個選項可以快速將你的 iPad App 移植到 Mac。

Optimize Interface for Mac (針對 Mac 優(yōu)化界面)

使用 UIUserInterfaceIdiom.mac 習慣用法運行你的 App。選擇這個選項可以顯示外觀和行為與 AppKit 中控件相似的控件。

注釋

要進一步了解如何在 Xcode 項目中打開 Mac Catalyst,請參閱“為你的 iPad App 創(chuàng)建 Mac 版本”。

首先從 iPad 習慣用法開始

默認情況下,Xcode 會在你打開 Mac Catalyst 后選擇“Scale Interface to Match iPad”(縮放界面以匹配 iPad)。這個選項提供了一種將 iPad App 移植到 Mac 的簡化方法。你的 Mac App 會使用 UIUserInterfaceIdiom.pad 習慣用法運行,這時 macOS 會縮放 App 的用戶界面以匹配 Mac 顯示環(huán)境,同時保留類似 iPad 上的外觀和視圖指標。

在測試你的 App 時,你可能會發(fā)現(xiàn),采用外觀和行為與 AppKit 中控件相似的控件,或是提供更清晰的文本,可以提升你 App 的用戶體驗。如果是這樣,請選擇“Optimize Interface for Mac”(針對 Mac 優(yōu)化界面) 以更改為 UIUserInterfaceIdiom.mac。但是,選擇這個選項可能需要你對 App 進行其他更改。

更新你的 App 以使用 Mac 習慣用法

選擇“Optimize Interface for Mac”(針對 Mac 優(yōu)化界面) 意味著你的 Mac App 會使用 UIUserInterfaceIdiom.mac 用戶界面習慣用法運行,這會更改你 App 的界面。一些控件的尺寸和外觀會改變,而與它們的交互體驗和使用 AppKit 控件時完全相同。例如,UIButton 的外觀與 NSButton 完全相同。

由于系統(tǒng)會在用戶界面習慣用法為 UIUserInterfaceIdiom.mac 時適當?shù)卦O置控件尺寸,因此不再需要縮放你 App 的界面以匹配 Mac 屏幕尺寸。屏幕點的尺寸與基于 AppKit 的 App 中完全相同。但是,如果你的 App 采用硬編碼尺寸或使用尺寸適用于 iPad 的圖像,你可能需要更新 App 以適應尺寸差異。你可能還需要調(diào)整自動布局約束。

一些控件提供了其他設置,可幫助你實現(xiàn)更像 Mac 的外觀。例如,當習慣用法為 UIUserInterfaceIdiom.mac 時,通過將 preferredStyle 設置為 UISwitch.Style.checkbox,可以使 UISwitch 顯示為復選框。然后,將 title 設置為復選框的文本。

 let showFavoritesAtTop = UISwitch() showFavoritesAtTop.preferredStyle = .checkbox if traitCollection.userInterfaceIdiom == .mac {  showFavoritesAtTop.title = "Always show favorite recipes at the top" }

UIPageControl、UIRefreshControlUIStepper 不適用于采用 Mac 習慣用法運行的 App。如果你嘗試在視圖中顯示這些控件,你的 App 會拋出異常。當用戶界面習慣用法為 UIUserInterfaceIdiom.mac 時,請用相似的功能替換這些控件。例如,用“刷新”菜單項替換 UIRefreshControl,方法是創(chuàng)建一個標題為“Refresh”且使用鍵盤快捷鍵 Command-R 的 UIKeyCommand 對象。然后,將這一命令添加到 App 的菜單系統(tǒng)中。有關更多信息,請參閱“向菜單欄和用戶界面中添加菜單和快捷鍵”。

確定當前的用戶界面習慣用法

要確定你的 App 是不是在使用 Mac 習慣用法運行,請將 userInterfaceIdiom 屬性的值與 UIUserInterfaceIdiom.mac 進行比較。當比較結果為 true 時,你可以針對 Mac 量身定制 App 的行為,例如,顯示一個不同的子視圖。

 let childViewController: UIViewController if traitCollection.userInterfaceIdiom == .mac {  childViewController = MacOptimizedChildViewController() } else {  childViewController = ChildViewController() } addChild(childViewController) childViewController.view.frame = view.bounds view.addSubview(childViewController.view) childViewController.didMove(toParent: self)

設置首選行為風格

采用 Mac 習慣用法時,一些控件 (例如 UIButtonUISlider) 的外觀與其對應 AppKit 控件完全相同。但是,在一些情況下,你可能希望在 App 中利用 Mac 習慣用法,而同時保留控件的 iPad 外觀和行為。例如,讓 iPad App 顯示帶有自定拇指圖像的滑塊。默認情況下,當用戶界面習慣用法為 UIUserInterfaceIdiom.mac 時,用 Mac Catalyst 構建的 Mac 版 App 會顯示一個標準的 macOS 滑塊。

要在 App 的 iPad 和 Mac 版本中提供一致外觀的滑塊,請將該滑塊的 preferredBehavioralStyle 設置為 UIBehavioralStyle.pad。設置這種行為風格后,滑塊的行為方式就會像用戶界面習慣用法是 UIUserInterfaceIdiom.pad 時一樣,即使該 App 使用的是 Mac 習慣用法也是如此。

請記住,當 App 使用 Mac 習慣用法時,macOS 不會縮放 App 界面,因此,即使首選行為風格是 UIBehavioralStyle.pad,你可能也需要更新你的 App 以適應尺寸差異。例如,帶有自定拇指圖像的滑塊在 Mac App 中與在 iPad App 中可能需要不同尺寸的圖像。

 let slider = UISlider() slider.minimumValue = 0 slider.maximumValue = 1 slider.value = 0.5 slider.preferredBehavioralStyle = .pad   if slider.traitCollection.userInterfaceIdiom == .mac {  slider.setThumbImage(#imageLiteral(resourceName: "customSliderThumbMac"), for: .normal) } else {  slider.setThumbImage(#imageLiteral(resourceName: "customSliderThumb"), for: .normal) }

當行為風格為 UIBehavioralStyle.mac 時,UIButtonUISlider 的一些屬性和方法在 Mac 習慣用法中不受支持,調(diào)用它們時會拋出異常;例如,為除 normal 以外的任何控件狀態(tài)設置按鈕的標題或圖像,以及設置滑塊的拇指圖像、最小或最大軌跡圖像、色調(diào)或值圖像。但是,當控件的行為風格為 UIBehavioralStyle.pad 時,這些屬性和方法可以在 Mac 習慣用法中使用。

提供不同的代碼路徑

即使你的 Mac App 使用 UIUserInterfaceIdiom.pad 習慣用法運行,你可能也需要更改 Mac App 的外觀或行為。使用 targetEnvironment() 編譯條件根據(jù)目標環(huán)境選擇不同的代碼路徑。

例如,如果你的 iPad App 會在刪除按鈕旁邊以彈出窗口形式顯示項目刪除確認,但你想在 Mac App 中以提醒形式顯示該確認,則可以添加一個 targetEnvironment() 條件來確定提醒控制器的首選風格。

 let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { (action) in  if dataStore.delete(recipe) {  self.recipe = nil  } }   let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)   #if targetEnvironment(macCatalyst) let preferredStyle = UIAlertController.Style.alert #else let preferredStyle = UIAlertController.Style.actionSheet #endif   let alert = UIAlertController(title: "Are you sure you want to delete \(recipe.title)?", message: nil, preferredStyle: preferredStyle) alert.addAction(deleteAction) alert.addAction(cancelAction)   if let popoverPresentationController = alert.popoverPresentationController {  popoverPresentationController.barButtonItem = sender as? UIBarButtonItem }   present(alert, animated: true, completion: nil)


網(wǎng)站欄目:創(chuàng)新互聯(lián)IOS教程:為你的MacApp選擇一個用戶界面習慣用法
新聞來源:http://www.5511xx.com/article/dhedsos.html