https://github.com/bestswifter/BSPanoramaView
OpenGL !
Usage
#import "BSPanoramaView.h"
- (void)viewDidLoad {
[super viewDidLoad];
BSPanoramaView *panoView = [[BSPanoramaView alloc] initWithFrame:self.view.bounds imageName:@"test"];
[self.view addSubview:panoView];
}
- (void)setImageWithName:(NSString *)imageName {
self.shouldUnload = NO;
/// 將圖片轉(zhuǎn)換成為紋理信息,由于OpenGL的默認(rèn)坐標(biāo)系設(shè)置在左下角, 而GLKit在左上角, 因此需要轉(zhuǎn)換
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], GLKTextureLoaderOriginBottomLeft, nil];
UIImage *textureImage = [UIImage imageNamed:imageName];
GLKTextureLoader *loader = [[GLKTextureLoader alloc] initWithSharegroup:self.context.sharegroup];
[loader textureWithCGImage:textureImage.CGImage options:options queue:dispatch_get_main_queue() completionHandler:^(GLKTextureInfo * _Nullable textureInfo, NSError * _Nullable outError) {
if (self.shouldUnload) { // 因?yàn)槭钱惒郊虞d,所以需要考慮調(diào)用完 unloadImage 才加載成功的情況
[[PanoramaManager sharedInstance] unRegisterView:self];
GLuint name = textureInfo.name;
glDeleteTextures(1, &name);
glDrawElements(GL_TRIANGLES, self.numIndices, GL_UNSIGNED_SHORT, 0);
return ;
}
/// 設(shè)置著色器的紋理
self.effect = [[GLKBaseEffect alloc] init];
self.effect.texture2d0.enabled = GL_TRUE;
self.effect.texture2d0.name = textureInfo.name;
}];
}