首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift NSValue.valueWithCGRect

Swift NSValue.valueWithCGRect
EN

Stack Overflow用户
提问于 2014-06-10 20:26:14
回答 3查看 6.1K关注 0票数 11

我试着用Facebook pop UIButton POPSpringAnimation动画化一个NSValue.valueWithCGRect的界限,但是我找不到我应该用什么来代替NSValue.valueWithCGRect

这就是我想做的:

代码语言:javascript
复制
@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")

}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-06-10 20:32:58

这将汇编:

代码语言:javascript
复制
let rect = CGRect(x: 0,y: 0,width: 1,height: 1)
let val = NSValue(CGRect: rect)

这是“初始化器语法”。

票数 20
EN

Stack Overflow用户

发布于 2014-06-11 08:51:31

这是我的解决方案:

代码语言:javascript
复制
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")
}
票数 1
EN

Stack Overflow用户

发布于 2016-02-15 23:28:08

在Swift:

代码语言:javascript
复制
    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")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24150240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档