1
嘿傢伙,我有以下簡單的代碼: 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)[email protected]"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(透明)。
謝謝!