我已经写了一些代码,我希望能随机旋转一个街区进入屏幕上的视图,暂停,然后旋转它。这种行为应该以一种半随机的方式重复。然而,这类作品显示的是块,旋转,然后在一段时间后再次显示出来:
我在这个密码里漏掉了什么重要的东西?
-(void)randomlyShowBlock{
int randomTime = 1 + arc4random() % (3 - 1);
[RandomBlock setNeedsDisplay];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, randomTime * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
int randomX = 10 + arc4random() % ((int)self.view.frame.size.width - 10);
int randomY = 10 + arc4random() % ((int)self.view.frame.size.height - 10);
RandomBlock.frame = CGRectMake(randomX, randomY, RandomBlock.frame.size.width, RandomBlock.frame.size.height);
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
RandomBlock.transform = CGAffineTransformMakeRotation(DegreesToRadians(-90));
RandomBlock.backgroundColor = [[UIColor alloc] initWithRed:50.0/255.0 green:124.0/255.0 blue:203.0/255.0 alpha:1.0];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.4 delay:1 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
RandomBlock.transform = CGAffineTransformMakeRotation(DegreesToRadians(0));
RandomBlock.backgroundColor = [[UIColor alloc] initWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:0];
}
completion:^(BOOL finished){
NSLog(@"finished animation");
//model
[self randomlyShowBlock];
}];
}];
});
}发布于 2013-08-15 22:49:29
你不会改变动画中的框架,所以它不动也就不足为奇了。
至于旋转,我的猜测是,转换最初不是一个身份转换,而是一个零转换,iOS不知道如何从零到什么动画。在动画块之前,尝试将其设置为CGAffineTransformIdentity。
https://stackoverflow.com/questions/18263069
复制相似问题