JM:I have a dream,期待和你一起去实现!
原文及译文
JM
网友:narb

        我试图设置一个侧面/幻灯片菜单,但所有的例子,我发现有一个固定的宽度,所以当它来隐藏/显示菜单,他们正在播放宽度约束的 - /值。...

推荐:想去Google查资料?(你懂的)想建站?想测试?想挂机?想折腾?想要高性价比的服务器?点我!!


打开可变宽度的关闭侧菜单(在xcode中)(open close side menu with variable width (in xcode))

我试图设置一个侧面/幻灯片菜单,但所有的例子,我发现有一个固定的宽度,所以当它来隐藏/显示菜单,他们正在播放宽度约束的 - /值。

我想用百分比来设置宽度,所以我选择将宽度约束定义为常量= 0和乘数= 0.4

我是Xcode / iOS的新手,那么根据屏幕大小,当宽度变化时,如何显示/隐藏菜单?

我是否过分复杂的问题?我应该坚持固定的宽度吗?


I am trying to setup a side/slide menu but all the examples I find has a fixed width so when it comes to hide/show the menu they are playing with a -/+ value for the width constraint.

I wanted to set the width with a percentage ratio so I've chosen to define the width constraint as constant = 0 and multiplier = 0.4

I'm new to xcode/iOS so what is the way to show/hide the menu when you have variable width depending on the screen size?

Do I over complicate the problem? Should I stick with fixed width?


解决方案(由网友Sh_Khan提供)

这很简单,就像第一种情况一样

显示

 self.menuWidthCon.constant = 0

隐藏

 self.menuWidthCon.constant = -1 * (self.view.bounds.size.width) * 0.3

编辑:

把代码放入,确保sideMenuConstraint被正确地挂接到接口生成器约束

  override func viewDidLayoutSubviews
 {
     // MenuScrollView.contentSize.height = 1000

     if(once)
     {

         once = false
        sideMenuConstraint.constant = -1 * (self.view.bounds.size.width) * 0.45
       self.layoutIfNeeded()
     }

 }

It's simple just do the same as the first case

show

 self.menuWidthCon.constant = 0

Hide

 self.menuWidthCon.constant = -1 * (self.view.bounds.size.width) * 0.3

Edit:

put the code in , make sure sideMenuConstraint is hooked properly to interface builder constraint

  override func viewDidLayoutSubviews
 {
     // MenuScrollView.contentSize.height = 1000

     if(once)
     {

         once = false
        sideMenuConstraint.constant = -1 * (self.view.bounds.size.width) * 0.45
       self.layoutIfNeeded()
     }

 }

推荐:想去Google查资料?(你懂的)想建站?想测试?想挂机?想折腾?想要高性价比的服务器?点我!!


关于站长

JMJavaMethod的缩写,苦逼码农一个,一直想有番作为,奈何人老力衰,只能四处膜拜大佬以获得动力。已经从单机、局域网、互联网、混到了移动互联网,未来希望能在AI世界里继续混下去。这辈子有个终极目标:财务自由,心灵自由。

近期公告

一个人苦逼开发多日,网站终于正式上线,求关注!!! 一个人苦逼多日,终于正式上线,求关注!!!

找他  
猜你喜欢
想建站?想测试?
想挂机?想折腾?
想去Google查资料?(你懂的)
想要高性价比的服务器?
搬瓦工VPS - 性价最高的美国便宜VPS主机
友情链接

冀ICP备17016304号 版权所有 © JavaMethod.com All Rights Reserved,Theme by 拼图