【问题标题】:Camera Overview in iPhone for Augmented Reality AppiPhone 中用于增强现实应用程序的相机概述
【发布时间】:2010-09-06 06:37:47
【问题描述】:

大家好,我有以下简单代码: 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(透明)。

谢谢!

【问题讨论】:

    标签: iphone uiview ios4 augmented-reality


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 2014-05-10
      相关资源
      最近更新 更多