Mein Problem ist wirklich einfach, ich weiß nicht, wie man eine Liste (Menü) unter der Navigationsleiste anzeigt, wenn ich darauf klicke (in der Navigationsleiste).Swift - Menü unter Navigationsleiste mit Animation
Ich möchte die gleiche Sache als dieses Bild tun:
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)
})
}
ich, dies zu tun versucht
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
}
})
}
})
}
}
Das Problem ist, dass die angezeigte Ansicht über die Navigationsleiste hinausgeht, ist es nicht die Wirkung, die ich möchte ...
Hast du eine Idee, wie ich das machen kann?
Vielen Dank im Voraus
Danke für deine Antwort, ich habe meinen Code von AppDelegate auf den aktuellen View Controller verschoben und ich habe self.window geändert! zu sich selbst sehen. Es war so einfach aha! – KevinB