Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:46:38+00:00 2026-05-27T09:46:38+00:00

Environment: Xcode 4, ios 5, ipod touch 4th generation with retina display I am

  • 0

Environment: Xcode 4, ios 5, ipod touch 4th generation with retina display

I am trying to write a simple app that shows a video preview and capture a photo. For showing the preview, I am using the following code:

  // Create the session
    session = [[AVCaptureSession alloc] init];

    // Set preset to the highest available
    session.sessionPreset = AVCaptureSessionPresetPhoto;

    // Give the frame for preview
    CALayer *viewLayer = self.vPreview.layer;
    NSLog(@"viewLayer = %@", viewLayer);

    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = 
    [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

    captureVideoPreviewLayer.frame = self.vPreview.bounds;

    NSLog(@"Bounds: x:%d, y:%d,height:%d,width:%d",
          self.vPreview.bounds.origin.x,self.vPreview.bounds.origin.y,
          self.vPreview.bounds.size.height, self.vPreview.bounds.size.width);



    [self.vPreview.layer addSublayer:captureVideoPreviewLayer];

    // Get AV Device
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;

    // Add Input from the above device
    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
    if ( !input ) NSLog(@"ERROR: trying to open camera: %@", error);

    [session addInput:input];

I have the vPreview connected to an UIView on IB story board and it occupies the full screen. However, the frame always prints as 0,0,0,0 (x,y,h,w). Can some one pls tell me what is going wrong?

There are few more lines of code that set the output and runs the session. However, by this time, the frame is already wrong. Interestingly I can see the video preview however it shows in portrait where as my app is all landscape.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:46:38+00:00Added an answer on May 27, 2026 at 9:46 am

    Most likely this code is running in an init method before the view has actually been loaded from the NIB file. So when you call self.vPreview.bounds, self.vPreview is actually nil, giving a zero CGRect return value.

    With a UIViewController, the view is loaded lazily, so until something asks for the view property, the nib hasn’t been loaded.

    You should do your view customisation in the -viewDidLoad method. This is called once the nib has been loaded, and all your connected IBOutlets will be non-nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've been trying to test in-app purchases in a sandbox environment, but fail to
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
Short introduction Working on my first commercial iOS app, XCode 3.2 has proven to
I have an iPhone app that is currently using the test environment for iAds.
I'm building an iOS app that uses push notifications, and I'm finally ready to
Does Apple's Xcode development environment provide any tools for memory leak detection? I am
Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
I am doing unit testing on my iPhone app using OCUnit on XCode 3.2.3,
I recently released a new version of my iPhone app that was built for
I have an app for the iPhone developed on XCode 4. It works correctly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.