2010-09-06 4 views
1

Hey Guys J'ai le code simple suivant: WhereAmIViewController.hPrésentation de la caméra dans l'iPhone pour la Réalité Augmentée App

#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 

Voilà ce que je suis l'affichage à l'écran. Je voulais juste savoir comment obtenir ces 3 étiquettes comme un aperçu de la caméra. Je me suis référé à http://www.musicalgeometry.com/archives/821 Mais avoir des problèmes comme le mien est "View Based App" et le tutoriel utilise un modèle "Application Windows" .. Comment puis-je configurer ce code pour obtenir la superposition de la caméra? P.S: La couleur de fond est: noColor (transparent).

Merci!

Répondre

1

Vous avez besoin d'un UIImagePickerController, puis vous créez un UIView et ajoutez vos 3 étiquettes aux emplacements appropriés dans la sous-vue, puis vous pouvez appeler, picker.cameraOverlayView = YOUR_UI_VIEW et picker.showsCameraControls = NO. Si vous avez déjà tout installé à l'intérieur de votre contrôleur WhereAmIView, vous pouvez faire picker.cameraOverlayView = whereAmIVC.view

Questions connexes