Xcode: dismiss camera overlay

Discussion in 'iOS Programming' started by IphoneD09, Jan 25, 2012.

  1. IphoneD09 macrumors newbie

    Joined:
    May 27, 2009
    #1
    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];
        }
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Where are your UIImagePickerControllerDelegate methods? And how does the (poorly named, IMO; use camel-case) tosecondview get called?
     
  3. IphoneD09 thread starter macrumors newbie

    Joined:
    May 27, 2009
    #3
    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!
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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?
     
  5. IphoneD09 thread starter macrumors newbie

    Joined:
    May 27, 2009
    #5
    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
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Sorry, but I'm not about to debug your project for you. That's your responsibility.
     
  7. IphoneD09 thread starter macrumors newbie

    Joined:
    May 27, 2009
    #7
    I'm just trying to find a solution. Never ment to insult you.
     
  8. phantax macrumors member

    Joined:
    Feb 2, 2009
    #8
    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
     

Share This Page