gpt4 book ai didi

ios - Swift 打开侧边栏/菜单时调整 View 中对象的大小

转载 作者:行者123 更新时间:2023-11-30 12:19:52 26 4
gpt4 key购买 nike

我目前正在使用侧栏/菜单对应用程序进行编程,我想从 View 中保留一些功能,这些功能在侧栏打开时部分隐藏。我正在考虑在从右侧打开侧边栏时调整主视图中某些对象的大小/过渡/消失

例如,主视图/页面被隐藏,我想调整一些内容的大小,以便它们仍然可以点击并发挥作用,当您将其拖回时,正常 View 会再次出现

我想它主要看起来像一个带有动画的新 View ,但我没有找到如何实现它的方法,因此我决定使用侧边栏。您能否告诉我,如何使 View 可以根据侧边栏进行更改并显示一些对象,而不是仅在该侧显示部分信息?

这是实际的应用:

main view is just with coverArts (第一个在中间,第二个在底部),当拖动/打开侧栏时,第一盖会根据滑动移动调整大小,而第二下盖则直接移动。那么它应该看起来像 second picture

最佳答案

========= View 中将出现添加观察者 =======

NotificationCenter.default.addObserver(self, selector: #selector(YourVC.showOverlayView), name: Notification.Name("showOverlayView"), object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(YourVC.hideOverlayView), name: Notification.Name("hideOverlayView"), object: nil)

=========您可以从这里隐藏和显示=======

func showOverlayView() {
UIView.animate(withDuration: 2.0, animations: {
self.viewBlackOverLay = UIView(frame: CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height))
self.viewBlackOverLay.backgroundColor = UIColor.black.withAlphaComponent(0.3)
self.view.addSubview(self.viewBlackOverLay)
})
}

func hideOverlayView() {
UIView.animate(withDuration: 1.0, animations: {
self.viewBlackOverLay.removeFromSuperview()
})
}

========= 邮政观察员 =======

当您想打开侧边菜单时,请在行下方添加

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showOverlayView"), object: nil)

在关闭侧边菜单的位置添加行下方

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "hideOverlayView"), object: nil)

关于ios - Swift 打开侧边栏/菜单时调整 View 中对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44922411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com