代码之家  ›  专栏  ›  技术社区  ›  Omkar Jadhav

iPhone中用于增强现实应用程序的摄像头概述

  •  1
  • Omkar Jadhav  · 技术社区  · 14 年前

    嘿,伙计们,我有以下简单的代码: 其中amiviewcontroller.h

        #import <UIKit/UIKit.h>
        #import <CoreLocation/CoreLocation.h>
    
        @interface WhereAmIViewController : UIViewController <CLLocationManagerDelegate> {
    
            CLLocationManager *locationManager;
            CLLocation *startingPoint;
            IBOutlet UILabel *latitudeLabel;
            IBOutlet UILabel *longitudeLabel;
            IBOutlet UILabel *magneticHeading;
        }
        @property (retain, nonatomic) CLLocationManager *locationManager;
        @property (retain, nonatomic) CLLocation *startingPoint;
        @property (retain, nonatomic) UILabel *latitudeLabel;
        @property (retain, nonatomic) UILabel *longitudeLabel;
        @property (nonatomic, retain) UILabel *magneticHeading;
    
    @end
    

    其中amiviewcontroller.m

    #import "WhereAmIViewController.h"
    
    @implementation WhereAmIViewController
    @synthesize locationManager;
    @synthesize startingPoint;
    @synthesize latitudeLabel;
    @synthesize longitudeLabel;
    @synthesize magneticHeading;
    
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {
    
        NSString *magneticstring = [[NSString alloc] initWithFormat:@"%0.0f°",
                                    newHeading.magneticHeading];
        magneticHeading.text = magneticstring;
        [magneticstring release];
    }
    
    
    
    
    #pragma mark -
    -(void)viewDidLoad
    {
        self.locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
        [locationManager startUpdatingHeading];
    }
    
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [locationManager release];
        [startingPoint release];
        [latitudeLabel release];
        [longitudeLabel release];
        [super dealloc];
    }
    #pragma mark -
    #pragma mark CLLocationManagerDelegate Methods
    -(void)locationManager:(CLLocationManager *)manger
            didUpdateToLocation:(CLLocation *)newLocation
            fromLocation:(CLLocation *)oldLocation
    {
    
        if(startingPoint == nil)
            self.startingPoint = newLocation;
    
        NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
        latitudeLabel.text = latitudeString;
        [latitudeString release];
        NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
        longitudeLabel.text = longitudeString;
        [longitudeString release];
    
    }
    
    -(void)longitudeManager:(CLLocationManager *)manager
                             didFailWithError:(NSError *)error
    {
                                 NSString *errorType = (error.code ==kCLErrorDenied)?@"Access Denied":@"Unknown Error";
                                 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error Getting Location!" message:errorType delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                 [alert show];
                                 [alert release];
    }
    
    @end
    

    所以这就是我在屏幕上显示的……我只想知道如何得到这3个标签作为相机的概述。我已经提到 http://www.musicalgeometry.com/archives/821 但是像我这样有困难的是“基于视图的应用程序”,并且本教程使用了“基于Windows的应用程序”模板。如何配置此代码以获取摄像头覆盖? P.S:背景色为:无彩色(透明)。

    谢谢您!

    1 回复  |  直到 14 年前
        1
  •  1
  •   vodkhang    14 年前

    您需要一个uiImagePickerController,然后创建一个uiView并在子视图的适当位置添加3个标签,然后您可以调用, picker.cameraOverlayView = YOUR_UI_VIEW picker.showsCameraControls = NO . 如果已经在WhereMiviewController中设置了所有内容,那么可以执行以下操作 picker.cameraOverlayView = whereAmIVC.view