[英]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,因為我希望封面是可單擊的。 不確定是否正確;)
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.