내 문제는 내 UIView 애니메이션이 처음으로 작동한다는 것입니다. 애니메이션에는 두 가지 세트가 있습니다. 첫 번째 세트가 올바르게 작동하고 두 번째 세트가 문제를 일으 킵니다. 첫 번째 세트는 4 개의 버튼을 화면에서 원하는 위치보다 조금 더 멀리 슬라이드시킵니다. (내가 extendedState라고 부르는 이러한 위치) 두 번째 애니메이션 세트는 원하는 위치로 약간 뒤로 미십시오. 이것은 올바른 지점으로 되돌아 오는 효과를줍니다.첫 번째 시도에서 UIView 애니메이션이 움직이지 않는다
두 애니메이션 사이에는 첫 번째 애니메이션 세트가 완료되면 버튼이 시작 위치로 깜박입니다. 시작 위치를 extendedStates (움직이는 것을 멈출 때의 위치)로 설정하면 버튼이 애니메이션 사이를 이동하지 않는 것처럼 보입니다. (좋아요.) , I (이 애니메이션의 제 2 세트를 실행
- I는 animationDidStop 블록 (완벽하게 잘 작동) 애니메이션의 제 1 세트
- 발사 버튼을 누른 다음은 조작 순서의
,536,913 : 첫 번째 시도에 애니메이션을하지 않는 한) 여기@IBAction func selectAnimal(sender: UIButton) { showButtons() bigCircle.enabled = false enableButtons() if(tapToSelectLabel.hidden) { animator.repositionButtonsToExtendedState(buttons) //sets the starting position to the extendedState so it appears not to move between animations animator.slideButtonsIntoScreen(buttons, delegate: self) //this is the first set of animations } if(sender.titleLabel != nil) { if(bigCircleLabel.text != "Choose an animal") { if let answer:String = bigCircleLabel.text { solution = game.checkAnswer(answer, question: game.threeQuestions[game.questionIndex]) } showResponse() } } }
이 단추 처리기에 대한 코드입니다입니다 63,210
지금 여기 여기.
을
let buttonRects:[CGRect] = [CGRectMake(834, 120, 175, 175),
CGRectMake(631, 198, 175, 175),
CGRectMake(470, 365, 175, 175),
CGRectMake(386, 578, 175, 175)]
UIView.animateWithDuration(0.35, delay: 0, options: [.BeginFromCurrentState, ], animations: {
self.buttons[3].frame = buttonRects[3]
}, completion: { (value:Bool) in
self.buttons[3].enabled = true
UIView.animateWithDuration(0.25, delay: 0, options: [ ], animations: {
self.buttons[2].frame = buttonRects[2]
}, completion: { (value:Bool) in
self.buttons[2].enabled = true
UIView.animateWithDuration(0.4, delay: 0, options: [ ], animations: {
self.buttons[1].frame = buttonRects[1]
}, completion: { (value:Bool) in
self.buttons[1].enabled = true
UIView.animateWithDuration(0.5, delay: 0, options: [ ], animations: {
self.buttons[0].frame = buttonRects[0]
}, completion: { (value:Bool) in
self.buttons[0].enabled = true
})
})
})
})
이 ^이 코드는 내가 그들에 있어야 할 자리에 뒤로 버튼이 약간의 슬라이딩 animationDidStop 블록 내부의 코드의 내 애니메이터 클래스
에 대한 코드입니다animator.slideButtonsIntoScreen
func slideButtonsIntoScreen(buttons:[UIButton], delegate:UIViewController) {
let center = CGPoint(x:delegate.view.frame.width, y:delegate.view.frame.height)
let startAngles:[CGFloat] = [0.405, 0.75, 1.1, 1.48]
let endAngles:[CGFloat] = [1.95, 2.25, 2.622, 2.98]
let radii:[CGFloat] = [555, 559, 558.5, 551]
let durations:[Double] = [1.75, 1.5, 1.25 , 1]
for index in 0...3 {
let path = UIBezierPath(arcCenter: center, radius: radii[index], startAngle: -startAngles[index], endAngle: -endAngles[index], clockwise: false)
let anim = CAKeyframeAnimation(keyPath: "position")
anim.path = path.CGPath
anim.rotationMode = kCAAlignmentNatural
anim.repeatCount = 0
anim.duration = durations[index] - 0.25
anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
anim.setValue("on", forKey: "type")
anim.delegate = delegate
buttons[index].layer.addAnimation(anim, forKey: "animate position along path"+String(index))
anim.removedOnCompletion = true
}
}
animator.repositionButtonsToExtendedState
func repositionButtonsToExtendedState(buttons:[UIButton]) {
let buttonExtendedRects:[CGRect] = [CGRectMake(755, 155, 175, 175),
CGRectMake(585, 245, 175, 175),
CGRectMake(450, 405, 175, 175),
CGRectMake(393, 590, 175, 175)]
for index in 0...3 {
buttons[index].frame = buttonExtendedRects[index]
}
}
나는 중단 점 및 인쇄 문을 설정, 그래서 나는 그것이 첫 번째 시도에서 애니메이션에 도달하는 사실, 그냥 애니메이션을 표시하지 않습니다 알고있다. 첫 번째 이후 매번 정확하게 작동합니다.
코드가 모든 곳에서 보이는 것처럼 보입니다. 빈 프로젝트를 만들고 문제의 [Minimal, Complete, Verifiable example] (http://stackoverflow.com/help/mcve)을 추가하십시오. – JAL
AutoLayout을 사용하는 경우 프레임 대신 구속 조건을 애니메이션화해야합니다. –