小编kej*_*ion的帖子

如何获得默认的系统填充值?

我正在使用 SwiftUI,但我已经创建了一个可表示的UITextView.

我想将插图设置为系统默认填充,以便它与应用程序的其余部分相匹配。

这是我现在正在使用的:

UITextView().textContainerInset = UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15)
Run Code Online (Sandbox Code Playgroud)

这看起来不错,但如果可能的话,我真的更愿意使用默认的系统填充。

文档padding()说明如下:

长度

在每条边上插入此视图的数量。如果为零,则金额为系统默认金额。

如何获取默认的系统填充CGFloat值?

ios swift swiftui

13
推荐指数
1
解决办法
4879
查看次数

SwiftUI 根据设备设置 navigationViewStyle

我试图让我的导航视图样式堆叠在 iPad 上,但在 iPhone 上默认。

代码:

.navigationViewStyle(UIDevice.current.userInterfaceIdiom == .pad ? StackNavigationViewStyle() : DefaultNavigationViewStyle())
Run Code Online (Sandbox Code Playgroud)

给我错误:

'? 中的结果值 :' 表达式具有不匹配的类型 'StackNavigationViewStyle' 和 'DefaultNavigationViewStyle'

这些不是 NavigationViewStyle 的子类吗?

xcode ios swift swiftui

8
推荐指数
1
解决办法
1520
查看次数

使用偏移时的导航栏项目可点击区域切割

在 SwiftUI 中,请考虑以下导航栏:

在此处输入图片说明

以下是尾随.navigationBarItems的声明方式:

HStack(spacing: 0) {
    Button(action: {
        self.addListModal = true
    }, label: {
        NavBarImage(image: "plus")
    })
    // more buttons here
Run Code Online (Sandbox Code Playgroud)

这是NavBarImage结构:

struct NavBarImage: View {
    var image: String

    var body: some View {
        ZStack {
            Rectangle().foregroundColor(Color.red).frame(width: 40, height: 45)
            Image(systemName: image)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

红色在那里,所以我可以看到每个按钮的可点击区域应该是什么。这ZStack有一个Rectangle想法介绍给我的一种方式,使图像更容易点击。

现在,我想将项目向右移动,以便它们更符合下面的列表内容。我尝试添加一个.offset到我的HStack

HStack(spacing: 0) {
    // buttons
}
.offset(x: 15, y: 0)
Run Code Online (Sandbox Code Playgroud)

产生这个结果:

在此处输入图片说明

所以这对我来说看起来很完美。然而,问题是最右侧的导航按钮的可点击区域在右侧被切断。

我已经用绿色说明了可点击区域的切断,这里:

在此处输入图片说明

所述按钮的绿色区域不再记录任何点击。

我已经使用负尾随试图.paddingHStack相反,它并没有区别。有没有办法纠正这个问题,也许是通过UINavigationBar …

ios swift swiftui

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

textFieldDidChangeSelection:在视图更新期间修改状态,这将导致未定义的行为

这是我的代码:

struct CustomTextField: UIViewRepresentable {
    var placeholder: String
    @Binding var text: String

    func makeUIView(context: UIViewRepresentableContext<CustomTextField>) -> UITextField {
        let uiView = UITextField()
        uiView.delegate = context.coordinator

        return uiView
    }

    func updateUIView(_ uiView: UITextField, context: UIViewRepresentableContext<CustomTextField>) {
        uiView.placeholder = placeholder
        uiView.text = text

        if uiView.window != nil, !uiView.isFirstResponder {
            uiView.becomeFirstResponder()
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, UITextFieldDelegate {
        var parent: CustomTextField

        init(_ CustomTextField: CustomTextField) {
            self.parent = CustomTextField
        }

        func textFieldDidChangeSelection(_ textField: UITextField) {
            parent.text = …
Run Code Online (Sandbox Code Playgroud)

uikit ios swift swiftui

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

如何使用代码在laravel控制台命令中中止/退出/停止/终止

假设我正在编写命令。如何在运行中完全停止运行?

例:

public function handle()
{
    if (!$this->good_times) {
        $this->error('Bad times');
        $this->exit();
    }

    // continue command stuff
}
Run Code Online (Sandbox Code Playgroud)

我试过了:

throw new RuntimeException('Bad times');
Run Code Online (Sandbox Code Playgroud)

但这会在终端中丢掉一堆丑陋的东西。

php command laravel laravel-5

2
推荐指数
2
解决办法
2212
查看次数

为什么要这样休息?解决似乎什么都没改变的问题?

我正在尝试为游戏的设备经理编写代码。

这是代码:

public class EquipmentManager : MonoBehaviour
{
    public int slots;
    public List<Equipment> defaultEquipment;
    public List<Equipment> currentEquipment;

    private void Start()
    {
        slots = System.Enum.GetNames(typeof(EquipmentSlot)).Length;

        EquipDefault();
    }

    public void Equip(Equipment newEquipment)
    {
        foreach (Equipment oldEquipment in currentEquipment)
        {
            if (oldEquipment.slot == newEquipment.slot)
            {
                Unequip(oldEquipment);
                break;
            }
        }

        currentEquipment.Add(newEquipment);
        gameObject.GetComponent<AvatarManager>().RenderPrefab(newEquipment.prefabName, true);
    }

    public void Unequip(Equipment oldEquipment)
    {
        currentEquipment.Remove(oldEquipment);
        gameObject.GetComponent<AvatarManager>().RenderPrefab(oldEquipment.prefabName, false);
    }

    public void EquipDefault()
    {
        foreach (Equipment equipment in defaultEquipment)
        {
            Equip(equipment);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我break;从循环if内部删除,foreach则不会添加新设备, …

c# unity-game-engine

0
推荐指数
1
解决办法
88
查看次数

AddRange引发“无法隐式转换类型”异常

我不知道为什么这不起作用:

    Dictionary<string, List<GameObject>> prefabs = new Dictionary<string, List<GameObject>>();
    List<GameObject> slotPrefabs = new List<GameObject>();

    // yadda yadda yadda

    if (prefabs.ContainsKey(slot))
    {
        prefabs[slot] = prefabs[slot].AddRange(slotPrefabs);
    }
    else
    {
        prefabs.Add(slot, slotPrefabs);
    }
Run Code Online (Sandbox Code Playgroud)

它给了我:

无法将类型“ void”隐式转换为“ System.Collections.Generic.List”

我只想添加到字典键的现有列表(如果已经存在)。

c# unity-game-engine

-2
推荐指数
1
解决办法
42
查看次数

标签 统计

ios ×4

swift ×4

swiftui ×4

c# ×2

unity-game-engine ×2

command ×1

laravel ×1

laravel-5 ×1

php ×1

uikit ×1

xcode ×1