简体   繁体   English

自定义UIViewController在Swift中使用animateWithDuration进行转换

[英]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. 我有一个符合UIViewControllerTransitioningDelegate和UIViewControllerAnimatedTransitioning的视图控制器。 I have a few animations (using facebook pop) that essentially slide certain elements of the view out. 我有一些动画(使用facebook pop)基本上可以滑出视图的某些元素。 After these animations complete I want to transition to the next view controller. 完成这些动画后,我想转换到下一个视图控制器。

I have overridden prepareForSegue like so: 我已经覆盖了prepareForSegue,如下所示:

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: 我在Obj-C代码中看到过这个:

^{ // 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
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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