0

我很难修复我的代码。如何在不使用该addSubview方法的情况下添加和组合 2 个 UIImages?是否有任何可能的解决方案来组合 2 UIImages?。这是我的代码

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ 
    if (CGRectIntersectsRect(piece1.frame, piece2.frame))
    { 
        if (piece1.center.x < piece2.center.x) 
        { 
            NSLog(@"ok"); 
        }
    } 
}
4

1 回答 1

1

类似的东西。(我没有检查代码,请注意)。并且有多种混合模式可用。

CGRect drawRect = CGRectMake(0, 0, imageWidth, imageHeight);

UIGraphicsBeginImageContext(CGSizeMake(imageWidth, imageHeight));

[piece1 drawInRect: drawRect blendMode:kCGBlendModeNormal alpha:1];
[piece2 drawInRect: drawRect blendMode:kCGBlendModeScreen alpha:1];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  

UIGraphicsEndImageContext();
于 2012-07-27T01:15:07.123 回答