iOS開發之SceneKit框架--SCNView.h


1、SCNView

  在macOS中,SCNView是NSView的子類,在iOS和tvOS中,SCNView是UIView的子類。SCNView用於顯示SceneKit的3D場景,而需要設置場景的相關內容和屬性需要通過SCNScene。SCNView需要遵循SCNSceneRenderer協議和SCNTechniqueSupport協議。

 

2、相關API簡介

  • 初始化方法  
- (instancetype)initWithFrame:(CGRect)frame options:(nullable NSDictionary<NSString *, id> *)options;
  • 設置SCNScene場景
@property(nonatomic, retain, nullable) SCNScene *scene;
  • 對視圖進行配置
//視圖在什么時候重繪
//當YES時,視圖在顯示鏈接幀速率上繼續重繪。
//當設NO時,該視圖將只在某些改變或在接收器場景中動畫時重新繪制。默認為NO。
@property(nonatomic, assign) BOOL rendersContinuously;
//設置動畫幀速率 @property(nonatomic) NSInteger preferredFramesPerSecond API_AVAILABLE(macos(10.12));
//設置抗鋸齒模式me局 @property(nonatomic) SCNAntialiasingMode antialiasingMode API_AVAILABLE(macos(10.10));
  • 相機管理控制
//允許操縱相機,用戶可以改變視角的位置和方向
@property(nonatomic) BOOL allowsCameraControl;

//allowsCameraControl為YES時 獲取當前相機的相關配置(只讀屬性)
@property(nonatomic, readonly) id <SCNCameraControlConfiguration> cameraControlConfiguration API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0));

//allowsCameraControl為YES時 獲取默認相機控制器
@property(nonnull, nonatomic, readonly) SCNCameraController* defaultCameraController API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0));
  • 在視圖的場景中播放動作和動畫
//恢復播放視圖的場景。
- (IBAction)play:(nullable id)sender;

//暫停視圖場景的播放。
- (IBAction)pause:(nullable id)sender;

//停止回放視圖的場景,並將場景時間重置到其開始時間
- (IBAction)stop:(nullable id)sender;
  • 其它方法
//指定與接收器相關的EAGL上下文。
//如果當前API為金屬,則此屬性返回零,並沒有影響。
@property(nonatomic, retain, nullable) EAGLContext *eaglContext;

//截屏
- (UIImage *)snapshot API_AVAILABLE(macos(10.10));
  •  相關枚舉和結構體
#if defined(SWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH) && SWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH >= 3
typedef NSString * SCNViewOption NS_STRING_ENUM;
#else
typedef NSString * SCNViewOption;
#endif

//SCNRenderingAPI
FOUNDATION_EXTERN SCNViewOption const SCNPreferredRenderingAPIKey API_AVAILABLE(macos(10.11), ios(9.0)) __WATCHOS_UNAVAILABLE;

//The value is directly a id <MTLDevice>. 金屬
FOUNDATION_EXTERN SCNViewOption const SCNPreferredDeviceKey API_AVAILABLE(macos(10.11), ios(9.0));

//The value is a NSNumber wrapping a BOOL. Defaults to NO. 非金屬
FOUNDATION_EXTERN SCNViewOption const SCNPreferLowPowerDeviceKey API_AVAILABLE(macos(10.11), ios(9.0));

#define SCNViewOptionPreferredRenderingAPI SCNPreferredRenderingAPIKey
#define SCNViewOptionPreferredDevice       SCNPreferredDeviceKey
#define SCNViewOptionPreferLowPowerDevice  SCNPreferLowPowerDeviceKey

//相機控制器相關信息
API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
@protocol SCNCameraControlConfiguration <NSObject>
@property(nonatomic, assign) BOOL autoSwitchToFreeCamera;
@property(nonatomic, assign) BOOL allowsTranslation;
@property(nonatomic, assign) CGFloat flyModeVelocity; // in m/s
@property(nonatomic, assign) CGFloat panSensitivity;
@property(nonatomic, assign) CGFloat truckSensitivity;
@property(nonatomic, assign) CGFloat rotationSensitivity;
@end

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM