Xcode 动画延迟
我试图为我的动画设置一个延迟,所以一旦它出现然后消失,我想等待一定的秒数,让它重新出现。我试着在我的代码中把它放在多个地方,但结果都是一样的Xcode 动画延迟,xcode,delay,uiviewanimation,Xcode,Delay,Uiviewanimation,我试图为我的动画设置一个延迟,所以一旦它出现然后消失,我想等待一定的秒数,让它重新出现。我试着在我的代码中把它放在多个地方,但结果都是一样的 - (void) startRedDot { redDotTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self
- (void) startRedDot {
redDotTimer = [NSTimer scheduledTimerWithTimeInterval:1.5
target:self
selector:@selector(moveButtonWithAnimation)
userInfo:nil
repeats:YES];
[redDotTimer fire];
}
-(void) moveButtonRandomly {
CGSize limits;
CGPoint newPosition;
// Get limits
limits.width = gameView.frame.size.width - redButton.frame.size.width;
limits.height = gameView.frame.size.height - redButton.frame.size.height;
// Calculate new Position
newPosition = (CGPoint){ limits.width * drand48(), limits.height * drand48() };
// Set new frame
redButton.frame = (CGRect){ newPosition, redButton.frame.size };
}
- (void) moveButtonWithAnimation {
CGFloat fadeDurration;
if ( !redButton )
return; // only invoke the button if it exists
fadeDurration = 0.0f;
//Fade Out
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 0.0f;
} completion:^(BOOL finished) {
// Move the button while it is not visible
[self moveButtonRandomly];
[UIView setAnimationDelay:9.0];
// Fade in
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 4.0f;
}];
}];
}
setAnimationDelay应该用在beginAnimation和commitAnimation块中,这是在iOS中制作动画的老方法。在您的情况下,请尝试以下方法:
- (void) moveButtonWithAnimation {
CGFloat fadeDurration;
if ( !redButton )
return; // only invoke the button if it exists
fadeDurration = 2.0f;
//Fade Out
[UIView animateWithDuration: fadeDurration animations:^{
redButton.alpha = 0.0f;
} completion:^(BOOL finished) {
// Move the button while it is not visible
[self moveButtonRandomly];
[UIView animateWithDuration:fadeDurration delay:2.0 options:0 animations:^{
redButton.alpha = 1.0f;
} completion:nil];
}];
}它说脚本值不是数组对不起,我不明白你的错误是什么?脚本值不是数组?哪一行代码显示该错误?另外,我注意到您将动画的持续时间设置为0.0f。因此,它不会产生动画效果。您的按钮可能会立即出现和消失。我希望它会出现,然后消失,并在屏幕上停留一两秒钟。因此,您需要将fadeDuration设置为2.0f,而不是0.0。此外,alpha值的最大值为1.0,将其设置为4.0没有意义。当前延迟值为9秒,可能太长。