2015-05-30 7 views
7

की दिशा निर्दिष्ट करें क्या "शो" सेग्यू (जिसे पहले "पुश" सेग्यू कहा जाता है) के दिशा (बाएं, दाएं, ऊपर या नीचे) से दिशा निर्दिष्ट करने का कोई आसान तरीका है?"शो" (पुश) segue

डिफ़ॉल्ट "शो" सेग्यू बाएं से दाएं चला जाता है, लेकिन मैं इसे नीचे से ऊपर तक जाना चाहता हूं।

उत्तर

7

मुझे विश्वास नहीं है कि इसे प्राप्त करने के लिए एक अंतर्निहित विधि है, हालांकि आप कस्टम ट्रांज़िशन का उपयोग कर सकते हैं, जो आईओएस 7 में पेश किए गए थे। वहां बहुत सारे महान ट्यूटोरियल हैं, मैंने नीचे कुछ लिंक जोड़े हैं और कुछ नमूना कोड दिखाते हैं कि आप शीर्ष दृश्य नियंत्रक को शीर्ष से नीचे कैसे स्लाइड कर सकते हैं।

साइटें की जाँच करने के लिए:

(नोट: जिस तरह से एक UIViewController के view तीसरे और चौथे ट्यूटोरियल में पहुँचा जा सकता है पुरानी हो चुकी है। toViewController.view के बजाय आप transitionContext.viewForKey(UITransitionContextToViewKey) का उपयोग करना चाहिए)

एक उदाहरण:

सबसे पहले, आप अपने स्टोरीबोर्ड, जो मैं आप आज़मा चुके हैं ग्रहण करने के लिए जा रहा हूँ सेट करने की आवश्यकता के लिए जा रहे हैं।

दूसरा, आपको NSObject सबक्लास की आवश्यकता है जो UIViewControllerAnimatedTransitioning के अनुरूप है। इसका उपयोग एक व्यू कंट्रोलर से दूसरे तक संक्रमण को नियंत्रित करने के लिए किया जाएगा।

class TransitionManager : NSObject, UIViewControllerAnimatedTransitioning { 
    let animationDuration = 0.5 

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { 
     return animationDuration 
    } 

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     let containerView = transitionContext.containerView() 
     let toView = transitionContext.viewForKey(UITransitionContextToViewKey)! 
     containerView.addSubview(toView) 

     let finalFrame = containerView.bounds 
     let initalFrame = CGRect(x: 0, y: -finalFrame.height, width: finalFrame.width, height: finalFrame.height) 

     toView.frame = initalFrame 
     UIView.animateWithDuration(animationDuration, 
      animations: { toView.frame = finalFrame }, 
      completion: { _ in transitionContext.completeTransition(true) }) 
    } 
} 

RayWenderlich: How To Make A View Controller Transition Animation Like in the Ping App ट्यूटोरियल में वर्णित है, आप अपने UINavigationController के प्रतिनिधि एक सेटअप की आवश्यकता होगी। निम्नलिखित NavigationControllerDelegate वर्ग जब एक धक्का segue किया जा रहा है TransitionManager का एक उदाहरण वापस जाने के लिए इस्तेमाल किया जाएगा:

class NavigationControllerDelegate: NSObject, UINavigationControllerDelegate { 
    let transitionManager = TransitionManager() 

    func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     if operation == .Push { 
      return transitionManager 
     } 

     return nil 
    } 
} 

और है कि यह होना चाहिए! इस पर विस्तार करने के लिए मैं आपको इंटरएक्टिव ट्रांज़िशन पर एक नज़र डालने की सलाह दूंगा।

संबंधित मुद्दे