Reputation: 3229
How to do 3D cube animation in swift iOS like this
I tried
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
})
}
Also found this, but it is not same which I need. There are a lot of UIViewController
3D animations which do not fulfill my requirement, what I need is cube animation transition.
Upvotes: 2
Views: 2558
Reputation: 1897
I know its too late to answer but it might help someone who is looking out for a solution. Try using STCubeTransition https://github.com/Sa74/STCubeTransition. It allows you to translate 2 different views with cube animation.
Upvotes: 1