小编spo*_*oax的帖子

导航视图在 iPad 上的 SwiftUI 中无法正常工作

我正在尝试创建一个适用于 iPhone 和 iPad 的导航视图。目前我可以在 iPhone 上使用它,但是当在 iPad 上运行它时,导航视图无法正确显示我的主视图。见下文:

在此输入图像描述

  1. 这是我加载应用程序的时候
  2. 如果我按产品(左上),它会打开产品选项卡。
  3. 当我点击产品时,它会转到此屏幕
  4. 如果我单击“产品 1”(见第三张图片),它会将所有详细信息打开到另一个导航栏中。

我想要实现的是图像 4 不在导航选项卡中,而是全屏。我尝试从代码中删除 NavigationView,这似乎解决了问题并使其全屏显示。但是,我随后失去了导航视图按钮以允许用户查看其他产品。

这是我的代码的缩短版本(没有所有文本/图像详细信息):

var body: some View {
    NavigationView {
        ScrollView(.vertical, showsIndicators: false) {
            VStack(alignment: .center, spacing: 20) {
                ProductHeaderView(product: product)
                
                VStack(alignment: .leading, spacing: 15) {
                    Text(product.title)
                        .font(.largeTitle)
                        .fontWeight(.heavy)
                        .foregroundColor(product.gradientColors[1])
                    Text(product.headline)
                        .font(.headline)
                        .multilineTextAlignment(.leading)
                }
                .padding(.horizontal, 20)
                .frame(maxWidth: 640, alignment: .center)
            }
            .navigationBarTitle(product.title, displayMode: .inline)
            .navigationBarHidden(true)
        }
        .edgesIgnoringSafeArea(.top)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

预先感谢您的帮助 :)

编辑:

这是 ProductHeaderView.swift 代码:

var body: some View {
    ZStack {
        LinearGradient(gradient: …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swiftui

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

ARKit 交互(手势)

我正在尝试使用 ARKit 制作一个 iOS 应用程序。到目前为止,我已经使用了 Apple 的“放置对象”示例并对其进行了扩充,因此它具有我自己的几何形状。这部分都很好用。

我有几个不同的物体可以放在地上。用简单的术语解释物体,它们是前面有门的盒子。

我遇到的问题是我现在想向应用程序添加手势,以便在轻敲门时它会旋转打开。然后当它再次被敲击时,门就会关闭。

我已经寻找了一些关于如何做到这一点的教程,但找不到任何东西。有人可以向我解释如何做到这一点,或者向我指出如何实现这种交互性的教程。

谢谢!:)

xcode ios swift swift4 arkit

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

选择不同选项卡时更改导航栏标题

我仍然是xcode的新手.

我想在我的UITabBarController中选择不同的选项卡时以编程方式更改导航标题.

我有一个创建标签栏的UItabBarController,然后我有单独的UIViewControllers,每个标签都有不同的内容 - 这部分工作正常,但是当选择不同的标签时我无法更改导航标题.

这是主标签控制器的代码.

// SUPER VIEW DID LOAD

override func viewDidLoad() {
    super.viewDidLoad()

    // NAVIGATION ITEM
    navigationItem.title = "Job Information"
    navigationController?.navigationBar.prefersLargeTitles = true

    //setup our custom view controllers

    let jobInfo = page_jobInfo()
    let shots = page_shotList()
    let attachments = page_attachments()
    let notes = page_notes()

    jobInfo.tabBarItem.title = "Information"
    jobInfo.tabBarItem.image = UIImage(named: "jobInfo")

    shots.tabBarItem.title = "Shots"
    shots.tabBarItem.image = UIImage(named: "shots")

    attachments.tabBarItem.title = "Attachments"
    attachments.tabBarItem.image = UIImage(named: "attachments")

    notes.tabBarItem.title = "Notes"
    notes.tabBarItem.image = UIImage(named: "notes")

    viewControllers = [jobInfo, shots, attachments, …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar uitabbarcontroller ios swift

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

如何向textField类添加标签或为占位符添加动画

我正在尝试在ios中创建自己的Google材质文本字段。当用户开始填写文本字段时,点击时下划线更改颜色,并且占位符文本向上移动。像这样:

在此处输入图片说明

我从这里开始关注此提要。

到目前为止,我在文本下方使用了该行,因此,当用户点击该行时,颜色会更改,而当用户在文本字段外点击时,该行会变回原始颜色。

我现在需要弄清楚如何使占位符文本停留在屏幕上并进行动画处理,这是否可能?我不认为这是我的下一个想法,是向我的自定义textField类添加UILabel并对其进行动画处理,但是我无法解决该怎么做?这有可能吗?

自定义文本字段类:

class CustomTextField: UITextField, UITextFieldDelegate{

    let border = CALayer()

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        delegate = self
        createBorder()
    }
    required override init(frame: CGRect) {
        super.init(frame: frame)
        delegate = self
        createBorder()
    }

    func createBorder(){
        let width = CGFloat(2.0)
        border.borderColor = UIColor(red:0.60, green:0.60, blue:0.60, alpha:1.0).cgColor
        border.frame = CGRect(x: 0, y: self.frame.size.height-width, width: self.frame.size.width, height: self.frame.size.height)
        border.borderWidth = width
        self.layer.addSublayer(border)
        self.layer.masksToBounds = true
    }

    func textFieldDidBeginEditing(_ textField: UITextField) {
        clearButtonMode = .whileEditing
        movePlaceholderUp()
    }
    func …
Run Code Online (Sandbox Code Playgroud)

xcode uitextfield ios swift

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

使用自定义单元类时的Tableview错误

我试图以编程方式使用自定义单元类创建tableViewController,但是我收到此错误:

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符cellId对单元格进行出列 - 必须为标识符注册一个nib或类或在故事板中连接原型单元'***First throw call stack:

我在我的应用程序中有几个UItableViews与自定义单元格,他们都工作正常,但由于某种原因,这一个不起作用.我花了最后几个小时试图解决这个问题,但看不出问题,有人可以帮帮我吗?

这是我的tableview类:

var tableView = UITableView()
    var twoDimensionalArray = [
        cameraInfoStruct(cameraInfo: ["Camera Body","Lens", "FPS", "Shutter Angle", "Colour Temperature", "Resolution Width", "Resolution Height", "Format", "Camera Rig"]),
        cameraInfoStruct(cameraInfo:["Focus Length", "F - Stop", "Camera Height", "Camera Tilt", "Camera Roll", "Filter"])
    ]

    let cellId = "cellId"
    let screenHeight = UIScreen.main.bounds.height
    let screenWidth = UIScreen.main.bounds.width
    let sectionHeaders = ["General", "Advanced"]

    override func viewDidLoad() {
        super.viewDidLoad()

        addTableView()
    }

    func addTableView() {
        tableView = UITableView(frame: CGRect(x: 0, y: 0, width: …
Run Code Online (Sandbox Code Playgroud)

xcode uitableview ios swift

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

“ UICollectionView必须使用非null布局参数初始化”

我正在尝试在本教程之后的第一时间创建一个简单的collectionView

到目前为止,我已经执行了所有步骤,并确保我没有错过任何内容。问题是我收到此错误:

由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“ UICollectionView必须使用非空布局参数初始化”

我看过相同问题的不同帖子,但我的答案似乎都没有解决我的问题。本教程没有为collectionView指定初始布局大小,因此我假设Xcode只是自动将其设置为视图的边界,因此它没有非nil布局?

class shootDaysCollectionView: UICollectionViewController, UICollectionViewDelegateFlowLayout {

    private let cellId = "cellId"

    override func viewDidLoad() {

    }

    // VIEW WILL APPEAR
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.tabBarController?.navigationItem.title = "SHOOT DAYS"

        collectionView?.backgroundColor = UIColor.white
        collectionView?.register(shootDayCell.self, forCellWithReuseIdentifier: cellId) 
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! shootDayCell

        return cell
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return …
Run Code Online (Sandbox Code Playgroud)

xcode ios uicollectionview swift

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