我可以组合2个UIImages吗?

时间:2012-07-27 00:14:48

标签: objective-c ios5

我很难修复我的代码。如何在不使用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"); 
        }
    } 
}

1 个答案:

答案 0 :(得分:1)

类似于此的东西。 (我没有检查代码,要小心)。并且有各种各样的blendMode可用。

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();