小编KSC*_*KSC的帖子

访问协议类型的成员在Swift中不起作用

以下是问题,如果类型是protocol.type,我无法调用类方法.是否有可以实现这一目标的替代模式.

真实情况是我有arr:[SomeProtocol.Type],我想执行let字符串:[String] = arr.map {$ 0.str}

protocol SomeProtocol: class {
   static var str: String { get }

   static func value() -> Int
}

class SomeClass: SomeProtocol {
   static var str: String = "SomeClass"

   static func value() -> Int {
      return 1
   }
}

let protocolType: SomeProtocol.Type = SomeClass.self
println(protocolType.str) // compile error
println(protocolType.value()) // compile error
Run Code Online (Sandbox Code Playgroud)

protocols ios swift

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

CABasicAnimation与键路径"边界"不起作用

我使用CABasicAnimation将以下代码添加到CALayer的动画边界属性中.但代码似乎不起作用.

    let fromValue = textLabel.layer.bounds
    let toValue = CGRectMake(textLabel.layer.bounds.origin.x, textLabel.layer.bounds.origin.y,   textLabel.layer.bounds.width, textLabel.layer.bounds.height + 50)

    let positionAnimation = CABasicAnimation(keyPath: "bounds")
    positionAnimation.fromValue = NSValue(CGRect: fromValue)
    positionAnimation.toValue = NSValue(CGRect: toValue)
    positionAnimation.duration = 1
    positionAnimation.fillMode = kCAFillModeBoth
    positionAnimation.removedOnCompletion = false

    textLabel.layer.addAnimation(positionAnimation, forKey: "bounds")
Run Code Online (Sandbox Code Playgroud)

cabasicanimation bounds swift

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

标签 统计

swift ×2

bounds ×1

cabasicanimation ×1

ios ×1

protocols ×1