2016-07-08 1 views
0

私は、原点(左上と右のエッジが同じ位置にとどまる)アニメーションの起源のiOS

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") 
    } 
} 

が、アニメーションの増加を変更することなく、ビューの高さを増大させてアニメーションを作成しようとしてきました中央からのサイズ(上端を上に、下端を下に) 何が欠けていますか?

+0

このようにするには、ビューのアンカーポイントを設定する必要があります。あなたは 'animateWithDuration'でこれをやろうとしましたか?次に、あなたが望むものを明示的にフレームに設定することができます。 – Putz1103

答えて

1

これを試すことができます。

 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) 

     } 
関連する問題