साथ definesPresentationContext का उपयोग करते हुए मैं बच्चे के दृश्य नियंत्रकों जो एक कस्टम ढंग से उपस्थित अन्य दृश्य नियंत्रक रुप से सक्षम होना चाहिए का एक सेट का प्रबंधन करने के दृश्य नियंत्रक रोकथाम उपयोग कर रहा हूँ। ROOT
, A
, और B
UIModalPresentationStyle.custom
मैं जब एक दृश्य नियंत्रक से पेश UIModalPresentationStyle.custom
का उपयोग कर एक उदाहरण के रूप एक मुद्दा है, जहां definesPresentationContext
संपत्ति इस्तेमाल नहीं किया में चलाने की है, मैं तीन दृश्य नियंत्रक है
ROOT
|_ A
A
ROOT
का बच्चा है। मैं A
से B
रुप से पेश करने के लिए है, जबकि कस्टम UIPresentationController
, UIViewControllerTransitioningDelegate
, और UIViewControllerAnimatedTransitioning
का उपयोग कर चाहते हैं।
func buttonPressed(_ sender: Any?) {
let presentationController = MyCustomPresentation()
let controllerToPresent = B()
controllerToPresent.modalTransitionStyle = .custom
controllerToPresent.transitioningDelegate = presentationController
present(controllerToPresent, animated: true, completion: nil)
}
हालांकि, अपनी प्रस्तुति नियंत्रक (जो भी मेरी UIViewControllerAnimatedTransitioning
है) मैं मुठभेड़ के अंदर निम्नलिखित:
तो मैं नियंत्रक A
के लिए कोड के अंदर निम्न उपाय अपनाते हैं (ध्यान दें नियंत्रक A
true
को definesPresentationContext
सेट है) समस्या:
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let fromVC = transitionContext.viewController(forKey: .from)
let toVC = transitionContext.viewController(forKey: .to)
if let fromVC = fromVC as? A,
let toVC = toVC as? B {
//Do the presentation from A to B
}
}
इस समारोह में, मैं जहां उम्मीद fromVC
प्रकार A
के होने के लिए, यह वास्तव में ०१२३३५४६३५९ है। तथ्य यह है कि A
निर्दिष्ट करता definesPresentationContext
के बावजूद।
तो मैं समझ यह है, क्योंकि मैं UIModalPresentationStyle.custom
उपयोग कर रहा हूँ। इसलिए मैं यह UIModalPresentationStyle.overCurrentContext
यह सही ढंग से A
से definesPresentationContext
संपत्ति को पढ़ने के लिए आईओएस का कारण बनता है, और मेरे animateTransition
समारोह अब दृश्य नियंत्रक से सही के साथ बुलाया जाता है करने के लिए बदलने के लिए, लेकिन:
क्योंकि मेरी मोडल प्रस्तुति शैली नहीं रह गया है .custom
, मेरे संक्रमण प्रतिनिधि में निम्न विधि नहीं रह गया है कहा जाता हो जाता है
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?
तो अपनी प्रस्तुति नियंत्रक अप्रयुक्त हो जाता है।
मुझे .custom
मोडल संक्रमण शैली चाहिए जो definesPresentationContext
का सम्मान करती है। क्या यह संभव है? क्या मैं कुछ भूल रहा हूँ?
असल में, मैं वर्तमान संदर्भ में एक कस्टम मॉडल प्रस्तुति चाहते हैं।
क्या आपने 'ए' में भी संक्रमण प्रतिनिधि को सेट करने का प्रयास किया है? इस लाइन से पहले: 'वर्तमान (नियंत्रक टॉस्पेंट, एनिमेटेड: सत्य, समापन: शून्य) '। इस प्रयास करें: 'self.transitioningDelegate = presentationController' मैं इस सुझाव है का उपयोग करते समय:' UIModalPresentationStyle.overCurrentContext' – zero