如何使用CGAffineTransformMakeScale为View及其NavigationBar设置动画

时间:2016-06-28 20:10:42

标签: ios swift uiview core-animation

我试图在屏幕中间出现另一个时为我的containerView设置动画。但我不明白。如果仅为视图设置动画,则navBar不会执行任何操作,如果我对它们进行动画处理都会移除。

When I only animate the view its look like this

When I animate the navigationBar its look like this

这是我的代码

 let datePickerController = self.storyboard!.instantiateViewControllerWithIdentifier("DatePickerViewController") as! DatePickerViewController
    let navController = UINavigationController(rootViewController: datePickerController)
    navController.modalPresentationStyle = UIModalPresentationStyle.Custom
    navController.transitioningDelegate = self

    UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
        self.view.alpha = 0.5
        self.navigationController!.navigationBar.alpha = 0.5
        self.view.transform = CGAffineTransformMakeScale(0.9, 0.9)
        //NavigationBar animattion
       // self.navigationController!.navigationBar.transform = CGAffineTransformMakeScale(0.9, 0.9)
        self.presentViewController(navController, animated:true, completion: nil)
    }) { (Bool) in

    }

1 个答案:

答案 0 :(得分:1)

我解决了,解决方案是改变这一行

    self.view.alpha = 0.5
    self.navigationController!.navigationBar.alpha = 0.5
    self.view.transform = CGAffineTransformMakeScale(0.9, 0.9)
    //NavigationBar animattion
   // self.navigationController!.navigationBar.transform = CGAffineTransformMakeScale(0.9, 0.9)

通过这些

  self.navigationController!.view.transform = CGAffineTransformMakeScale(0.93, 0.93)
  self.navigationController!.view.alpha = 0.5