how to make objects appear from one side when I ro

2020-03-31 03:01发布

问题:

how to make objects appear from (one side only), when I rotate them in iOS ?

What I want to happen, (as you can see i can add another face to my UITableview cell)

What is happening, i can't even add another face since the previous one is showing up again

The Code I'm using

func animate()
{
    var id = CATransform3DIdentity
    id.m34 =  -1.0 / 1000

    var transformAnim            = CAKeyframeAnimation(keyPath:"transform")
    transformAnim.values         = [
        NSValue(CATransform3D: CATransform3DRotate(id, 0 * CGFloat(-M_PI_2), 0, 1.0, 0)),
        NSValue(CATransform3D: CATransform3DRotate(id, 1 * CGFloat(-M_PI_2), 0, 1.0, 0)),
        NSValue(CATransform3D: CATransform3DRotate(id, 0 * CGFloat(-M_PI_2), 0, 1.0, 0))
    ]
    transformAnim.keyTimes       = [0, 0.5, 1.0]
    transformAnim.duration       = 0.7

    self.imageViewLogo.layoutIfNeeded()

    self.imageViewLogo.layer.addAnimation(transformAnim, forKey: "transform")
}

If you know a feature called [force 2 sided] in 3ds max for example, I want it turned of here, but it seems that iOS has no feature like this.

  • This is an advanced question, I wish an expert answers me.

Thanks.

EDIT

if you are still not sure what I'm asking, I mean this :

how to make an object to show only from one side when i rotate it ?

回答1:

That is a standard flip transition. Take a look at the UIView method +transitionFromView:toView:duration:options:completion:, specifically the UIViewAnimationOptionTransitionFlipFromLeft and UIViewAnimationOptionTransitionFlipFromRight settings.

There is also a view controller transition if you want to do a flip transition to a different view controller.

If you want to build this animation yourself it's much more work.

What you have to do is create 2 separate animations, one for the front face and one for the back face:

First, you animate the front face rotating to 90 degrees, at which point it disappears because you are viewing it edge-on. At that point you add your back half view/layer, but facing the other way. Then in the second animation you rotate the new view 90 degrees, which leaves it flat and face-up. It's possible to get a seamless animation that gives you exactly the effect you want, but it's difficult, fussy code to write.



回答2:

the solution was a simple statement that I never heard of before

imageViewLogo.layer.doubleSided = false

from apple's website :-

A Boolean indicating whether the layer displays its content when facing away from the viewer. Animatable.