用alpha蒙版过渡

时间:2013-05-02 22:10:15

标签: ios view controller transition mask

我想用这种方法在两个视图控制器之间创建一个过渡:

-(void)animate {

    UIImage *maskingImage = [UIImage imageNamed:@"mask.png"];
    CALayer *maskLayer =[CALayer layer];
    maskLayer.anchorPoint=CGPointMake(0.5, 0.5);
    maskLayer.frame=self.view.superview.frame;
    maskLayer.contents=(id)self.maskingImage.CGImage;
    self.view.layer.mask=maskLayer;

    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    anim.duration = 2.5;
    anim.toValue=[NSNumber numberWithInt:self.view.bounds.size.height/8];
    anim.fillMode=kCAFillModeBoth;
    anim.removedOnCompletion=NO;
    anim.delegate = self;
    [self.view.layer.mask addAnimation:anim forKey:nil];
}

我的错误在哪里?我尝试过像这样的其他过渡,它的确有效:

-(void)animate {

    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    anim.toValue = [NSNumber numberWithDouble:0.9];
    anim.duration = 0.5;
    anim.delegate = self;
    [self.view.layer addAnimation:anim forKey:nil];
}

mask.png是一个黑色矩形,带有居中的白色圆圈

0 个答案:

没有答案