【发布时间】:2016-04-07 07:57:10
【问题描述】:
我试图在动画结束时调用一个方法,但在某些情况下,例如,当用户离开应用程序时,它的完成块永远不会被调用。 此外,当 VC 与 UIView 动画同时出现其动画时,完成块永远不会被调用。
即使动画以某种方式中断,我应该怎么做才能确保调用回调? 我应该根本不使用 UIView 动画完成块并使用其他东西吗?请赐教..!
-(void)action {
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.doorLeft.frame = CGRectMake(0, 0, self.doorLeft.frame.size.width, self.doorLeft.frame.size.height);
self.doorRight.frame = CGRectMake(self.frame.size.width -self.doorRight.frame.size.width, 0, self.doorRight.frame.size.width, self.doorRight.frame.size.height);
} completion:^(BOOL finished){
if (finished) {
switch (self.type) {
case 0:
[self.delegate startTOship];
break;
case 1:
[self.delegate gameTOship];
break;
case 2:
[self.delegate shipTOgame];
break;
case 3:
[self.delegate shipTOmap];
break;
case 4:
[self.delegate gameTOmap];
break;
case 5:
[self.delegate mapTOgame];
break;
case 6:
[self.delegate mapTOship];
break;
}
[UIView animateWithDuration:0.3
delay:0.5
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.doorLeft.frame = CGRectMake(-self.doorLeft.frame.size.width, 0, self.doorLeft.frame.size.width, self.doorLeft.frame.size.height);
self.doorRight.frame = CGRectMake(self.doorRight.frame.size.width *2, 0, self.doorRight.frame.size.width, self.doorRight.frame.size.height);
} completion:^(BOOL finished){
if (finished) {
[self actionEnded];
}
}
];
}
}
];}
【问题讨论】:
标签: objective-c uiview core-animation uiviewanimation caanimation