2

I'm trying to create an IOS app and flip two views when pressing some buttons. I have found the flip animation but I want the flip to change the content to the new view when it is flipped 90° and not when the animation is completed. This is my function:

func animationFlip(fromView:UIView, toView:UIView, animationTime:Float)
{

    UIView.animateWithDuration(NSTimeInterval(animationTime), animations: {

        UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: fromView, cache: true)

        },completion:{completion in
            UIView.animateWithDuration(NSTimeInterval(animationTime), animations: { () -> Void in

                fromView.hidden = true;
                toView.hidden = false;
                UIView.setAnimationTransition(UIViewAnimationTransition.FlipFromRight, forView: toView, cache: true)


            })
    })
}

I have found this code which seems to do the trick but it is written in obj-c. How can it be translated to swift?

[UIView transitionFromView:viewToReplace
        toView:replacementView
        duration:1
        options:UIViewAnimationOptionTransitionFlipFromBottom
        completion:nil];

Thanks in advance!

Fidan Bytyqi
  • 21
  • 1
  • 3
  • 2
    Why do you need someone to translate a single method into Swift? Just type "UIView.transition.... and the method will auto complete for you. – rdelmar May 10 '15 at 16:22
  • Oh didn't know it was that simple :) I tried it but it is flipping my whole view. I have a view container inside my regular view and it is only that part that I want to flip. Do you know how to fix that? – Fidan Bytyqi May 10 '15 at 17:03
  • To avoid flipping the whole view you need to use another view to contain the two views you are transitioning between. See http://stackoverflow.com/a/9524837/2466193. – Ali Beadle May 10 '15 at 20:55
  • Thanks @AliBeadle. I had three container views in my main View Controller and there I could access these views in my ViewController.swift for creating the animation. But now that I have one Container view in main that contains all the three views I can't handle them in my swift-code (ViewControll.swift). I have tried to ctrl-click and drag them to the swift-code but it is not working. Do you know how I can fix it? – Fidan Bytyqi May 14 '15 at 12:49
  • @FidanBytyqi I don't understand the question. I recommend posting it as a separate question with more explination. – Ali Beadle May 15 '15 at 17:48

1 Answers1

2

In Swift:-

UIView.transitionFromView(viewToReplace, toView: replacementView, duration: 1, options: .TransitionFlipFromBottom, completion: { _ in })
il_raffa
  • 5,090
  • 129
  • 31
  • 36
S.Singh
  • 21
  • 5