【发布时间】:2015-03-26 10:37:48
【问题描述】:
我试图在按下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,动画执行得很好。
有什么建议吗? 谢谢
【问题讨论】:
标签: ios objective-c uicollectionviewcell cabasicanimation