用于增强现实应用的iPhone相机概述

时间:2010-09-06 06:37:47

标签: iphone uiview ios4 augmented-reality

嘿伙计我有以下简单代码: WhereAmIViewController.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

WhereAmIViewController.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:背景颜色为:noColor(透明)。

谢谢!

1 个答案:

答案 0 :(得分:1)

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