我有這段代碼應該給mainView的彈簧效果。查看動畫無效 - ios Swift 3
但是我沒有得到想要的效果,我只通過Storyboard獲得應用於ViewController的Transition樣式。
override func viewDidLoad()
{
super.viewDidLoad()
self.statusBarHidden = UIApplication.shared.isStatusBarHidden
UIApplication.shared.setStatusBarHidden(true, with: .none)
self.mainView = UIView(frame: CGRect(x: self.view.getWidth/20, y:self.view.getHeight/6, width:self.view.getWidth/1.3 , height: self.view.getHeight/1.3))
self.mainView.backgroundColor = UIColor.blue
self.mainView.center.x = self.view.center.x
self.mainView.center.y = self.view.center.y
self.mainView.transform = CGAffineTransform(scaleX: 0.8, y: 1.2) // initial view distorted scale so it has a starting point for the animation
self.view.addSubview(self.mainView)
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: {
self.mainView.transform = .identity // get back to original scale in an animated way
}, completion: nil)
}
你可以請求幫助獲得對mainView的彈簧效果嗎?
謝謝
在'viewDidAppear'不'viewDidLoad'開始動畫。在'viewDidLoad'中,該視圖還不可見,並且不能生成動畫。 – Sulthan
只需在你的'UIView.animate'區塊內調用'view.layoutIfNeeded()' –
@Sulthan不錯!謝謝! –