I am trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
The only thing I am having trouble with is changing the size and location of a UIView object. The problem is I am using apple's sample code and it's just not making sense for me.
Apple provides this sample VC that I have called MediaCapturePreviewView. Here is the header file code:
#import <UIKit/UIKit.h>
@class AVCaptureSession;
@interface MediaCapturePreviewView : UIView
@property (nonatomic) AVCaptureSession *session;
@end
Here is it's main file code:
#import "MediaCapturePreviewView.h"
#import <AVFoundation/AVFoundation.h>
@implementation MediaCapturePreviewView
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
+ (Class)layerClass
{
return [AVCaptureVideoPreviewLayer class];
}
- (AVCaptureSession *)session
{
return [(AVCaptureVideoPreviewLayer *)[self layer] session];
}
- (void)setSession:(AVCaptureSession *)session
{
[(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
}
@end
Then in my app's central View Controller, I have imported the header file of "MediaCapturePreviewView" that I just showed you. Last but not least, in my central view controller's main file I have an IBOutlet in the interface area that looks like this:
@property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
The above IBOutlet has been connected to a UIView object in Interface Builder that covers the entire iPhone screen.
And then here is a small example of how previewView is used when you tap the "take a picture" button:
- (IBAction)snapStillImage:(id)sender
{
dispatch_async([self sessionQueue], ^{
// Update the orientation on the still image output video connection before capturing.
[[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
I have tried adding in this code right after the above method calls but it is not helping:
_previewView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.frame.size.height/2);
I know that you can edit properties for CALayer class objects like frame, bounds, and position but I'm just stuck and don't know where exactly I need to edit these things.
This is what the current UIView looks like when taking a picture:
And this is what I need it to look like:
I basically need it to take up exactly the top 50% of the iPhone's screen.
Any help is greatly appreciated thank you.