2014-06-10 22 views
11

Tôi đang cố gắng để animate giới hạn của một UIButton sử dụng POPSpringAnimation pop Facebook, nhưng tôi không thể tìm thấy những gì tôi nên sử dụng trong nhanh chóng trong thay thế của NSValue.valueWithCGRectSwift NSValue.valueWithCGRect

Đây là những gì tôi m cố gắng để làm:

@IBAction func buttonTapped(sender : UIButton) { 

    var springAnimation = POPSpringAnimation() 
    springAnimation.property = POPAnimatableProperty.propertyWithName(kPOPLayerBounds) as POPAnimatableProperty 
    springAnimation.springBounciness = 12.0 
    springAnimation.springSpeed = 10.0 

    springAnimation.toValue = NSValue.valueWithCGRect(newBounds) 

    shutterButton.pop_addAnimation(springAnimation, forKey: "size") 

} 

Trả lời

20

này sẽ biên dịch:

let rect = CGRect(x: 0,y: 0,width: 1,height: 1) 
let val = NSValue(CGRect: rect) 

Đây là "initializer cú pháp"

+0

đâu tài liệu này? Tôi không nhận được kết quả cho việc này với tự động hoàn tất hoặc – rounak

+0

Cảm ơn, điều đó đã hiệu quả. –

+1

@rounak: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_27 – newacct

1

Đây là giải pháp của tôi:

func scaleView(view: UIView, magnitude: CGFloat) { 
    var springAnimation = POPSpringAnimation() 
    springAnimation.property = POPAnimatableProperty.propertyWithName(kPOPViewScaleXY) as POPAnimatableProperty 
    springAnimation.springBounciness = 12.0 
    springAnimation.springSpeed = 10.0 

    let newRect = CGRect(x: (view.bounds.origin.x + (view.bounds.size.width/2.0)) - ((view.bounds.size.width/2.0) * magnitude), y: (view.bounds.origin.y + (view.bounds.size.height/2.0)) - ((view.bounds.size.height/2.0) * magnitude), width: view.bounds.size.width * magnitude, height: view.bounds.size.height * magnitude) 

    springAnimation.fromValue = NSValue(CGRect: view.bounds) 
    springAnimation.toValue = NSValue(CGRect: newRect) 
    view.pop_addAnimation(springAnimation, forKey: "size") 
} 
0

Trong Swift:

let hover = CABasicAnimation(keyPath: "position") 
    hover.additive = true 
    hover.fromValue = NSValue(CGPoint: CGPointZero) 
    hover.toValue = NSValue(CGPoint: CGPointMake(0.0, -10.0)) 
    hover.autoreverses = true 
    hover.duration = 0.2 
    hover.repeatCount = Float(Int.max) 
    button.layer.addAnimation(hover, forKey: "myHoverAnimation")