問題は本当に簡単です。ナビゲーションバーの下のリスト(メニュー)をクリックすると(ナビゲーションバー上で)表示する方法がわかりません。Swift - アニメーションのあるナビゲーションバーの下のメニュー
私はこれを実行しようとしました:appDelegateで
func doSomething(){
let navigationBarHeight = self.navigationController?.navigationBar.frame.height ?? 0
print(navigationBarHeight)
let heightTotal = UIApplication.shared.statusBarFrame.height + navigationBarHeight
DispatchQueue.main.async(execute: {
appDelegate.infoView(message: "test", Yorigin: heightTotal, color: colorBlueFollow)
})
}
そして、この:
func infoView(message: String, Yorigin: CGFloat ,color: UIColor){
if infoViewIsShowing == false{
infoViewIsShowing = true
// let infoViewHeight = self.window!.bounds.height/14.2
let infoViewHeight = self.window!.bounds.height/4.2
let infoViewY = Yorigin - infoViewHeight
let infoView = UIView(frame: CGRect(x: 0, y: infoViewY, width: self.window!.bounds.width, height: infoViewHeight))
infoView.backgroundColor = color
self.window!.addSubview(infoView)
let infoLabelWidth = infoView.bounds.width
let infoLabelHeight = infoView.bounds.height + UIApplication.shared.statusBarFrame.height/2
let infoLabel = UILabel()
infoLabel.frame.size.width = infoLabelWidth
infoLabel.frame.size.height = infoLabelHeight
infoLabel.numberOfLines = 0
infoLabel.text = message
infoLabel.font = UIFont(name: "HelveticaNeue", size: 11)
infoLabel.textColor = UIColor.white
infoLabel.textAlignment = .center
infoView.addSubview(infoLabel)
// Animate errorView
UIView.animate(withDuration: 0.2, animations: {
// Move down
infoView.frame.origin.y = Yorigin
}, completion: { (finished: Bool) in
if finished{
UIView.animate(withDuration: 0.2, delay: 3, options: .curveLinear, animations: {
// move up
infoView.frame.origin.y = infoViewY
}, completion: { (finished: Bool) in
if finished {
infoView.removeFromSuperview()
infoLabel.removeFromSuperview()
self.infoViewIsShowing = false
}
})
}
})
}
}
問題があります表示されているビューがナビゲーションバーの上を通過している、それは私が好きなエフェットではありません...
私はそれをどうやってできるのか考えていますか?
あなたはcocoapodsに見ていました事前
私のコードをAppDelegateから現在のView Controllerに移動し、self.windowを変更しました。 self.viewに。それは単純なahaだった! – KevinB