简体   繁体   中英

Custom UIViewController transitions with animateWithDuration in Swift

So... Truth is, I've been navigating through the documentation almost blindly. I really don't understand why there's no sample code illustrating how to use certain methods. But yeah, enough whining from me.

I have a view controller that conforms to UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning. I have a few animations (using facebook pop) that essentially slide certain elements of the view out. After these animations complete I want to transition to the next view controller.

I have overridden prepareForSegue like so:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {

      self.transitioningDelegate = self;

      let targetViewController = self.storyboard.instantiateViewControllerWithIdentifier("chooseSigilViewController") as UIViewController;

      self.presentViewController(targetViewController, animated: true, completion: nil);

      // slide out ui elements in the current UIViewController
      slideLabelsOut(greetingsLabel, nameUtilityLabel);
      slideTextFieldOut(inputPlayerNameTextField);
      slideProceedButtonOut(sender as UIButton); }

I than set up the transition duration and the actual animation... what I have problem with is this line:

UIView.animateWithDuration(self.transitionDuration(transitionContext), animations: <#(() -> Void)?#>, completion: <#((Bool) -> Void)?#>)

How do I setup my code within the animations: and completion: arguments.

I've seen this used in Obj-C code:

^{ // code goes here }

I've tried it that way, it didn't work. Also it felt really awkward as I don't really know what that "^" even does?

Try something like this:

UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0, options: .CurveLinear, animations: {
    // Your animation
}, completion: {
    (finished: Bool) in
    // Your completion
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM