2011-04-30 5 views

답변

8

코어 애니메이션과 CAKeyFrameAnimation을 사용하여 커브 포인트를 정의 할 수 있습니다. 이 자습서를 참조하십시오. http://nachbaur.com/2011/01/07/core-animation-part-4/

+0

사용자 정의보기의 레이어 애니메이션 감사... 나는 –

+0

을 검사 할 것입니다.이 예제는 전체보기가 아닌 레이어의 애니메이션을 나타냅니다. 어디 경로를 따라 전체 UIView 이동해야 할 경우가 있습니다. animateWithDuration을 사용하여 여기에서부터 쉽게 얻을 수는 있지만, 주어진 경로를 사용하여 여기에서부터 얻는 방법을 볼 수는 없습니다. animateWithDuration 호출을 함께 묶으려고하면 마지막 호출은 항상 이전 호출을 취소합니다. – EFC

-6

애니메이션을 완료 절에 중첩하여 스택 할 수 있습니다. 하나 이상

0

은에 의해 achived 할 수 있습니다 : -

내가) CAKeyframeAnimation II) Create Curve Path III)

import UIKit 
import CoreGraphics 
class ViewController: UIViewController { 

    var moveAlongPath:CAAnimation! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     addAnimation() 
     initiateAnimation() 
    } 

    func curevedPath() -> UIBezierPath { 

     let path = createCurvePath() 

     let shapeLayer = CAShapeLayer() 
     shapeLayer.path = path.cgPath 
     shapeLayer.strokeColor = UIColor.blue.cgColor 
     shapeLayer.fillColor = UIColor.clear.cgColor 
     shapeLayer.lineWidth = 1.0 
     self.view.layer.addSublayer(shapeLayer) 
     return path 
    } 


    func addAnimation() { 
     let moveAlongPath = CAKeyframeAnimation(keyPath: "position") 
     moveAlongPath.path = curevedPath().cgPath 
     moveAlongPath.duration = 5 
     moveAlongPath.repeatCount = HUGE 
     moveAlongPath.calculationMode = kCAAnimationPaced 
     moveAlongPath.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)] 
     self.moveAlongPath = moveAlongPath 
    } 

    func initiateAnimation() { 
     let layer = createLayer() 
     layer.add(moveAlongPath, forKey: "animate along Path") 
    } 

    //MARK:- Custom View Path 
    func createLayer() -> CALayer { 
     let customView = CustomView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) 
     self.view.addSubview(customView) 
     let customlayer = customView.layer 
     customlayer.bounds = CGRect(x: 0, y: 0, width: 50, height: 50) 
     customlayer.position = CGPoint(x: 25, y: 25) 
     return customlayer 
     } 

    //MARK:- Custom Curve Path 
    func createCurvePath() -> UIBezierPath { 
     let path = UIBezierPath() 
     path.move(to: CGPoint(x: 10, y: 200)) 
     path.addQuadCurve(to: CGPoint(x: 300, y: 200), controlPoint: CGPoint(x: 150, y: 10)) 
     return path 
    } 

} 


class CustomView:UIView { 

    override init(frame: CGRect) { 
     super.init(frame: frame) 
     setUpView() 
    } 

    func setUpView() { 
     let image = UIImage(named: "Go.png") 
     let imageView = UIImageView(image: image) 
     imageView.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height) 
     addSubview(imageView) 
    } 

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

} 

enter image description here

Demo Reference

관련 문제