0

i have an issue with the following code:

I've implemented a simple ViewController named LayoutViewController, who shows a picture that automatically moves according to magnetic heading. the code consists in:

lm = [[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone;
[lm startUpdatingLocation];
lm.headingFilter = kCLHeadingFilterNone;
[lm startUpdatingHeading];

in view did load, then i implemented didUpdateHeading, where the animation is performed. Everything works FINE. In another view controller i placed a button and in the IBAction i put:

LayoutViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"LayoutViewController"];

and everything worked.

The problem is that if i try to use LayoutViewController as a camera overlay view, animation doesn't work.

i implemented:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];


    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.showsCameraControls = YES;
    picker.modalPresentationStyle = UIModalPresentationFullScreen;


    LayoutViewController* overlayView = [self.storyboard instantiateViewControllerWithIdentifier:@"LayoutViewController"];
    picker.cameraOverlayView=overlayView.view;

( [picker setCameraOverlayView:overlayView.view] instead of picker.cameraOverlayView=overlayView.view gives the same issue)

When doing that, it opens camera and i can see the picture i have in LayoutViewController, so LayoutViewController instance is successfully loaded, but no animation is performed because it seams didupdateheading is not being called.

Please help me!

Andrea
  • 1
  • 2

1 Answers1

0

Do you retain a 'LayoutViewController' object? Or do you only set it's view as a cameraOverlayView?

If you don't retain it, CLLocationManager will be deallocated too.

Jakub
  • 51
  • 1
  • Well i didn't retain it, i just write: LayoutViewController* overlayView = [self.storyboard instantiateViewControllerWithIdentifier:@"LayoutViewController"]; picker.cameraOverlayView=overlayView.view; Can you please tell me the way to retain it properly? Thank you! – Andrea Dec 29 '14 at 16:49
  • You can for example create an strong property to retain it: @property(strong,nonatomic) LayoutViewController* myRetainedController – Jakub Dec 30 '14 at 06:53