iOS Xcode: dismiss camera overlay

IphoneD09

macrumors newbie
Original poster
May 27, 2009
9
0
I have an app showing the camera picture with a button on top.
This button should dismiss the camera view and go to the second view, but it doesn't.
It restarts the camera instead, and stays on the first view.
Can you have a look what i'm doing wrong?

An example project can be found here: http://wtrns.fr/P4oekRGDMncWLq

In the .h
Code:
    #import <UIKit/UIKit.h>

    #define CAMERA_TRANSFORM_X 1
    #define CAMERA_TRANSFORM_Y 1.12412
    #define SCREEN_WIDTH  320
    #define SCREEN_HEIGTH 480
     

    @interface ViewController : UIViewController{

    UIView *overlayView;}

    -(IBAction)tosecondview:(id)sender;
    @property (nonatomic, retain) IBOutlet UIView *overlayView;

    @end
in the .m

Code:
    @implementation ViewController

    @synthesize overlayView;


    -(IBAction)tosecondview:(id)sender{
    
    [self dismissModalViewControllerAnimated:NO];
    
    SecondViewController * mysecondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
    [mysecondViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
	[self presentModalViewController:mysecondViewController animated:YES];

    }

    ....

    - (void) viewDidAppear:(BOOL)animated {
    
      UIImagePickerController *picker = [[UIImagePickerController alloc] init];
      picker.sourceType = UIImagePickerControllerSourceTypeCamera;
      picker.showsCameraControls = NO;
      picker.navigationBarHidden = YES;
      picker.wantsFullScreenLayout = YES;
      picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
      picker.cameraOverlayView = overlayView;
      [self presentModalViewController:picker animated:NO];
    
        [super viewDidAppear:YES];
    }
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
Where are your UIImagePickerControllerDelegate methods? And how does the (poorly named, IMO; use camel-case) tosecondview get called?
 

IphoneD09

macrumors newbie
Original poster
May 27, 2009
9
0
Ah, forgot those in my example. I did them now. But the camera is still not dismissed...

Code:
@interface ViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

UIView *overlayView;
}
-(IBAction)tosecondview:(id)sender;
@property (nonatomic, retain) IBOutlet UIView *overlayView;

@end
tosecondview is called through a button in the interface.
Thank you for taking a look!
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
Well, you've shown that ViewController (another poorly-named thing, by the way; too vague) conforms to the UIImagePickerControllerDelegate protocol, but haven't shown the implementation of its methods. But, I don't think that's the issue.

So, are you certain that tosecondview is being called?
 

IphoneD09

macrumors newbie
Original poster
May 27, 2009
9
0
I'm positive about it being called. If get rid of the UIImagePicker code i do get to the actual second view on button press.

Here's a link to the test project. I would really aprreciate if you could take a look. I will take your advice on the naming stuff. Thank you.
http://wtrns.fr/P4oekRGDMncWLq
 

phantax

macrumors member
Feb 2, 2009
72
0
I downloaded your code and tried to run it.

1) You aren't checking that the device actually has a camera before trying to use it, meaning your code crashes on the simulator.

2) I don't see that either of your ViewControllers conforms to the UIImagePickerControllerDelegate protocol.

3) I do not see any of the UIImagePickerController delegate methods implemented in any of your ViewControllers.

From points 2 and 3 above, it should be obvious as to why your application isn't working as you expect it.

You should probably read through this UIImagePickerControllerDelegate Protocol Reference
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.