小编Daw*_*ong的帖子

手动布局中的自动布局

我可以在frame, bounds, autoresizingMask用于定位自身的父视图中添加自动布局视图吗?

通常在互联网上,您会看到相反的情况,但我无法实现这种情况。

编辑:我为你们添加了一些代码。只需使用“Single View Application”创建一个新的 Xcode 项目,并将以下代码粘贴到为我们创建的 ViewController.swift 上。

class ViewController: UIViewController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        let custom = CustomManualLayoutSubviews()
        let subview = UIView()
        let childView = UIView()

        custom.backgroundColor = UIColor.red
        subview.backgroundColor = UIColor.green
        childView.backgroundColor = UIColor.blue

        custom.translatesAutoresizingMaskIntoConstraints = false
        subview.translatesAutoresizingMaskIntoConstraints = false
        childView.translatesAutoresizingMaskIntoConstraints = false

        view.addSubview(custom)
        custom.addSubview(subview)
        subview.addSubview(childView)

        pin(child: custom, parent: view)
        pin(child: childView, parent: subview)
    }

    private func pin(child: UIView, parent: UIView) { …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout swift

7
推荐指数
1
解决办法
3341
查看次数

如何通过当前 shell (zsh/bash) 检测数组起始索引?

我们都知道 Bash 中的数组从 0 开始索引,而 zsh 中的数组从 1 开始索引。

如果我无法确保运行环境是 bash、zsh 或其他环境,脚本如何知道它应该使用 0 或 1?

预期代码示例:

#!/bin/sh

detect_array_start_index(){
  # ... how?
  echo 1
}
ARR=(ele1 ele2)
startIndex=$(detect_array_start_index) # 0 or 1
for (( i=${startIndex}; i < ${#ARR[@]} + $startIndex; i++ )); do
    echo "$i is ${ARR[$i]}"
done
Run Code Online (Sandbox Code Playgroud)

我有一个想法是找到固定数组中第一个值的索引,我得到了这个:Get the index of a value in a Bash array,但接受的答案使用 bash 变量间接语法${!VAR[@]},这在 zsh 中无效。

arrays indexing bash shell zsh

5
推荐指数
1
解决办法
864
查看次数

标签 统计

arrays ×1

autolayout ×1

bash ×1

indexing ×1

ios ×1

objective-c ×1

shell ×1

swift ×1

zsh ×1