2016-06-28 31 views
1

當試圖在屏幕中間出現其他人時嘗試爲我的containerView設置動畫。但我不明白。如果只爲視圖添加動畫,那麼navBar不會做任何事情,如果我動畫它都會移動。如何使用CGAffineTransformMakeScale爲視圖及其導航欄製作動畫

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

我解決這個問題,解決的辦法是改變這一行

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