繁体   English   中英

动画期间的subView堆叠

[英]subView stacking during animation

我是Swift的新手,正在尝试学习一本互动书。 我已经使用CATransform3DMakeRotation创建了封面效果。

在此处输入图片说明



如您所见,当我堆叠视图时,问题就来了。 如果我尝试添加封底,则由于动画触发,堆叠顺序会丢失。

到目前为止,我的代码:

let bookcontainerwidth = 400
let bookcontainerheight = 200
let bookcoverwidth = bookcontainerwidth/2
let bookcoverheight = bookcontainerheight

let flipspeed = 2.0

//container
let container = UIView(frame: CGRect(x: 0, y: 0, width: bookcontainerwidth, height: bookcontainerheight))
container.backgroundColor = UIColor.white

//back cover
let backcover = UIButton(frame: CGRect(x: bookcontainerwidth/2, y: 0, width: bookcoverwidth, height: bookcoverheight))
backcover.backgroundColor = UIColor.darkGray
backcover.setTitle("Back", for: UIControlState.normal)

//front cover
let frontcover = UIButton(frame: CGRect(x: bookcontainerwidth/2, y: 0, width: bookcoverwidth, height: bookcoverheight))
frontcover.backgroundColor = UIColor.gray
frontcover.addTarget(receiver, action: #selector(opencover), for: .touchUpInside)
frontcover.setTitle("Front", for: UIControlState.normal)
frontcover.layer.anchorPoint = CGPoint(x: 0.0, y: 0.5);
frontcover.center = CGPoint(x:bookcoverwidth, y: bookcoverheight/2);

container.addSubview(backcover)
container.addSubview(frontcover)


func opencover(){

    UIView.animate(withDuration: flipspeed){ () -> Void in

        //these do not work
        //container.bringSubview(toFront: frontcover)
        //container.sendSubview(toBack: backcover)

        frontcover.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI), 0.0, 1.0, 0.0);
    }

}

公开接受所有反馈。 如我所说,我是菜鸟。 例如,我正在使用UIButton,因为我希望封面是可单击的。 不确定是否正确;)

谢谢!

找到了:

frontcover.layer.zPosition = 300.0;

使用CATransform3DMakeRotation进行平滑水平翻转的完整说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM