swift2 IOS Swift中三维立方体过渡

wsxa1bj1  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(159)

如何做3D立方体动画在swift iOS喜欢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的三维动画不符合我的要求,我需要的是立方体动画过渡。

wlzqhblo

wlzqhblo1#

我知道现在回答太晚了,但它可能会帮助那些正在寻找解决方案的人。尝试使用STCubeTransition https://github.com/Sa74/STCubeTransition。它允许你用立方体动画转换2个不同的视图。

相关问题