ios – 将CALayer设置为SCNMaterial的漫反射内容

过去几天,我一直在互联网上搜索无效.不幸的是,关于这个具体问题的苹果文档是模糊的,没有示例代码可用(至少这是我发现的).什么似乎是你可能会问的问题?

我试图设置一个uiview的图层作为用于渲染iPhone模型屏幕(Yep,trippy:P)的材质的内容. iPhone屏幕的UV映射设置为0到1,因此在将纹理/图层映射到纹素之后不会出现任何问题.

所以,而不是让这个层在iPhone上显示出来,与左图像相同,相反,我把这个渲染到iPhone上像右图

正确渲染错误的渲染

还要注意的是,当我设置一个断点并调试实际的iPhone节点并在Xcode中查看它时,会显示一个完全不同的渲染,并且当我继续执行时,该层被半固定:

现在…如何解决这个问题?我试过玩漫漫的内容变换矩阵,但没有任何修改.我也尝试将UIView的大小调整为256×256(因为UV似乎是256×256,如搅拌机中所示 – 3D建模包),但是并没有修复任何东西.

这是图层的代码

UIView *screen = [[UIView alloc] initWithFrame:self.view.bounds];
screen.backgroundColor = [UIColor redColor];

UIView *temp = [[UIView alloc] initWithFrame:CGRectMake(0,screen.bounds.size.width,60)];
temp.backgroundColor = [UIColor colorWithRed:0 green:(112.f/255.f) blue:(235.f/255.f) alpha:1];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(temp.bounds,40,0)];
label.frame = CGRectOffset(label.frame,0);
label.textColor = [UIColor colorWithRed:0 green:(48.f/255.f) blue:(84.f/255.f) alpha:1];
label.text = @"Select Track";
label.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:30];
label.minimumScaleFactor = 0.001;
label.adjustsFontSizetoFitWidth = YES;
label.lineBreakMode = NSLineBreakByClipping;
[temp addSubview:label];

UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0,temp.bounds.size.height - 2,temp.bounds.size.width,2)];
separator.backgroundColor = [UIColor colorWithRed:0 green:(48.f/255.f) blue:(84.f/255.f) alpha:1];
[temp addSubview:separator];
[screen addSubview:temp];
screen.layer.contentsGravity = kCAGravityCenter;

编辑
甚至更严厉的是,如果我使用以下方式捕获视图的UIImage:

- (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size,view.opaque,0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetimageFromCurrentimageContext();

    UIGraphicsEndImageContext();

    return img;
}

并使用它作为弥漫的内容…一切工作完全正常吗?这是真的很奇怪和令人沮丧,因为图像的大小是完全一样的uiview的…

编辑2

我最终只是使用视图的图像作为纹理,这使得事情比我需要的更加静态.我不会将此设为答案,因为即使在很长一段时间内,我仍然会等待正确解决这个问题.所以,如果你有一个答案,这个主题已经打开了很长时间,请碰到它,如果可以的话.这部分的文件太差了.

解决方法

SceneKit docs非常强烈地建议,虽然有些情况下您可以使用动画CALayers作为材料内容,但不包括UIView图层:

SceneKit cannot use a layer that is already being displayed elsewhere (for example,the backing layer of a UIView object).

这表明如果您想为您的材料制作动画内容,则您可以使用完全基于自己或者SpriteKit使用的核心动画.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...