iOS PanoramaGL(全景展示)用法

来源:互联网 发布:小学生合适学编程吗 编辑:程序博客网 时间:2024/05/29 16:50

     初做项目,两次涉及到了360度全景展示(也可以是720的旋转),查找了很多资料,基本都是用PanoramaGL这个库实现的,下面我就这两次用这个库出现的问题以及应项目需求在库里做的改动简单的总结一下。技术就是前人栽树,后人乘凉,我老在大树下乘凉心里有点过意不去,时不时的也种点小树苗。大笑


    在code4app里面用到的那个库其实只是基础,不完善,灵活度和可操作性都不够,所以建议大家舍弃这个库,直接在csdn里面下载。下载地址:http://download.csdn.net/detail/pingyan88/5697173


   PanoramaGL用法:将库下载下来导入项目中,并添加相关的依赖框架(框架缺一不可),但并不是单纯的导入框架就可以了,我自己在第一次导入的时候做了很多修改,那错误就像个无底洞,但后来几次就轻松多了,主要是得对照源代码在

Build Settings 里进行配置。(由于要修改的地方太多,这里就不一一列举出来了。)


     因为,这个库是12年更新的,所以没有使用ARC,如果,你引用了它的库,你会发现ARC错误,即使你全部加上-fno-objc-arc,你也会发现**变量的错误,网上有改正的方法,但是有的地方,改了还是报错,而且许多地方都要更改(**,-fno-objc-arc),所以,我选择建立工程后,把工程修改为不适用ARC,对自己新建的文件修改,添加-f-objc-arc,使用ARC。这样即使报错,双击fix一下就编译通过了。


     多说无益,直接上代码。


- (void)viewDidLoad

{

    

    [super viewDidLoad];


    plView = (PLView *)self.view;

    plView.delegate = self;

    plView.PLdelegate =self;

   panorama =nil;

    cubicPanorama= [PLCubicPanorama panorama];

    //下面就是核心代码,用6张JPG的图片来实现。相当于拼成了一个正方体。

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_f" ofType:@"jpg"]]] face:PLCubeFaceOrientationFront];

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_b" ofType:@"jpg"]]] face:PLCubeFaceOrientationBack];

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_l" ofType:@"jpg"]]] face:PLCubeFaceOrientationLeft];

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_r" ofType:@"jpg"]]] face:PLCubeFaceOrientationRight];

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_u" ofType:@"jpg"]]] face:PLCubeFaceOrientationUp];

    [cubicPanorama setTexture:[PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"quito1_d" ofType:@"jpg"]]] face:PLCubeFaceOrientationDown];

    panorama = cubicPanorama;

    

    [plView setPanorama:panorama];

    

   //改变初始化的位置(有些项目需要点击全景进去是指定的某一个角度)

     [panorama.currentCamera lookAtWithPitch:0.0f yaw:40.0f];(具体角度根据需要调整)

    currentCamera = panorama.currentCamera;


    

    //添加热点(这个类可以实现在全景里面添加按钮,并且按钮跟随场景的转动而转动。有的需求是,当转动到某一个页面时,随之出现一个按钮,后面会说到)

    PLTexture *hotspotTexture = [PLTexture textureWithImage:[PLImage imageWithPath:[[NSBundle mainBundle] pathForResource:@"360_f_arrow@2x" ofType:@"png"]]];

    PLHotspot *hotspot = [PLHotspot hotspotWithId:1 texture:hotspotTexture atv:-20.0f ath:-40.0f width:0.08f height:0.08f];(角度是相对场景而调整,可自设置)

    //width height热点大小 atv上正数下负数 ath位置右边正数 左边负数

    [panorama addHotspot:hotspot];

  当旋转到某一个页面的时候出现一个按钮(yaw是横向,pitch是纵向

if ((camera.yaw <90.f && camera.yaw >=0 && !isshow)) //|| (camera.pitch <10 && camera.pitch >5.f))

    {

        self.curtainLabel = [[UIButton alloc]initWithFrame:CGRectMake(290, 0, 30, 30)];

        self.curtainLabel.backgroundColor = [UIColor blueColor];

        self.curtainLabel.layer.cornerRadius = 5.0f;

        self.curtainLabel.hidden = YES;

        self.curtainLabel.layer.shadowColor = [UIColor blackColor].CGColor;

        self.curtainLabel.layer.shadowOffset = CGSizeMake(2, 2);

        

       //添加触发到视频也的按钮

        [self.curtainLabel addTarget:self action:@selector(curtainBtn) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:self.curtainLabel];

        

    }

}
//下面位按钮触发的事件,可根据需求执行操作

-(void)view:(UIView<PLIView> *)pView didClickHotspot:(PLHotspot *)hotspot screenPoint:(CGPoint)point scene3DPoint:(PLPosition)position

{

    NSLog(@"hhhhhh");

}

   前面有说到,该库支持360和720旋转。具体修改旋转角度是在Plconstants类里面     

    

  


我项目中所涉及的技术也就这些吧。如果还有别的功能,大家就自己在研究研究吧。

1 0
原创粉丝点击