【发布时间】:2016-03-06 17:56:29
【问题描述】:
我想根据如下截图所示的材料设计实现两个 UIView 之间的过渡动画(仅动画的第一部分):
但我想通过将动画蒙版应用于 UIView 使其更加逼真。这是我开发的代码:
- (IBAction)onButtonTapped:(UIButton *)sender
{
// 1. make a hole in self.view to make visible another view
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
[maskPath appendPath:[UIBezierPath bezierPathWithArcCenter:sender.center
radius:sender.frame.size.width/2.0f
startAngle:0.0f
endAngle:2.0f*M_PI
clockwise:NO]];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.fillColor = [UIColor blackColor].CGColor;
maskLayer.path = maskPath.CGPath;
// 2. add scale animation for resizing hole
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSValue valueWithCGRect:sender.frame];
animation.toValue = [NSValue valueWithCGRect:self.view.bounds];
animation.duration = 3.0f;
[maskLayer addAnimation:animation forKey:@"scaleAnimation"];
self.view.layer.mask = maskLayer;
}
我的想法是在模态 UIView 中添加一个“洞”,然后缩放机智动画。
问题是它不能正常工作。代码的第一部分很好地打了一个洞。但是孔的缩放动画根本不起作用。
【问题讨论】:
标签: ios objective-c animation uiview material-design