UIPresentationController」カテゴリーアーカイブ

PopoverⅢ(UIPresentationController)

平成30年4月29日(日曜日)

再再掲!!リンク完動!! Updated to Swift 4.
図も交えた理解しやすい説明(英文)
(dismissal animation)
Using custom interactive transitions to dismiss a modal
プロジェクト名 InteractiveModal
Using custom interactive transitions to dismiss a modal
のUINavigationController版↓
ModalNavigationControllerPractice(swift3.3)
引っ張って閉じることができるモーダルを実装する (UINavigationControllerの場合)
「それはUINavigationControllerにはPan Gesture Recognizerをアタッチすることができないことです。
そこで、UINavigationControllerの子のViewControllerでPan Gestureをハンドリングし、UINavigationControllerに伝播する方法で目的を達成できましたのでコード片を残しておきたいと思います。」

iOSのカスタム画面遷移64種類を試せるサンプルコードを公開しましたAdd Star

UIKitにある機能でWebで見かけるようなUI達を作る

interactionControllerForDismissal(UIPercentDrivenInteractiveTransition)

平成30年4月27日(金曜日)

apple(遷移にインタラクティブ性を追加する)
トランジションアニメーションをカスタマイズする

UIPercentDrivenInteractiveTransition オブジェクトは、既存のアニメーターオブジェクトと連携してアニメーションのタイミングを制御します。
割合主導型のインタラクティブアニメーターを設定する

// Add the gesture recognizer to the container view.
UIView* container = [transitionContext containerView];
[container addGestureRecog

平成30年4月26日(木曜日)

前提
① Delegate内で定義!!

extension ViewController: UIViewControllerTransitioningDelegate {
func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return interactor.hasStarted ? interactor : nil
}
}

② class作成!!

class Interactor: UIPercentDrivenInteractiveTransition {
var hasStarted = false
var shouldFinish = false
}
/*
open func update(_ percentComplete: CGFloat)

open func cancel()

open func finish()
*/

③ 移動量計算、GestureRecognizer内でinteractor.update(progress)してOK!!
@IBAction func handleGesture(_ sender: UIPanGestureRecognizer) {

let percentThreshold:CGFloat = 0.3

// convert y-position to downward pull progress (percentage)
let translation = sender.translation(in: view)
let verticalMovement = translation.y / view.bounds.height
let downwardMovement = fmaxf(Float(verticalMovement), 0.0)
let downwardMovementPercent = fminf(downwardMovement, 1.0)
let progress = CGFloat(downwardMovementPercent)

guard let interactor = interactor else { return }

switch sender.state {
case .began:
interactor.hasStarted = true
dismiss(animated: true, completion: nil)
case .changed:
interactor.shouldFinish = progress > percentThreshold
interactor.update(progress)
case .cancelled:
interactor.hasStarted = false
interactor.cancel()
case .ended:
interactor.hasStarted = false
interactor.shouldFinish
? interactor.finish()
: interactor.cancel()
default:
break
}
}
}

使い方
let interactor = Interactor()
作成し、destinationViewControllerに渡す。

class ViewController: UIViewController {

let interactor = Interactor()

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destinationViewController = segue.destination as? ModalViewController {
destinationViewController.transitioningDelegate = self
destinationViewController.interactor = interactor
}
}

}

追加(参考)
func dismiss(animated flag: Bool,
completion: (() -> Void)? = nil)

(Dismisses the view controller that was presented modally by the view controller.)
(ビューコントローラによってモーダルに表示されたビューコントローラを閉じます)

@IBAction func toSecondVew(){
performSegue(withIdentifier: "toSecond", sender: nil)
}

@IBAction func back(){
self.dismiss(animated: true, completion: nil)
}

UIPresentationController(Summary)

平成30年4月21日(土曜日)

カスタム表示の場合、独自の Presentation Controller を用意して、表示された View Controller にカスタムの外観を付与できます。Presentation Controller は、View Controller とそのコンテンツとは別個のカスタムクロムを管理できます。たとえば、View Controller のビューの背後に配置された淡色表示のビューは、Presentation Controller により管理されます。

View Controller の表示スタイルを UIModalPresentationCustom に設定し、適切な遷移デリゲートを提供すると、UIKit はカスタム Presentation Controller 代わりに使用します。

カスタムビューは、presentationTransitionWillBegin メソッドを使用して画面にアニメーション化します。このメソッドでは、カスタムビューを設定し、それらをコンテナビューに追加します。表示される View Controller か表示中の View Controller のトランジションコーディネータを使用してアニメーションを作成します。

。アニメーターオブジェクトは、表示されるViewControllerを、frameOfPresentedViewInContainerViewメソッドから返す四角形フレームにアニメーション化する責任を負っています。

UIPresentationController{
override func containerViewWillLayoutSubviews() {
presentedView?.frame = frameOfPresentedViewInContainerView
}

}

View Controller を表示するときは、そのビューをコンテナビューのサブビューとして追加します。コンテナビューは、ウィンドウまたは通常のビューのことがありますが、常にアニメーションを実行するように設定されています



カスタムアニメーションを使用して View Controller を表示する

カスタムアニメーションを使用して View Controller を表示するには、既存の View Controller のアクションメソッドで次の手順を実行します。

表示する View Controller を作成します。

カスタム遷移デリゲートオブジェクトを作成し、View Controller の transitioningDelegate(UIViewControllerAnimatedTransitioning) プロパティに割り当てます。

遷移デリゲートのメソッドは、カスタムアニメータオブジェクトを作成して、求められたときに返す必要があります。
presentViewController:animated:completion: メソッドを呼び出して View Controller を表示します。
presentViewController:animated:completion: メソッドを呼び出すと、UIKit は表示プロセスを初期化します。表示は、次の実行ループ反復時に開始され、カスタムアニメーターが completeTransition: メソッドを呼び出すまで続きます。インタラクティブ遷移では、遷移の進行中にタッチイベントを処理することができますが、非インタラクティブ遷移はアニメーターオブジェクトにより指定された持続期間に実行されます。


The best way to learn UIViewControllerAnimatedTransitioning

平成30年4月15日(日曜日)

検索KEY WORD
UIPresentationController up down left right

Example of how to use presentation, animation & interaction controllers w/ custom segues to create a slide-in modal menu which partially covers presenting view.

「プレゼンテーション、アニメーション、およびインタラクションコントローラを使用してカスタムセグを使用して、プレゼンテーションビューを部分的にカバーするスライドインモーダルメニューを作成する方法の例。」

MrAlek/hamburger.swift
末尾にリンクあり(SWIFT4)ソースのみ 使い方不明 ERROR無し
SWIFT 4 版


swift2 バージョン(UINavigationControllerを使うときの参考)
UIViewControllerAnimatedTransitioningを使って画面遷移アニメーションを作る


平成30年4月14日(土曜日)

[iOS] 遷移元の画像が遷移先にズームイン・アウトするような画面遷移(UITableView及びUICollectionViewの場合)
プロジェクト名 CustomTransitionSample01 動作確認 swift3.3

平成30年4月12日(木曜日)

★ソースのみシンプル(swift4 convert ok!! 今後組み込み後 要動作確認)
prepare segueを設定し、動作確認。
@stingerstinger/SDPresentationManager.swift
ソース名:SDPresentationManager
プロジェクト名 singleview2


英文、シンプルでわかりやすい説明。プロジェクト無し、ソース有り
swift4 要convert
Custom View Controller Transitions

平成30年4月11日(水曜日)

swift4 完動!!
iOS Animation Tutorial: Custom View Controller Presentation Transitions
final → BeginnerCook

平成30年4月7日(日曜日)

再掲!!リンク完動!! Updated to Swift 4.
図も交えた理解しやすい説明(英文)
(dismissal animation)
Using custom interactive transitions to dismiss a modal
プロジェクト名 InteractiveModal

もう一点
Create an interactive slide-out menu using Custom View Controller Transitions
InteractiveSlideOutMenu-master
InteractiveSlideOutMenu-MenuRightSide有り(但しswift2 要コンバート)
Updated for Swift 3.1

PopoverⅡ(UIPresentationController)

平成30年4月7日(土曜日)

完動!! Swift 3.2 error無く Swift 4.にverup
iOS Tutorial: How to make a customizable interactive slide-out menu in Swift
github
/InteractiveSlideOutMenu
↓のリンクから「Tutorials」を辿ってダウンロード。。


完動!! Updated to Swift 4.
★★containerView: Think of this as the device window, or the stage on which the animation plays.
「containerView:これはデバイスウィンドウ、またはアニメーションが再生されるステージと考えることができます。」
iOS Tutorial: How to close a modal by dragging it down
プロジェクト名 InteractiveModal.xcodeproj github


旧バージョン error多数 プロジェクト名 RPModalGestureTransition-master
UIPercentDrivenInteractiveTransitionを使ってModalをDismissする


仕組みの理解(Objective-C)
UINavigationController上でのアニメーション
[Objective-C] UIViewControllerの遷移をカスタマイズする

画像がズームインしながら画面遷移するSwiftライブラリを公開しました

UIPresentationController

平成30年4月3日(火曜日)

UIPresentationController解析

ViewController
..UIViewControllerTransitioningDelegate(HalfModalTransitioningDelegate)
….. HalfModalTransitioningDelegate init(元view、先view)
………① animation HalfModalTransitionAnimator
………② presentationController HalfModalPresentationController
………③ interaction 対話 interactionController

PopoverⅠ(UIPresentationController)

平成30年4月6日(金曜日)

swift4版 検索キーワード(Interactive Transitions in Swift)
実行可!!
iOS 11 and Swift 4
Custom UIViewController Transitions: Getting Started
プロジェクト名 GuessThePet-starter
プロジェクト名 GuessThePet-final
何れもswift4 そのまま動作!!
interactiveTransitioning

平成30年4月4日(水曜日)

apple
apple
トランジションアニメーションをカスタマイズする
Gromview Toview Presentedview

英文説明チュートリアル(ソース有りerror多し プロジェクト無し)
The Step by Step Guide to Custom Presentation Controllers

実行可!!
UIPresentationController Tutorial: Getting Started
ダウンロードプロジェクト名 MedalCount Completed & MedalCount Starter

その他参考 (但しswift3への要コンバート DemosForBlog-master(CustomPresentation)残念ながら、コンバートにて多数のerror!!)
How to use custom presentation

平成30年4月1〜2日(日曜日 月曜日)

現段階★★★サンプル(swift 3.2)swift4にても、error無く動作
HalfModalPresentationController
ソース(上と同じもの+エトセトラソース 日付新しい)
HalfModalPresentationController.swift

最も新しいと思われるリンクとソース
Animating changes to presentingViewController during interactive dismissal
更にリンクをたどると。。。
interactive-parent-transform-bug
プロジェクト名 interactive-parent-transform-bug-master
UIPercentDrivenInteractiveTransitionを継承したinteractiveTransitioning
UIPanGestureRecognizerを使用したもので、技術的に押さえておきたい事項!!
interactiveTransitioning


        presentingViewController.transitionCoordinator?.animateAlongsideTransition({ context in
            self.setScale(expanded: true)
        }, completion: { context in
            self.setScale(expanded: !context.isCancelled())
        })
    }
    
    override func dismissalTransitionWillBegin() {
        presentingViewController.transitionCoordinator?.animateAlongsideTransition({ context in
            self.setScale(expanded: false)
        }, completion: { context in
            self.setScale(expanded: context.isCancelled())
        })
    }

Missing argument for parameter 'animation' in call
UIPercentDrivenInteractiveTransition interaction controller.に移行か、保留。
試行錯誤するも、完全動作に至らず。

↑の参考リンク
UIKitにある機能でWebで見かけるようなUI達を作る
context.isCancelled
Animating changes to presentingViewController during interactive dismissal

Interestingly, on iOS 11.x animate(alongsideTransition:completion:) works correctly for presentingViewController too (there is no need to use animateAlongsideTransition(in:animation:completion:)) - looks like Apple lifted something under the hood in the latest iOS.

更にキーワード三つ
[iOS]Twitterっぽい画像の閉じ方を実装してみる
↑source code developed with Swift 2.x. Xcode 9 does not support building or migrating Swift 2.x targets.
①UIViewControllerTransitioningDelegate(この中で、以下二点を利用)
②UIViewControllerAnimatedTransitioning(遷移のアニメーション)
③UIPercentDrivenInteractiveTransition(遷移の進行率・程度 percentComplete)


参考リンク swift2 old error
iOS8 presentation controllers
Xcode 8 Swift 3: Modal presentation transitioning delegate not called

下の参考リンク三点(日本語)ヴァージョンが古く動作せずも、仕組み等についてわかりやすい日本語による説明有り。
[iOS 8] UIPresentationController でカスタムのモーダル表示を実装する
プロジェクト名 SamplePresentation
SwiftでTumblrのリアクションみたいにモーダルウィンドウがにゅっと出るやつを作る
【iOS】Swipeで簡単に戻れるNavigationControllerを作ってみた


順序として、

①UIViewControllerTransitioningDelegate デリゲート

②UIPresentationController実装
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? {
return CustomPresentationController(presentedViewController:presented, presenting: presenting)
}

③class CustomPresentationController: UIPresentationController {

// 呼び出し元の View Controller の上に重ねるオーバーレイ View
var overlay: UIView!
・・・
}


UIPopoverController is deprecated in iOS 9.

下記リンク抜粋
//
UIPresentationController は抽象クラス
この抽象クラスを実装することで自由な表示・アニメーションのモーダルが実現される。
上記 UIPopoverController の代替として UIPopoverPresentationControllerが実装クラスとして提供される。
//

平成30年3月31日(土曜日)

現段階★★★SWIFT4 動作確認 STORYBOARD + 若干のCODE(簡便)popoverPresentationController利用!!
Popoverを表示

平成30年3月18日(日曜日)

Popoverの2つの実装方法を比較する
folder DownLoad_DEMO内に →  HowToDisplayPopover-master として保存

平成30年3月17日(土曜日)

取り敢えず、ここから学習か
Popoverの2つの実装方法を比較する
新:popoverPresentationController(forecasterplus導入済み)
旧:UIPopoverController’ was deprecated in iOS 9.0

検索エトセトラ(モーダルウィンドウ、addsubview等など、それぞれ有用か)
検索結果

要検討
[swift] PopoverPresentationControllerの実装とタップした時にメインViewにタップ情報を反映させる方法

swift4 collectionview tapped