ios - 动画起源iOS

标签 ios swift animation

我一直在尝试创建一个在不更改原点的情况下增加 View 高度的动画(左上角和右上角边缘保持在同一位置)

import UIKit
class SampRect: UIView {
var res : CGRect?
override init(frame: CGRect) {
    super.init(frame: frame)
    self.backgroundColor = UIColor(red: 0.91796875, green: 0.91796875, blue: 0.91796875, alpha: 1)
    self.layer.cornerRadius = 5

    let recognizer = UITapGestureRecognizer(target: self, action:#selector(SampRect.handleTap(_:)))
    self.addGestureRecognizer(recognizer)


}

func handleTap(recognizer : UITapGestureRecognizer) {

    let increaseSize = CABasicAnimation(keyPath: "bounds")
    increaseSize.delegate = self
    increaseSize.duration = 0.4
    increaseSize.fromValue = NSValue(CGRect: frame)
    res = CGRect(x: self.frame.minX, y: self.frame.minY, width: frame.width, height: self.frame.height + 10)
    increaseSize.toValue = NSValue(CGRect: res!)

    increaseSize.fillMode = kCAFillModeForwards
    increaseSize.removedOnCompletion = false

    layer.addAnimation(increaseSize, forKey: "bounds")


}

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
    self.frame = res!
}


required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
   }
}

但是动画从中间增加尺寸(将顶部边缘向上推,将底部边缘向下推) 我缺少什么?

最佳答案

你可以试试这个。

        let newheight:CGFloat = 100.0
        UIView.animateWithDuration(0.5) {

            self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, newheight)

        }

关于ios - 动画起源iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38269499/

相关文章:

objective-c - 如何从 NSHomeDirectory 加载图像

ios - 快速将 View Controller 解除到另一个 View Controller

jquery - rollOver 上的 CSS 叠加

jquery - 防止父元素上的 CSS 动画应用于子元素

ios - RestKit 和 AFNetworking 构建错误

ios - Google Maps iOS 的位置标记信息窗口

ios - 将AVAudioPlayer设置为AVAudioSession的输入数据源

ios - 谷歌地图不适合 subview

swift - 类型约束的可选扩展对其他类型可见

swift - 我应该使用哪个动画师来交换 UILabel.text 值?