내 팝업 UIView의 배경색을 4 가지 색상 사이에서 변경하고 다시 반복하여 반복하려고합니다. 아래의 코드는 마지막 두 색상 만 나타나고, 처음 두 개는 건너 뛰고 있습니다. 생각해 볼 수있는 모든 것을 시도했습니다. 제가 누락 된 아이디어가 있습니까?swift 3 uiview 애니메이션은 마지막 두 애니메이션 만 표시합니다.
UIView.animateWithDuration(2, delay: 0.0, options:[UIViewAnimationOptions.Repeat, UIViewAnimationOptions.Autoreverse], animations: {
self.view.backgroundColor = UIColor.blackColor()
self.view.backgroundColor = UIColor.greenColor()
self.view.backgroundColor = UIColor.grayColor()
self.view.backgroundColor = UIColor.redColor()
}, completion: nil)
업데이트 코드 :
UIView.animate(withDuration: 12, delay: 1, options:
[UIViewAnimationOptions.allowUserInteraction,
UIViewAnimationOptions.repeat,
UIViewAnimationOptions.autoreverse],
animations: {
self.popupView.backgroundColor = UIColor.black
self.popupView.backgroundColor = UIColor.green
self.popupView.backgroundColor = UIColor.gray
self.popupView.backgroundColor = UIColor.red
}, completion:nil)
업데이트 2 : 개별 애니메이션 블록 : 모든
UIView.animate(withDuration: 3, delay: 0.0, options:
[UIViewAnimationOptions.repeat,
UIViewAnimationOptions.autoreverse,
.allowUserInteraction],
animations: { (BOOL) -> Void in
self.popupView.backgroundColor = UIColor.black
}) { (Bool) -> Void in
UIView.animate(withDuration: 3.0, animations: {() -> Void in
self.popupView.backgroundColor = UIColor.green
}, completion: { (Bool) -> Void in
UIView.animate(withDuration: 3.0, animations: {() -> Void in
self.popupView.backgroundColor = UIColor.gray
}, completion: { (Bool) -> Void in
UIView.animate(withDuration: 3.0, animations: {() -> Void in
self.popupView.backgroundColor = UIColor.white
}, completion:nil)
})
})
}
정확하게 무엇을 원하지만 코드의 결과로 배경색이 빨간색으로 바뀝니다. 대부분의 시간에는 다른 색상이 표시되지 않습니다. 애니메이션 블록에서 색상을 변경해도 색상이 변경되지 않습니다. – Ryan
나는 하나씩 색을 반복하고 싶다. 기간을 연장 할 수는 있지만 여전히 회색과 빨간색으로 표시됩니다. – Berro
완료 블록에있는 별도의 애니메이션 블록에 각 색상 변경 사항을 입력해야합니다. – Ryan