[英]Flutter swift plugin creating and showing an arbitrary UIViewController
[英]Swift | UIViewController not showing as PopUp but Fullscreen
所以我有一個視圖控制器,它基本上是一個警報窗口,它應該是一個彈出窗口,並通過點擊其框架外的水龍頭而被解除。
但是每當我調用那個 VC 時,它總是顯示為全屏而不是彈出窗口。
我嘗試了幾種方法來做到這一點,即如下所述。
if let exp : String = expiredVehicles[i] {
expiredVehicleNumber = expiredVehicles[i]
let popUpVC = SubscriptionExpired()
popUpVC.modalTransitionStyle = .crossDissolve
popUpVC.modalPresentationStyle = .popover // also tried other presentation styles but none work and it is still fullscreen
popUpVC.view.backgroundColor = UIColor.white.withAlphaComponent(0.8)
self.present(popUpVC, animated: true, completion: nil)
}
如果有人需要查看該 VC 的定義,我很樂意分享
我覺得我應該提到要顯示為彈出窗口的 VC 繼承了 UIViewController
任何可能有幫助的見解都會很棒。
感謝您的輸入
一種可能的方法是向您的視圖添加點擊手勢識別器,這會關閉 VC。
但這只有在此彈出窗口具有只讀信息並且不需要用戶的任何進一步操作時才有用。
func addTapRecognizer(){
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap))
self.view.addGestureRecognizer(tap)
}
@objc func handleTap(){
// dismiss the VC here
}
}
您可以調用以下方法來顯示彈出窗口:
let popupVC = SubscriptionExpired()
popupVC.modalPresentationStyle = .overCurrentContext
self.addChild(popupVC)
popupVC.view.frame = self.view.frame
self.view.addSubview(popupVC.view)
popupVC.didMove(toParent: self)
}
然后,要刪除該彈出窗口,您可以使用:
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0
}, completion: { (finished) in
if finished {
self.view.removeFromSuperview()
}
})
在這種情況下,我在彈出窗口中有一個按鈕,每當按下該按鈕時,方法就會觸發。 你能試試嗎? 我可以根據您的需要編輯我的答案。
您需要在呈現視圖控制器時實現這一點:
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
// Return no adaptive presentation style, use default presentation behaviour
return .none
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.