// 先直接贴代码,迟点整理下233333
// 给动画的
// 给动画的
// 给动画的
@IBOutlet weak var threeBtnView: UIView!
@IBOutlet weak var searchView: UIView!
@IBOutlet weak var grayView: UIView!
@IBOutlet weak var forMapView: UIView!
var zoomedInSearchView:Bool = true
var searchViewOriginalHeight:CGFloat!
var grayViewOriginalHeight:CGFloat!
@IBOutlet weak var searchHeightCon: NSLayoutConstraint!
@IBOutlet weak var grayViewHeightCon: NSLayoutConstraint!
@IBAction func zoomSearchView(_ sender: Any){
searchView.clipsToBounds = true
if zoomedInSearchView {
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.searchHeightCon.constant = self.searchHeightCon.constant * 0.5
self.searchView.bounds = CGRect(x: 0, y: self.searchViewOriginalHeight*0.5, width: self.searchView.bounds.width, height: self.searchView.bounds.height)
// self.searchView.frame = CGRect(x: 0, y: self.searchView.frame.minY, width: self.searchView.bounds.width, height: self.searchViewOriginalHeight*0.5)
// self.grayView.frame = CGRect(x: self.grayView.frame.minX, y: self.grayView.frame.minY, width: self.grayView.frame.width, height: self.grayViewOriginalHeight)
self.view.layoutIfNeeded()
self._mapView.frame = CGRect(x: 0, y: 0, width: self.forMapView.frame.width, height: self.forMapView.frame.height)
self.view.layoutIfNeeded()
}, completion: nil)
zoomedInSearchView = false
}
else{
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.searchHeightCon.constant = self.searchHeightCon.constant*2
self.searchView.bounds = CGRect(x: 0, y: 0, width: self.searchView.bounds.width, height: self.searchView.bounds.height)
// self.grayView.frame = CGRect(x: self.grayView.frame.minX, y: self.grayView.frame.minY, width: self.grayView.frame.width, height: self.grayViewOriginalHeight)
// self._mapView.frame = CGRect(x: 0, y: self.grayView.frame.maxY+10, width: self.view.frame.width, height: self.view.frame.height - (self.grayView.frame.maxY+10) - 49 - 10)
self.view.layoutIfNeeded()
self._mapView.frame = CGRect(x: 0, y: 0, width: self.forMapView.frame.width, height: self.forMapView.frame.height)
self.view.layoutIfNeeded()
}, completion: nil)
zoomedInSearchView = true
}
}
var grayViewZoomed:Bool = true
@IBAction func grayViewZoom(_ sender: Any) {
grayView.clipsToBounds = true
if grayViewZoomed {
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
self.grayViewHeightCon.constant = self.grayViewHeightCon.constant * 0.3
self.grayView.bounds = CGRect(x: 0, y: self.grayViewOriginalHeight*(1-0.3), width: self.grayView.bounds.width , height: self.grayViewOriginalHeight)
// self.grayView.frame = CGRect(x: self.grayView.frame.minX, y: self.grayView.frame.minY, width: self.grayView.frame.width, height: self.grayView.frame.height*0.3)
// self._mapView.frame = CGRect(x: 0, y: self.grayView.frame.maxY+10, width: self.view.frame.width, height: self.view.frame.height - (self.grayView.frame.maxY+10) - 49 - 10)
self.view.layoutIfNeeded()
self._mapView.frame = CGRect(x: 0, y: 0, width: self.forMapView.frame.width, height: self.forMapView.frame.height)
self.view.layoutIfNeeded()
}, completion: nil)
grayViewZoomed = false
}
else{
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.grayViewHeightCon.constant = self.grayViewHeightCon.constant * (1.000/0.3)
// self.grayView.frame = CGRect(x: self.grayView.frame.minX, y: self.grayView.frame.minY, width: self.grayView.frame.width, height: self.grayViewOriginalHeight)
self.grayView.bounds = CGRect(x: 0, y: 0, width: self.grayView.bounds.width, height: self.grayViewOriginalHeight)
// self.grayView.frame = CGRect(x: self.grayView.frame.minX, y: self.grayView.frame.minY, width: self.grayView.frame.width, height: self.grayViewOriginalHeight)
// self._mapView.frame = CGRect(x: 0, y: self.grayView.frame.maxY+10, width: self.view.frame.width, height: self.view.frame.height - (self.grayView.frame.maxY+10) - 49 - 10)
self.view.layoutIfNeeded()
self._mapView.frame = CGRect(x: 0, y: 0, width: self.forMapView.frame.width, height: self.forMapView.frame.height)
self.view.layoutIfNeeded()
}, completion: nil)
grayViewZoomed = true
}
}
// 给动画的
// 给动画的
// 给动画的
Swift简单View缩放动画
最后编辑于 :
?著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事?!?“怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目中要求子菜单的弹出动画为围绕点击的靠近点展开放大,而不是从中心展开,下面是动画效果: 在iOS中,anchor...
- 参考:第五篇:CABasic Animation。iOS动画系列之五:基础动画之缩放篇&旋转篇 原理和上一篇是相同...
- 这一篇主要介绍基础动画之缩放和旋转。这些基本操作分享完之后,我想想可以找个稍微复杂一点点的动画做做啦。 这篇继续基...