1

저는 Xcode에서 단일 뷰 응용 프로그램을 가지고 있고 ViewController.swift에서 다음을 수행합니다. 내 목표는 화면을 5 초 이상 점진적으로 갈색의 직사각형으로 채우는 것이다. 나는 뭔가를 놓치고 있는가, 아니면 완전히 잘못된 접근인가?iOS에서 점진적으로 사각형 애니메이션 추가

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 
    let expandAnimation: CABasicAnimation = CABasicAnimation(keyPath: "path") 
    expandAnimation.fromValue = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0)) 
    expandAnimation.toValue = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.size.width, height: self.view.bounds.size.height)) 
    expandAnimation.duration = 5.0 
    expandAnimation.fillMode = kCAFillModeForwards 
    expandAnimation.isRemovedOnCompletion = false 
    let rectLayer: CAShapeLayer = CAShapeLayer() 
    rectLayer.fillColor = UIColor.brown.cgColor 
    rectLayer.path = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0)).cgPath 
    rectLayer.add(expandAnimation, forKey: nil) 
    self.view.layer.addSublayer(rectLayer) 
} 

색상이 서서히 나타나기를 원하지 않습니다. 나는 유리 충전 효과를 원한다. 멋진 물결 효과를 제외하고이

Water Filling Fancy

을 상상해보십시오.

+0

당신의 시야를 색에서 다른 색으로 점차 변화시키고 싶습니까? –

+0

빈에서 완전히 갈색으로 채워진 것 –

답변

1

더 나은 귀하의 질문을 이해 한 후에는 (파도의 애니메이션없이) 물 유리의 제출을 ​​시뮬레이션 할, 당신은 그것을 통해 얻을 수 있습니다

let myLayer: CALayer = .init() 
    myLayer.backgroundColor = UIColor.red.cgColor 
    self.view.layer.addSublayer(myLayer) 

    func animateFilling(to view:UIView) 
    { 
     var mFrame = CGRect(x: 0, y: view.frame.size.height, width: view.frame.size.width, height: 0) 
     myLayer.frame = mFrame 
     let fillingAnim = CABasicAnimation(keyPath: "bounds") 
     fillingAnim.fillMode = kCAFillModeForwards 
     fillingAnim.fromValue = mFrame 
     fillingAnim.duration = 2 
     fillingAnim.isRemovedOnCompletion = false 
     mFrame.size.height = 1000 
     fillingAnim.toValue = mFrame 
     myLayer.add(fillingAnim, forKey: nil) 
    } 
+0

죄송합니다. 설명에 충분하지 않을 경우. 그러나 나는 색깔이 서서히 나타나기를 원하지 않는다. 글래스 필링 효과와는 정반대의 효과를 원합니다. 다음을 제외하고 [this] (http://i1.wp.com/www.quartzcodeapp.com/wp-content/uploads/2015/03/water-fill-animation.gif?resize=300%2C300)의 반대를 상상해보십시오. 공상적인 물결 모양 효과. 그래서 내가'UIBezierPath'를 사용하고 있습니다. –

+0

빠른 응답을 해주셔서 감사합니다! –

+0

이 gif로 질문을 업데이트하면 사람들에게 더 명확 해집니다. –

1

을 내가 같이 그것을 쉽게 생각 당신이 정상파를 원하지 않는다면

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    let vv = UIView(frame: CGRect(x: 0, y: self.view.bounds.size.height, width: self.view.bounds.size.width, height: 0)) 

    vv.backgroundColor = UIColor.brown 

    self.view.addSubview(vv) 

    UIView.animate(withDuration: 5.0) { 


     vv.frame = CGRect(x: 0, y: self.view.bounds.size.height/3.0, width: self.view.bounds.size.width, height: self.view.bounds.size.height * 2/3.0) 

    } 

} 
+1

너무 감사합니다! –

관련 문제