2011-08-08 3 views
1

iOSアプリケーション用のNSPopoverに類似したものはありますか?これはMac用のオブジェクトライブラリには表示されますが、iPhoneやiPad用には表示されませんが、これを使用してアプリをダウンロードしています(または少なくとも非常に類似した機能)。iOS用NSPopover

私の質問:これを実装する正当な方法はありますか?

答えて

3

UIPopoverControllerはあなたが探しているものです。

+0

UIPopoverControllerはiPad専用です! –

+0

したがって、プログラムで_popover_を作成する必要があります。 –

2

ありUIPopOverControllerですが、その使用は制限されているのiPadに:

ポップオーバー・コントローラは、iPadデバイスのみに使用するためのものです。他のデバイスで作成しようとすると例外が発生します。

source

iPhone/iPod touchのために、あなたはWEPopOverのように、外部のフレームワークを使用することができます。彼らはUIPopoversと呼ばれているがあり

0

は、UIPopoverControllerはiPhoneとiPadの両方できるようになりましです。あなたは両方で同じように見えるpopoversを作ることができます(iOS 9のように、私は信じています)。

ステップ1:あなたのクラス定義にUIAdaptivePresentationControllerDelegateUIPopoverPresentationControllerDelegateを含める

ステップ2:このようなあなたのクラスのどこかにプレゼンテーションをオーバーライド

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { 
    return .none 
} 

ステップ3:あなたをビューコントローラを提示すると、popoverスタイルを使用するように指示します。このような何か:

//I pull my popover from a separate storyboard, but any modal view will do 
let storyboard = UIStoryboard(name: "Popovers", bundle: nil) 
let modal = storyboard.instantiateViewController(withIdentifier: "AnyPickerModal") as! AnyPickerVC 
modal.modalPresentationStyle = UIModalPresentationStyle.popover 

let pc = modal.popoverPresentationController 
pc?.permittedArrowDirections = .any 
pc?.sourceView = <your button or view you tap to show the popover> 
pc?.sourceRect = <your button or view>.bounds 

//How big the popover should be 
modal.preferredContentSize = CGSize(width: 300, height: 180) 

pc?.delegate = self 

self.present(modal, animated: true, completion: nil) 

ご提示モーダルが両方 iPhoneやiPad上でポップオーバーとして表示されます。私のiPhoneアプリからのスクリーンショットが添付されています。コーディングハッピー

enter image description here

関連する問題