开发者

Make iphone camera as a magnifying lens

开发者 https://www.devze.com 2023-02-10 06:43 出处:网络
I have an application called magnifying lens .Here I need to start the camera at the time of appliaction starts itself.How can I possible to start the camera while starting the app?

I have an application called magnifying lens .Here I need to start the camera at the time of appliaction starts itself.How can I possible to start the camera while starting the app?

I have the camera active code here

    // Create image picker controller
  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

  // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;

  // Delegate is self
    imagePicker.delegate = self;

  // Allow editing of image ?
    imagePicker.allowsImageEditing = NO开发者_如何学Python;

  // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 

But I don't know where to place this code for start the camera at the time when the application starts.I put the code in the viewdidLoad method .But it didn't give me the desired result.

I am very new to this if you can suggest me an idea it will be very useful to me.

Thanks in advance Priya


@ Priya,

Where did you put that code? in app delegate the code won't work. first add a viewController's view to window. then in that view controller's viewDidLoad method put your code. Let me know your feedback


@Priya Ok I solved the issue. Put your code in viewDidAppear method. Implement the method on mainviewController. Here is what I did added Protocols in the interface file like this @interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate > and here is the viewDidAppear method

- (void)viewDidAppear:(BOOL)animated {

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

        // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

        // Delegate is self
    imagePicker.delegate = self;

        // Allow editing of image ? //Deprecated
    imagePicker.allowsImageEditing = NO;

        //Use this instead
    imagePicker.allowsEditing = NO;
        // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号