2014-12-05 28 views
0

我正在更新iOS5之前的應用程序 - 因此很多情況下需要更改。 在現有應用程序中,我們將視圖(在筆尖中創建)推送到包含UIPickerView/UIDatePicker的屏幕上,以允許用戶進行選擇。如何在iOS8和Swift中推送視圖

我應該是一個很容易遷移到iOS8/Swift的東西,但我花了過去的24小時試圖找出與Storyboard/Segue,Container views,viewControllers,UIPopoverPresentationControler等一起完成此操作的最佳方式, (即使蘋果的示例代碼將UIDatePicker推入表格單元格中)

這似乎是一個常見要求,我很感激任何有關其他人如何解決此問題的意見/評論。

非常感謝

+0

你能否提供更多細節?至少你正試圖轉換的obj-c代碼。 – 2014-12-05 17:38:53

回答

0

試試這個

self.performSegueWithIdentifier( 「你SEGUE標識符」,發件人:個體經營)

+0

你能提供更多的細節嗎? – 2014-12-05 14:46:52

0

感謝您的答案和問題尋求澄清。 經過一個週末的調查後,我意識到我被困在一箇舊的iOS範例中。

隨着iOS8的一切都移動到ViewController演示文稿,允許開發人員控制動畫和定義一系列設備(不同方向)的行爲。

的確定的答案我的問題(I相信)如下:

  1. 使用UIPresentationController到呈現所需的UIViewController:
    • 視圖控制器是顯示(使用代碼,筆尖或視圖故事板來創建選擇器視圖)
    • 演示控制器管理演示文稿的顯示方式(例如大小,presentationStyle)
    • 這也是處理透明/模糊視圖以覆蓋現有連續ENT

退房: FUNC sizeForChildContentContainer(容器:UIContentContainer,withParentContainerSize parentSize:CGSize) - > CGSize FUNC frameOfPresentedViewInContainerView() - >的CGRect

  • UIPresentationController需要一個轉換委託來管理演示文稿(符合UIViewControllerTransitioningDelegate)
  • {

    // We need to create a presentation controller to manage the presentation of VC 
    func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? { 
        let opc = OverlayPresentationController(presentedViewController: presented, presentingViewController: source) 
        return opc 
    } 
    
    // Get hold of an animation controller for presentation 
    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        let animationController = OverlayAnimatedTransitioning() 
        return animationController 
    } 
    
    // Get hold of an animation controller for dismissal 
    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        let animationController = OverlayAnimatedTransitioning() 
        return animationController 
    } 
    
  • 這又需要一個動畫控制器(UIViewControllerAnimatedTransitioning)來處理動畫(滑動,溶解或更多的東西冒險):

    FUNC transitionDuration(transitionContext: UIViewControllerContextTransitioning) - > NSTimeInterval {0}返回0。5 }

    FUNC animateTransition(transitionContext:UIViewControllerContextTransitioning){

    let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! 
    let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! 
    let containerView = transitionContext.containerView() 
    
    let animationDuration = self .transitionDuration(transitionContext) 
    containerView.addSubview(toViewController.view) 
    
    UIView.animateWithDuration(animationDuration, animations: {() -> Void in 
        <<< Animation Here>>>) 
        }) { (finished: Bool) in 
         transitionContext.completeTransition(true) 
    } 
    
  • 到位後積木,所需的UIViewController然後可以被調用(使用動作/選擇器/ SEGUE),並通過將所需的視圖的transitioningDelegate屬性所需的效果將被調用:

    @IBAction func showOVC(sender: AnyObject) { 
        let ovc = OverlayViewController() 
        let overlayTransitioningDelegate = OverlayTransitioningDelegate() 
        ovc.transitioningDelegate = overlayTransitioningDelegate 
        self.presentViewController(ovc, animated: true, completion: nil) 
    } 
    
  • 解僱以相同的方式處理,簡單地通過調用:

    dismissViewControllerAnimated(真,完成:無)

  • 可以通過文檔和這讓一切都清楚了我出色的WWDC視頻獲得更多信息:A look inside presentation controllers

    或看到蘋果的示例代碼:底線 - 並不像以前那麼簡單(假設單個設備處於一個方向),但是更復雜一點的是,對視圖和動畫有更大的控制力,可以縮放到多個設備。

    我希望這可以幫助人們在類似的位置 感謝