ネットワーク全体で iOS Smart Island に適応した最初の Toast ライブラリかもしれません - JFPopup

ゴールデン ストーン プロジェクトの最初のチャレンジにサインアップしました - 賞金プール 100,000 を共有します。これは私の 2 回目の記事です。クリックしてイベントの詳細を表示します

序文

昨年書いた記事では、私が書いた一連の Swift ポップアップ コンポーネント ライブラリ、エレガントな Swift ポップアップ コンポーネント - JFPopupについて詳しく紹介しました。その中にToastViewのセットが採用されており、これはApple iPhone14 Proシリーズ以降の今年のスマートアイランドのインタラクティブスタイルの新しいセットと一致しているので、ToastViewもスマートアイランドに適合できるのではないかと思いました。であること。前回の記事でJFPopupの具体的な使い方を詳しく紹介しましたが、今回はSmart Islandに適応するためのメンタルプロセスを中心に解説します。

特定の効果:

利用方法

前回の記事でも紹介しましたが、改めてここに書きます。また、Smart Island ToastはiPhone 14 Pro以上のモデルにデフォルトで対応しており、追加操作は不要です.Smart Islandモデル以外の場合は、デフォルトで中央に配置され、上下にも対応しています. より詳細なパラメータについては、エレガントな Swift ポップアップ コンポーネント - JFPopupを参照してください。

トースト:


//默认仅文案

JFPopupView.popup.toast(hit: "默认toast,支持灵动岛")

//带logo ,内置success or fail

JFPopupView.popup.toast(hit: "支付成功", icon: .success)

JFPopupView.popup.toast(hit: "支付失败", icon: .fail)

//自定义logo

JFPopupView.popup.toast(hit: "自定义", icon: .imageName(name: "face"))

复制代码

読み込み中:


DispatchQueue.main.async {

JFPopupView.popup.loading()

}

DispatchQueue.main.asyncAfter(deadline: .now() + 3) {

JFPopupView.popup.hideLoading()

JFPopupView.popup.toast(hit: "刷新成功")

}

复制代码

スマートアイランドへの具体的な適応プロセス

Apple が ActivityKit を下半期にローンチすると公式に発表しているため、Smart Island に適応した Api が追加される予定です。したがって、現在、私たちに適応できる公式の API はありません。ですから、自分で弾丸をかじって適応計画を考えるしかありません。

- まず、スマートアイランドの面積を知る必要があります

最も愚かな方法を使用して、シミュレーターのスクリーンショットを直接撮り、自分でサイズを計算します。効果の少なくとも 99% を復元できます。図に示すように、スマート アイランドの領域は幅約 120dt、高さ 34dp で、半円形のコーナーは当然 17dt です。上部に約 10 dp、画面の中央に配置。この情報を使用して、スマート アイランドのズームインとズームアウトのトランジション効果を自然にシミュレートできます。

- ToastView に Smart Island アニメーションを追加

オリジナルベースでスマートアイランドのアニメーション列挙を追加しました


public enum JFToastPosition {

case center

case top

case bottom

case dynamicIsland //新增灵动岛位置动画

}

复制代码

現在および破棄プロトコルを再実装するための遷移アニメーション コードは次のとおりです。

拡大:


let originSize = contianerView.jf.size

if config.toastPosition == .dynamicIsland {

contianerView.jf_size = CGSize(width: 120, height: 34)

contianerView.center = CGPoint(x: CGSize.jf.screenSize().width / 2, y: 27)

}

let updateV = {

contianerView.center = CGPoint(x: CGSize.jf.screenSize().width / 2, y: CGSize.jf.screenSize().height / 2)

if config.toastPosition == .top {

contianerView.jf_top = CGFloat.jf.navigationBarHeight() + 15

} else if config.toastPosition == .bottom {

contianerView.jf_bottom = CGSize.jf.screenHeight() - CGFloat.jf.safeAreaBottomHeight() - 15

} else if config.toastPosition == .dynamicIsland {

contianerView.jf_size = originSize

contianerView.center = CGPoint(x: CGSize.jf.screenSize().width / 2, y: originSize.height / 2 + 10)

}

contianerView.layoutIfNeeded()

}

guard config.withoutAnimation == false else {

updateV()

transitonContext?.completeTransition(true)

completion?(true)

return

}

if config.toastPosition == .dynamicIsland {

UIView.animate(withDuration: 0.25) {

updateV()

} completion: { finished in

transitonContext?.completeTransition(true)

completion?(finished)

}

return

}

复制代码

消える:


UIView.animate(withDuration: 0.25, animations: {

if config.toastPosition == .dynamicIsland {

contianerView?.layer.cornerRadius = 17

contianerView?.jf_size = CGSize(width: 120, height: 34)

contianerView?.center = CGPoint(x: CGSize.jf.screenSize().width / 2, y: 27)

}

contianerView?.subviews.forEach({ v in

if config.toastPosition == .dynamicIsland {

v.isHidden = true

} else {

v.alpha = 0

}

})

contianerView?.alpha = 0

}) { (finished) in

transitonContext?.completeTransition(true)

completion?(finished)

}

复制代码

終わり

以上が私のJFPopup組み込みコンポーネントJFToastViewのSmart Islandのアニメーションへの適応の全過程で、Appleが今年後半にApiをアップデートする場合は、できるだけ早く再適応させます。

おすすめ

転載: juejin.im/post/7145630021372084232