日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

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

新聞中心

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

概覽

用 Mac Catalyst 構(gòu)建的 Mac App 可以使用 UIUserInterfaceIdiom.padUIUserInterfaceIdiom.mac 用戶界面習(xí)慣用法運(yùn)行。要選擇 App 運(yùn)行時(shí)的習(xí)慣用法,請?jiān)?Xcode 項(xiàng)目中打開 Mac Catalyst,然后從以下選項(xiàng)中進(jìn)行選擇:

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

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

使用 UIUserInterfaceIdiom.pad 習(xí)慣用法運(yùn)行你的 App。選擇這個(gè)選項(xiàng)可以快速將你的 iPad App 移植到 Mac。

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

使用 UIUserInterfaceIdiom.mac 習(xí)慣用法運(yùn)行你的 App。選擇這個(gè)選項(xiàng)可以顯示外觀和行為與 AppKit 中控件相似的控件。

注釋

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

首先從 iPad 習(xí)慣用法開始

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

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

更新你的 App 以使用 Mac 習(xí)慣用法

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

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

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

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

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

確定當(dāng)前的用戶界面習(xí)慣用法

要確定你的 App 是不是在使用 Mac 習(xí)慣用法運(yùn)行,請將 userInterfaceIdiom 屬性的值與 UIUserInterfaceIdiom.mac 進(jìn)行比較。當(dāng)比較結(jié)果為 true 時(shí),你可以針對 Mac 量身定制 App 的行為,例如,顯示一個(gè)不同的子視圖。

 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)

設(shè)置首選行為風(fēng)格

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

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

請記住,當(dāng) App 使用 Mac 習(xí)慣用法時(shí),macOS 不會(huì)縮放 App 界面,因此,即使首選行為風(fēng)格是 UIBehavioralStyle.pad,你可能也需要更新你的 App 以適應(yīng)尺寸差異。例如,帶有自定拇指圖像的滑塊在 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) }

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

提供不同的代碼路徑

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

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

 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)


分享標(biāo)題:創(chuàng)新互聯(lián)IOS教程:為你的MacApp選擇一個(gè)用戶界面習(xí)慣用法
文章轉(zhuǎn)載:http://www.dlmjj.cn/article/dhedsos.html