我对你的问题有点困惑,但我在https://github.com/NSGod/CustomSCNView上创建了一个示例项目,它可以做你正在寻找的东西。
首先,在ViewController
的视图中,故事板上并排摆放了2个CustomSCNView
。和你一样,我从IB调色板拖动2 SCNView
到视图,然后将自定义类设置为CustomSCNView
。
其次,是其定义如下CustomSCNView
类:
#import <Cocoa/Cocoa.h>
#import <SceneKit/SceneKit.h>
@interface CustomSCNView : SCNView
@property (nonatomic, assign) BOOL allowsRotation;
@end
你可以看到,它有一个allowsRotation
属性,其他任何对象都可以设置。
要设置allowsRotation
的默认值,比NO
等,可以覆盖initWithCoder:
这是当你在Interface Builder设置的意见像你这样有什么用:
#import "CustomSCNView.h"
@implementation CustomSCNView
- (id)initWithCoder:(NSCoder *)coder {
if ((self = [super initWithCoder:coder])) {
_allowsRotation = YES;
}
return self;
}
@end
的视图控制器则有2 IBOutlet
s到CustomSCNView
s。
#import <Cocoa/Cocoa.h>
#import <SceneKit/SceneKit.h>
@class CustomSCNView;
@interface ViewController : NSViewController
@property (weak) IBOutlet CustomSCNView *sView1;
@property (weak) IBOutlet CustomSCNView *sView2;
@end
ViewController。L:
#import "ViewController.h"
#import "CustomSCNView.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_sView1.allowsRotation = NO;
_sView2.allowsRotation = YES;
}
@end
你可以看到,在viewDidLoad
,你可以设置任何你想要两个视图中allowsRotation
财产。当您运行此应用程序时,会自动为您创建两个CustomSCNView
实例(通过initWithCoder:
),当加载故事板/笔尖文件时。无需创建CustomSCNView
的另一个实例即可设置已有的2个现有实例的属性。
我有一个愚蠢的,但必要的问题,你是否在其他类中添加CustomSCNView的导入语句? – fsb
你有没有尝试过'-initWithFrame:options:'? – mnuages
是的,我做到了。我没有为CustomSCNView类创建一个init方法。我认为[[CustomSCNView alloc] init]可以工作。 –