Shubhank
Shubhank

Reputation: 21805

Resizable View using user touch

This is in continuation from this question.

enter image description here

So to sum it short :

1) I want to have resizable view camera in my app. I went to this repo, downloaded it and implemented it.

2)

AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer =
  [[AVCaptureVideoPreviewLayer alloc] initWithSession:
    [[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];

CGRect frame = CGRectMake(50, 50, 200, 150);
userResizableView = [[SPUserResizableView alloc] initWithFrame:frame];
// CALayer *viewLayer = [userResizableView layer];
userResizableView.delegate =self;
[view setBackgroundColor:[UIColor clearColor]];
userResizableView.contentView =view;
[self.view addSubview:userResizableView];
// [contentView release]; 
[userResizableView release];
CGRect bounds = [view bounds];

[newCaptureVideoPreviewLayer setFrame:bounds];

3) in my delegate method

- (void)userResizableViewDidEndEditing:(SPUserResizableView *)userResizableView
{
    CGRect ResizableViewFrame = self.userResizableView.frame;
    NSLog(@" %f--- %f--- %f--- %f ---",userResizableView.frame.origin.x,userResizableView.frame.origin.y,userResizableView.frame.size.width,userResizableView.frame.size.height);
    captureVideoPreviewLayer.frame = ResizableViewFrame;
    NSLog(@" %f--- %f--- %f--- %f ---",captureVideoPreviewLayer.frame.origin.x,captureVideoPreviewLayer.frame.origin.y,captureVideoPreviewLayer.frame.size.width,captureVideoPreviewLayer.frame.size.height);
}

4) Now my avcapturePreview is kind of going wild; it does not touch the top edge of the view once it starts editing. It kind of sticks to the bottom right corner but never fully fills the view.

The slog in the delegate logs equal values for both preview and user resizable view.

Upvotes: 3

Views: 876

Answers (1)

Sam
Sam

Reputation: 2579

Simply add:

[captureVideoPreviewLayer setNeedsLayout];
[captureVideoPreviewLayer setNeedsDisplay];

to the end of your delegate method to signal to UIKit that the bounds have changed and the layer's contents need updating.

Upvotes: 1

Related Questions