我想从不同的图像视图中添加两个图像,以使它们具有 3d 外观,使两个图像相互重叠,当用户显示图像时,它显示两个图像,当用户将他们的 iPhone 左右移动时,它显示一个图像(只显示一个图像,另一个图像消失)像全息图。
请帮助我一个对我来说非常重要的人。谢谢你......!!
当您想显示像全息图这样的图像然后只显示一个时,一种可能的方法是:
它可能会有所帮助。
尝试使用此代码合并两个图像
UIGraphicsBeginImageContext(firstImage.size);
[firstImage drawAtPoint:CGPointMake(0,0)];
[secondImage drawAtPoint:CGPointMake(0,0)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
您可以使用此代码。
+ (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second
{
// get size of the first image
CGImageRef firstImageRef = first.CGImage;
CGFloat firstWidth = CGImageGetWidth(firstImageRef);
CGFloat firstHeight = CGImageGetHeight(firstImageRef);
// get size of the second image
CGImageRef secondImageRef = second.CGImage;
CGFloat secondWidth = CGImageGetWidth(secondImageRef);
CGFloat secondHeight = CGImageGetHeight(secondImageRef);
// build merged size
CGSize mergedSize = CGSizeMake(MAX(firstWidth, secondWidth), MAX(firstHeight, secondHeight));
// capture image context ref
UIGraphicsBeginImageContext(mergedSize);
//Draw images onto the context
[first drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
[second drawInRect:CGRectMake(0, 0, secondWidth, secondHeight)];
// assign context to new UIImage
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// end context
UIGraphicsEndImageContext();
return newImage;
}
或者试试这个链接。