小编Lin*_*rth的帖子

我发现桌面视图无法在iOS 11中滚动

我发现我UITableView无法在iOS 11中滚动,所以我在"cell for row"委托方法中做了一些测试:

  • 当我设置cell.userInteractionEnabledNO,滚动工作
  • 当我设置cell.contentView.userInteractionEnabledNO,它没有

我的自定义视图cell.contentView,所以我不知道如何解决它...

objective-c uitableview ios11

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

在iOS 12中自动填充用户名和密码

我在iOS 11中成功实现了AutoFill存储的用户名和密码建议
.我的登录视图控制器中有两个文本字段,一个用于电子邮件,一个用于密码.内容类型定义如下:


电子邮件/用户名文本字段配置


密码文本字段配置

这曾经在iOS 11中运行得很好,但在将我的开发iPad升级到iOS 12之后,该应用建议用户名字段的电子邮件,并在编辑密码字段时发生以下情况:


在我的创建帐户视图控制器中,我有3个文本字段:电子邮件,密码,重复密码.他们的内容模式设置如下:

  • 电邮→电子邮件地址
  • 密码→新密码,规则: minlength:8;
  • 重复密码→新密码,规则: minlength:8;

编辑电子邮件地址字段时,它会正确建议电子邮件地址.但是,对于密码和重复密码字段,它建议存储密码,而不是建议新密码.


我尝试了什么

  • (不合逻辑地)翻转内容模式设置,因此登录密码字段设置为new password,并且创建帐户密码字段设置为password
    • 没有成功; 事实上,根本没有改变行为
  • 将内容模式设置none为登录和创建帐户字段,以便AutoFill可以尝试自动处理它
    • 没有成功; 事实上,根本没有改变行为

注意

  • 在服务器上正确设置了自动填充功能.创建帐户字段中建议的存储密码证明了这一点
  • 该功能仍在iOS 11 iPad上运行
  • 使用新用户名登录时,应用程序将要求用户将此用户名和密码添加到Keychain,即使在iOS 12上也是如此

知道我需要更改什么,以便存储的用户名和密码建议再次在iOS 12中工作?

谢谢!



编辑

根据下面@kralex的要求,这是故事板中登录视图控制器的视图层次结构:

......并在设备上:

autofill ios swift ios12

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

无法在SwiftUI中使用自定义视图

对于我的SwiftUI应用程序,我创建了一个简单的Title视图,该视图具有设置的字体大小和文本颜色。Title声明如下:

struct Title: View {
    var string: String

    var body: some View {
        Text(string)
            .font(.system(size: 32))
            .color(Color.black)
    }
}
Run Code Online (Sandbox Code Playgroud)

我现在在内容视图的正文中有以下文本对象:

var body: some View {
    VStack(alignment: .leading) {
        Text("Welcome")
            .font(.largeTitle)
            .color(Color.black)
        Text("to SwiftUI")
            .font(.largeTitle)
            .color(Color.secondary)
    }
}
Run Code Online (Sandbox Code Playgroud)

所以现在,我想用Texts 替换这两个Title

var body: some View {
    VStack(alignment: .leading) {
        Title("Welcome")
        Title("to SwiftUI")
    }
}
Run Code Online (Sandbox Code Playgroud)

替换视图后,我从Xcode收到一些看似无关的错误消息,这些错误消息使应用程序无法编译:

静态成员“ leading”不能用于“ Horizo​​ntalAlignment”类型的实例

'(LocalizedStringKey)-> Text'不能转换为'(LocalizedStringKey,String ?, Bundle ?, StaticString?)-> Text'

“字体”不能转换为“字体?”

...和更多。恢复Text而不是Title“修复”问题。

有趣的是,我还有一个自定义PrimaryButton视图,可以添加它而没有任何问题: …

swift swiftui

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

在SwiftUI中设置切换颜色

在遵循Apple 关于用户输入教程之后,我实现了一个切换。当前,它看起来像这样:

这是产生此UI的代码:

NavigationView {
    List {
        Toggle(isOn: $showFavoritesOnly) {
            Text("Show Favorites only")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Now, I'd like the Toggle's on-color to be blue instead of green.
I tried:

Toggle(isOn: $showFavoritesOnly) {
    Text("Show Favorites only")
}
.accentColor(.blue)
Run Code Online (Sandbox Code Playgroud)
.foregroundColor(.blue)
Run Code Online (Sandbox Code Playgroud)
.background(Color.blue)
Run Code Online (Sandbox Code Playgroud)

None of these worked and I wasn't able to find any other modifiers, such as tintColor.

How do I change the color of a Toggle?

toggle swift swiftui

7
推荐指数
6
解决办法
1493
查看次数

SwiftUI中Text(“”)和Text(verbatim:“”)初始化程序之间的区别

我一直在关注Apple的SwiftUI教程。在此过程中,我经常将Text对象与以下初始化程序一起使用:

/// Creates an instance that displays `content` verbatim.
public init<S>(_ content: S) where S : StringProtocol
Run Code Online (Sandbox Code Playgroud)

Now, in the fifth tutorial of the series, I've encountered the following usage of Text:

Text(verbatim: "")
Run Code Online (Sandbox Code Playgroud)

The description in the interface is the same as for the other initializer:

Text(verbatim: "")
Run Code Online (Sandbox Code Playgroud)

Question

What's the two initializers for and how are they different / when would I use which?

swift swiftui

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

如何使用GraphicContext快速获得书法线条笔刷效果

我想添加书法笔刷效果,如下图所示。我正在使用SwiftyDrawView进行绘图

在此处输入图片说明


以下是SwiftyDraw的代码片段

/// Overriding draw(rect:) to stroke paths

  override open func draw(_ rect: CGRect) {
        super.draw(rect)
        guard let context: CGContext = UIGraphicsGetCurrentContext() else { return }

        for line in lines {
            context.setLineCap(.round)
            context.setLineJoin(.round)
            context.setLineWidth(line.brush.width)
            // set blend mode so an eraser actually erases stuff
            context.setBlendMode(line.brush.blendMode)
            context.setAlpha(line.brush.opacity)
            context.setStrokeColor(line.brush.color.cgColor)
            context.addPath(line.path)
            context.strokePath()
        }
    }
Run Code Online (Sandbox Code Playgroud)

// TouchBegan

  override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard isEnabled, let touch = touches.first else { return }
        if #available(iOS 9.1, …
Run Code Online (Sandbox Code Playgroud)

core-graphics ios swift swifty-draw

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

永久动画SCNNode - SceneKit,Swift

我想永远动画2个立方体,直到用户点击其中一个.动画应该像∞一样.

这些是我想要动画的sceneView中的我的立方体: 立方体动画

我试图用嵌套动画做到这一点,它确实部分工作.现在,由于动画总是等到它们在开始新动画之前完成,它看起来并不光滑.

在继续开发∞动画之前,我想知道是否有更好的(实际工作)方式.这是我目前的代码:

SCNTransaction.begin()
SCNTransaction.setAnimationDuration(2)
cube1.position = SCNVector3Make(3, 0, 0)
cube2.position = SCNVector3Make(-3, 0, 0)
println("log 0")
SCNTransaction.setCompletionBlock {
    println("log 1")
    while (animationKey != 1) {
        //initially animationKey = 0
        SCNTransaction.begin()
        SCNTransaction.setAnimationDuration(2)
        cube1.position.x += 1
        cube1.position.y += 1
        cube2.position.x += 1
        cube2.position.y += 1
        println("log 2")
        SCNTransaction.setCompletionBlock {
            SCNTransaction.begin()
            SCNTransaction.setAnimationDuration(2)
            cube1.position.x -= 1
            cube1.position.y -= 1
            cube2.position.x -= 1
            cube2.position.y -= 1
            println("log 3")
            SCNTransaction.setCompletionBlock { animationKey = 1 }
            SCNTransaction.commit()
        }
        println("log 4")
        SCNTransaction.commit()
        }
    }
    println("log 5") …
Run Code Online (Sandbox Code Playgroud)

animation ios scenekit swift

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

Xcode 错误:“/R.swift/rswift:没有这样的文件或目录”

收到此错误:

/Users/brendanwinter/Library/Developer/Xcode/DerivedData/Sidearm-bpmbvflilopwujbzzhkazqidiguc/Build/Intermediates/Sidearm.build/Debug-iphonesimulator/louisville.build/Script-52247AC61D89704E005DF2FA.sh: line 2: /R.swift/rswift: No such file or directory

截图1

我努力了:

  • 重新安装 Pod
  • 更新 CocoaPods
  • 清除 DerivedData 文件夹
  • 干净的构建

swift

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

在物理计算场景包后获取节点位置

在此处输入图片说明

在处理场景套件应用程序时,我有 2 个盒子可以相互射击以获得点数。这是第一个框需要射击的位置的计算:

shot1 = SCNNode()
shot1.geometry = SCNSphere(radius: 0.5)
shot1.physicsBody = SCNPhysicsBody.dynamic()
shot1.position = SCNVector3Make
(boxNode1.position.x, 
 boxNode1.position.y + 1, 
 boxNode1.position.z - 1)
scnScene.rootNode.addChildNode(shot1)
Run Code Online (Sandbox Code Playgroud)

对于第二个框:

shot2 = SCNNode()
shot2.geometry = SCNSphere(radius: 0.5)
shot2.physicsBody = SCNPhysicsBody.dynamic()
shot2.position = SCNVector3Make
(boxNode2.position.x, 
 boxNode2.position.y + 1, 
 boxNode2.position.z + 1)
scnScene.rootNode.addChileNode(shot2)
Run Code Online (Sandbox Code Playgroud)

每一次射击都在正确的位置进行,然后被扔到另一个盒子上,并在其物理体上施加力作为脉冲。

对于触摸实现,我使用 touchesBegan 来搜索触摸,然后如果触摸具有 hitResult,我将按上述方式开火。

问题发生在:如果例如 shot1 击中 boxNode2,boxNode2 会按我的预期向后移动,这次如果我用 boxNode2 射击,shot2 的起始位置不在我预期的 boxNode2 的新位置,并且开始在开始的地方开火!

那么我怎样才能从 boxNodes 的新位置开火呢?

ios scenekit swift3

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

ARSessionConfiguration在Xcode 9 GM中未解析

ARKit使用测试版的Xcode 9 创建了一个项目,我可以在我的真实设备上运行而没有任何问题.
昨天,我升级到Xcode 9 GM,没有触及任何东西,Xcode显示多个错误,说它不知道ARSessionConfiguration即:

使用未声明类型'ARSessionConfiguration'

和:

使用未声明类型'ARWorldTrackingSessionConfiguration'

...对于此代码:

let session = ARSession()
var sessionConfig: ARSessionConfiguration = ARWorldTrackingSessionConfiguration()
Run Code Online (Sandbox Code Playgroud)

我已经导入ARKit并使用了ARSCNViewDelegate我的ViewController.
从Xcode的测试版打开项目时,它不会显示错误,我可以再次在手机上运行该应用程序.

知道如何解决这个问题吗?

ios arkit xcode9

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