UIKit:扩展循环UIView

时间:2015-11-10 06:26:05

标签: uiview ios8 uikit swift2 ios9

我正在寻找一个用于iOS 8.0或更高版本的Swift 2.0编写的答案。我有一个循环UIView,我想扩展它,但保留一个圆的属性。

要设置UIView,这就是代码。

let frame: CGRect = CGRect(x: 100, y: 100, width: 10, height: 10)
let view: UIView = UIView(frame: frame)
view.layer.cornerRadius = 5.0

1 个答案:

答案 0 :(得分:2)

如果您想展开圆圈视图,可以改变其比例:

circleView.transform = CGAffineTransformMakeScale(2, 2)

您可以为更改设置动画:

UIView.animateWithDuration(1) { () -> Void in
    self.circleView.transform = CGAffineTransformMakeScale(2, 2)
}

如果您只是想在短时间内展开按钮,然后让它恢复到原来的尺寸,您可以链接两个动画:

UIView.animateWithDuration(0.4, animations: { () -> Void in
    self.circleView.transform = CGAffineTransformMakeScale(1.2, 1.2)
}) { (finished) -> Void in
    UIView.animateWithDuration(0.4, animations: { () -> Void in
        self.circleView.transform = CGAffineTransformIdentity
    })
}

enter image description here