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