【问题标题】:Cannot convert value of type 'Int' to expected argument type 'Angle'. Xcode 11, Mac 10.15, SwiftUI无法将“Int”类型的值转换为预期的参数类型“Angle”。 Xcode 11、Mac 10.15、SwiftUI
【发布时间】:2019-10-16 20:59:39
【问题描述】:

无法将类型“Int”的值转换为预期的参数类型“Angle”。 Xcode 11、Mac 10.15、SwiftUI

    image
        .clipShape(rotation3DEffect( Angle, axis: (x: 15, y: 15, z: 15)))
        .overlay(Circle().stroke(Color.white, lineWidth: 4))
        .shadow(radius: 10)

应该给出什么值作为“角度”,我尝试了不同的方法,但没有奏效。

【问题讨论】:

    标签: swift xcode macos swiftui


    【解决方案1】:

    您必须将Shape 传递给.clipShape(),例如:

    .clipShape(Circle())
    

    您必须将.rotation3DEffect 应用为单独的修饰符,并将Angle 和3 个CGFloats 的元组作为参数,如下所示:

    .rotation3DEffect(Angle(degrees: 10), axis: (15.0, 15.0, 15.0))
    

    所以你的图片应该这样声明:

    image
        .clipShape(Circle())
        .overlay(Circle().stroke(Color.white, lineWidth: 4))
        .rotation3DEffect(Angle(degrees: 10), axis: (15.0, 15.0, 15.0))
        .shadow(radius: 10)
    

    【讨论】:

      【解决方案2】:

      尝试这样做:

      image
              .clipShape(rotation3DEffect( .degrees(Angle), axis: (x: 15, y: 15, z: 15)))
              .overlay(Circle().stroke(Color.white, lineWidth: 4))
              .shadow(radius: 10)
      

      来源:https://www.hackingwithswift.com/quick-start/swiftui/how-to-rotate-a-view-in-3d

      P.S. 假设 Angle 是您的 int 不能转换为角度,最好用 小写 声明常量和变量,即它应该是angle 而不是 Angle。有了更多上下文,这通常不是什么大问题,但在这种情况下,很难知道Angle 是有问题的常量或变量,因为它是大写的。

      【讨论】:

      • 看起来我在错误的上下文中使用了它。还有一个错误:参数类型“某些视图”不符合预期的类型“形状”
      • 那么,some View 是什么?我们需要更多上下文来帮助诊断问题。你能显示更多关于some View的代码吗?
      猜你喜欢
      • 1970-01-01
      • 2019-05-12
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      • 2017-01-09
      • 2017-02-08
      • 2018-10-01
      相关资源
      最近更新 更多