如何在快速iOS中进行3D立方体动画,如this
我试过
let container = UIView()
let redSquare = UIView()
let blueSquare = UIView()
override func viewDidLoad() {
super.viewDidLoad()
// set container frame and add to the screen
self.container.frame = CGRect(x: 60, y: 60, width: 200, height: 200)
self.view.addSubview(container)
// set red square frame up
// we want the blue square to have the same position as redSquare
// so lets just reuse blueSquare.frame
self.redSquare.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
self.blueSquare.frame = redSquare.frame
// set background colors
self.redSquare.backgroundColor = UIColor.redColor()
self.blueSquare.backgroundColor = UIColor.blueColor()
// for now just add the redSquare
// we'll add blueSquare as part of the transition animation
self.container.addSubview(self.redSquare)
}
@IBAction func animateButtonTapped(sender: AnyObject) {
// create a 'tuple' (a pair or more of objects assigned to a single variable)
let views = (frontView: self.redSquare, backView: self.blueSquare)
// set a transition style
let transitionOptions = UIViewAnimationOptions.TransitionFlipFromLeft
UIView.transitionWithView(self.container, duration: 1.0, options: transitionOptions, animations: {
// remove the front object...
views.frontView.removeFromSuperview()
// ... and add the other object
self.container.addSubview(views.backView)
}, completion: { finished in
// any code entered here will be applied
// .once the animation has completed
})
}
还找到this,但它与我需要的不一样。有很多UIViewController
3D动画无法满足我的要求,我需要的是立方体动画过渡。
答案 0 :(得分:1)
我知道回答太晚了,但它可能会帮助那些正在寻找解决方案的人。尝试使用STCubeTransition https://github.com/Sa74/STCubeTransition。 它允许您使用立方体动画翻译2个不同的视图。