在我按下它之后,我正试图在collectionViewCell
上创建动画。我有CABasicAnimation
电话:
CGRect frame = self.sharingAnimationView.bounds;
//// Subframes
CGRect group = CGRectMake(CGRectGetMinX(frame) + floor(CGRectGetWidth(frame) * 0.02041 + 0.5), CGRectGetMinY(frame) + floor(CGRectGetHeight(frame) * 0.02041 + 0.5), floor(CGRectGetWidth(frame) * 0.97959 + 0.5) - floor(CGRectGetWidth(frame) * 0.02041 + 0.5), floor(CGRectGetHeight(frame) * 0.97959 + 0.5) - floor(CGRectGetHeight(frame) * 0.02041 + 0.5));
//// Oval Drawing
CGRect ovalRect = CGRectMake(CGRectGetMinX(group) + floor(CGRectGetWidth(group) * 0.00000 + 0.5), CGRectGetMinY(group) + floor(CGRectGetHeight(group) * 0.00000 + 0.5), floor(CGRectGetWidth(group) * 1.00000 + 0.5) - floor(CGRectGetWidth(group) * 0.00000 + 0.5), floor(CGRectGetHeight(group) * 1.00000 + 0.5) - floor(CGRectGetHeight(group) * 0.00000 + 0.5));
UIBezierPath* ovalPath = UIBezierPath.bezierPath;
[ovalPath addArcWithCenter: CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect)) radius: CGRectGetWidth(ovalRect) / 2 startAngle: -90 * M_PI/180 endAngle: 270 * M_PI/180 clockwise: YES];
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.sharingAnimationView.bounds;
pathLayer.path = ovalPath.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = [[UIColor blackColor] CGColor];
pathLayer.lineWidth = 1.5;
pathLayer.lineJoin = kCALineJoinBevel;
[self.sharingAnimationView.layer addSublayer:pathLayer];
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
这基本上会在sharingAnimationView
中创建一个圆圈,并将其涂成黑色。我从didSelectItemAtIndexPath
调用此方法,但似乎动画没有发生。
奇怪的是,如果我将动画调用移动到awakeFromNib
动画执行得很好。
有什么建议吗? 谢谢
答案 0 :(得分:0)
当你第一次运行一些UI更改(比如标准的UIActivityIndicator或自定义动画)以及下一个繁重的任务时,这是众所周知的行为。在这种情况下,RunLoop不会执行UI更改,因为它期望先前的UI周期完成。如果您在UI线程中运行业务逻辑,那么您的活动指示器根本没有机会被处理。尝试首先在didSelectItemAtIndexPath中启动你的动画,并将其余的方法放在单独的方法中,并在运行动画后立即调用它,延迟时间最短
[self performSelector:@selector(mySeparateMethod) withObject:nil afterDelay:0.1];