1

我正在编写基于快门过渡教程的自定义过渡。这很简单,第一个视图控制器旨在分成数百个部分,然后一次淡出一个,但问题是它在横向模式下不起作用。显然 CALayer 的“contentsRect”方法(它应该在标准化图像空间上工作)只能在纵向模式下工作。如果有人需要查看,我已将我的文件附在此处,如果你能帮助我,请。

http://tinyurl.com/88669oy

问候

这也是我的转码:

CALayer*        viewLayer;

- (void)transitWithImageView:(UIImageView *)imgView inView:(UIView *)view withImage:(UIImage *)img
{
     viewLayer = [imgView layer];
    [view.layer addSublayer:viewLayer];


    CGSize layerSize = viewLayer.bounds.size;


    // BEGINING OF MAKE ARRAY OF TRANSITIONS
    NSMutableArray* allTransitionsArr = [[NSMutableArray alloc] init]; 
       for ( int i = 0; i < BLOCK_COUNT; i++ )
    {
        CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
        fade.toValue =   [NSNumber numberWithFloat:-1-sqrt(i)];
        fade.autoreverses = NO;
        fade.duration = DURATION;
        [allTransitionsArr addObject: fade];
    }
    // END OF MAKE ARRAY OF TRANSITIONS



    NSMutableArray *blocks = [[NSMutableArray alloc] init];     
    [viewLayer removeFromSuperlayer];
        [CATransaction begin];

    [CATransaction setCompletionBlock:^(void) 
     {
         [blocks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) 
          {
              [obj setDelegate:nil];
              [obj removeFromSuperlayer];
          }];
         [view.layer addSublayer:viewLayer];
     }];

    CGFloat bandWidth   = layerSize.width / sqrt(BLOCK_COUNT);
    CGFloat bandHeight  = layerSize.height / sqrt(BLOCK_COUNT);


    int yVal = -1;
     for(int i = 0; i < BLOCK_COUNT; i++)
    {
        CALayer *block = [[CALayer alloc] init];
        block.masksToBounds = YES;
        CGFloat xOffset = 1.f / sqrt(BLOCK_COUNT);
        CGFloat yOffset = 1.f / sqrt(BLOCK_COUNT);
        block.bounds = CGRectMake(0, 0, bandWidth, bandHeight);
        block.bounds = CGRectMake(0.f, 0.f, bandWidth, bandHeight);
        block.contents = (id)[img CGImage];
        block.contentsGravity = kCAGravityCenter;

        CGPoint bandOrigin = viewLayer.frame.origin;
        bandOrigin.x = bandOrigin.x + (bandWidth * (i % (int)sqrt(BLOCK_COUNT)));

        if (i % (int)sqrt(BLOCK_COUNT) == 0 )
            yVal++;

        bandOrigin.y = bandOrigin.y + (bandHeight * yVal);

        // PROBLEM IS GOT TO BE HERE
        block.contentsRect = CGRectMake(xOffset * (i % (int)sqrt(BLOCK_COUNT)) ,yOffset * yVal, xOffset, yOffset);

        [block setValue:[NSValue valueWithCGPoint:bandOrigin] forKeyPath:@"frame.origin"];

        [view.layer addSublayer:block];
        [block addAnimation:[allTransitionsArr objectAtIndex: BLOCK_COUNT - i - 1] forKey:nil];
        [blocks addObject:block];
        [block release];
    }
    [CATransaction commit];
    [blocks release];
}
4

0 回答 0