我正在尝试使用以下代码在UINavigationItem上添加我的图像:
override func viewDidLoad() {
super.viewDidLoad()
self.navItemTop.titleView?.contentMode = UIViewContentMode.scaleToFill
self.navItemTop.titleView? = ViewController4.navigationImage! //my image, its correct for sure
self.navigationController?.navigationBar.barTintColor = UIColor.white
}
当我去另一个UIViewController然后返回时,图像出现并在一秒后消失。我试图将这段代码放在viewWillAppear()方法中,但结果是一样的。 我怎样才能解决这个问题?
答案 0 :(得分:0)
您需要使用viewWillAppear:
方法设置图片。
原因:当你推或现在某个时候我们可能会为导航设置另一个图像或清除颜色。请注意,为什么viewDidLoad:
方法未被调用,您丢失了旧的导航设置。酒吧。
答案 1 :(得分:0)
您可以在UIImageView中添加它: -
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet"/>
<h1 class="thing-to-fade">Animate.css</h1>
<button id="my-button">Fade Out Up</button>
<script>
const element = document.querySelector('.thing-to-fade'); // define the element
document.querySelector('#my-button').addEventListener('click', event => {
element.classList.add('animated', 'fadeOutUp');
});
// add an eventlistener for the 'animationend' event
element.addEventListener('animationend', event => {
// after the animation ends, these classes will be removed
element.classList.remove('animated', 'fadeOutUp');
});
</script>