jinios / swift-cardgameapp

솔리테어 카드게임앱 - 코드스쿼드 미션 (2018.04 - 2018.05)
0 stars 0 forks source link

카드를 움직일때 animation 적용 #22

Closed jinios closed 6 years ago

jinios commented 6 years ago

animation적용을 위해선 from & to 지점의 frame 값을 알아야 한다.

jinios commented 6 years ago
// 예시코드 
...

guard let cardView = startView.selectedView(currentPos) else { return }
        UIView.animate(
            withDuration: 0.5,
            animations: {
                cardView.frame.origin.x += move.x
                cardView.frame.origin.y += move.y

        },
            completion: { [weak self] _ in
                (startView as? TableauPilesView)?.insertLastSubview(at: currentPos.stackIndex)
                self?.moveCardViews(view: startView, tappedView: cardView, startIndex: currentPos.stackIndex)
        })
    }

...

animate()는 타입메소드로, 동작은 간단하다.