Custom Transitions beim ModalView mit Flackern

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Custom Transitions beim ModalView mit Flackern

    Hi,

    ich habe mir eine CustomTransition geschrieben um ein Menu als ModalView einzublenden.
    Dabei wird die aktuelle View verschoben und das Menü liegt hinter dieser. (Ähnlich wie eine Push Transition nur das die erste View nicht komplett verschwindet und noch etwas am Rand zu sehen bleibt).

    Wenn ich nun wieder das Menü schließe (die Transistion die View wieder hineinbewegt. Flackert es kurz.

    Die Ursache ist, dass die View, die ich beim öffnen des Menüs verschoben habe sich bei der Schließanimation initial wieder auf die Koordinaten 0,0 setzt. und somit für einen Bruchteil einer Sekunden da ist wo sie eigentlich erst hin animiert werden soll.

    Weiß jemand wieso das so ist oder wie man das unterbinden kann?

    Quellcode

    1. ​import Foundation
    2. import UIKit
    3. class INTransitionAnimator:NSObject,UIViewControllerAnimatedTransitioning
    4. {
    5. var isAppearing:Bool = false
    6. func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval
    7. {
    8. return 1
    9. }
    10. // This method can only be a nop if the transition is interactive and not a percentDriven interactive transition.
    11. func animateTransition(transitionContext: UIViewControllerContextTransitioning)
    12. {
    13. var fromVC:UIViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
    14. var toVC:UIViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
    15. var container:UIView = transitionContext.containerView()
    16. var initialFrame : CGRect = transitionContext.initialFrameForViewController(fromVC)
    17. var offscreenRect : CGRect = initialFrame
    18. offscreenRect.origin.x += 260
    19. if(self.isAppearing)
    20. {
    21. toVC.view.frame = initialFrame
    22. container.addSubview(toVC.view)
    23. container.bringSubviewToFront(fromVC.view)
    24. UIView.animateWithDuration(1,
    25. animations:
    26. {
    27. fromVC.view.frame = offscreenRect
    28. },
    29. completion:
    30. {
    31. finished in
    32. fromVC.view.frame = offscreenRect
    33. transitionContext.completeTransition(true)
    34. }
    35. )
    36. }
    37. else
    38. {
    39. toVC.view.frame = offscreenRect
    40. UIView.animateWithDuration(1,
    41. animations:
    42. {
    43. toVC.view.frame = initialFrame
    44. },
    45. completion:
    46. {
    47. finished in
    48. fromVC.view.removeFromSuperview()
    49. transitionContext.completeTransition(true)
    50. }
    51. )
    52. }
    53. }
    54. }
    Alles anzeigen