2011-07-29 5 views
1

私はpresentModalViewコントローラを使用しており、そのコントローラを介して新しいビューへの遷移を押しています。 そして、私は(正常に動作している)の移行を行うには、次のコードiPhone - presentModalViewController from right from

[self presentModalViewController:myViewController animated:NO]; 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
[[myViewController.view layer] addAnimation:animation forKey:@"SwitchToView"]; 

を使用していますが、問題はその示す空白の画面とは、その後の移行が始まる、ということです。これを避ける方法は?

私が表示しようとしていた。

答えて

3

最初に、これは私が将来求職者が有用な何かを見つけることができるように、私のために働いていたものを投稿します、答えはなかったとして

CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
[[myViewController.view layer] addAnimation:animation forKey:@"SwitchToView"]; 


[self presentModalViewController:myViewController animated:NO]; 
+1

、ビューは、右下の隅から来ています。しかし、私はナビゲーションコントローラのそれと同様のものを持っていたい。 (しかし私は私のアプリでナビゲーションコントローラを持っていませんし、それを実装したくありません) – Satyam

+0

私にとっては右から左に表示されますが、白い背景にはまだあります:-( –

+0

私はこのテクニックを ' MFMailComposeViewController'を実行していましたが、ある時点、おそらくiOS6では正常に動作しなくなりました。シミュレータで見ることができます。開始ビューの複製が右から左にスライドし、最後に新しいビューが表示されます。 'controller.view.layer'、' controller.view.superview.layer'、 'controller.view.window.layer'と同じことです。これが一般的な問題か、私のアプリで奇妙なものかカスタムトランジションをあきらめて。 –

1

存在その後、アニメーションを追加異なるXIBファイル内のCATransitionを持つビューで、最初は常に黒い画面が表示されます。

ソリューションは、問題を見つけた後

[[self.view.superview layer] addAnimation:animation forKey:@"SwitchToView"]; 

でこれらの線

[[myViewController.view layer]; 
addAnimation:animation forKey:@"SwitchToView"]; 

を置き換えることだった、「明らかにローカルウィンドウが1であるので、あなたがしたい、理解するのは非常に簡単でした押す"。

+0

それは確かにスーパービューです。 – dklt

0

私が思うに、uiviewcontroller.transitioningDelegateはiOS7 ANS 8でそれを行うための方法である:私はそのようにやったとき

//Mark : Custom Transitionning for modal 
func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, fromRight:Bool , completion: (() -> Void)?) { 
    if fromRight 
    { 
     viewControllerToPresent.modalPresentationStyle = UIModalPresentationStyle.FullScreen 
     viewControllerToPresent.transitioningDelegate = self; 
     self.presentViewController(viewControllerToPresent, animated: true, completion: completion); 
    } 
    else 
    { 
     self.presentViewController(viewControllerToPresent, animated: true, completion: completion) 
    } 
} 


//MARK : Transitioning Delegate 
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return self; 
} 

func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return self; 
} 

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

func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 

    let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! 
    let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! 
    let toView = toViewController.viewForTransitionContext(transitionContext) 
    let fromView = fromViewController.viewForTransitionContext(transitionContext) 
    let containerView = transitionContext.containerView() 
    let duration = self.transitionDuration(transitionContext); 

    let initialFrame = transitionContext.initialFrameForViewController(fromViewController) 
    var offsetRect = initialFrame 
    offsetRect.origin.x += CGRectGetWidth(initialFrame); 

    //Present 
    if toViewController.isBeingPresented() 
    { 
     // init state before animation 
     toView.frame = offsetRect; 
     containerView.addSubview(toView); 
     // then animate 
     UIView.animateWithDuration(duration, animations: {() -> Void in 
      toView.frame = initialFrame; 
      }, completion: { (finished) -> Void in 
       transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
     }) 

    } 
    //Dismiss 
    else 
    { 
     // init state before animation 
     containerView.addSubview(toView) 
     containerView.sendSubviewToBack(toView) 
     // then animate 
     UIView.animateWithDuration(duration, animations: {() -> Void in 
      fromView.frame = offsetRect 
      }, completion: { (finished) -> Void in 
       fromView.removeFromSuperview() 
       transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
     }) 
    } 
} 
関連する問題