performSelector:withObject:afterDelay: performs animation without animation
-
21-12-2019 - |
题
I have a method called by performSelector:withObject:afterDelay:
, which performs animation with duration. So after the delay, animation runs but without animation duration:
[self performSelector:@selector(animate:) withObject:[NSNumber numberWithInt:-1] afterDelay:4.0];
-(void) animate:(int) mode
{
[UIView animateWithDuration:0.2
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.center = CGPointMake(160.0, 568.0 + mode*height/2);
}
completion:nil];
}
Also, I cannot nest animations in completion:
because it blocks UI interaction.
解决方案
I've tried your code and animation duration works great but I think you should fix the (int) mode part. You can't cast NSNumber to int that way. Your method must be - (void)animate:(NSNumber*)mode and after you can cast to int with [mode intValue].
其他提示
You cannot use performSelector:withObject:afterDelay:
with animate:
because it has a parameter that is not object-pointer type.
不隶属于 StackOverflow