Why does my CvVideoCamera cover the whole view? - ios

I'm using a CvVideo Camera thus:
- (void)viewDidLoad
{
[super viewDidLoad];
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetiFrame960x540;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.videoCamera start];
}
My storyboard looks like this:
When the view loads, the bar is visible briefly with the rest of the view white. Then when the camera starts it fills the whole screen. Why is it doing this?

Have you tried with a different parent view?
UIView *camView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)];
[self.view addSubview:camView];
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:camView];

Related

the #property showsIndoorMap is invalid in MAMapView of AMap3DMap Pod

- (void)viewDidLoad
{
[super viewDidLoad];
[MAMapServices sharedServices].apiKey = #"xxx";
self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
self.mapView.delegate = self;
self.mapView.showsIndoorMap = YES;
self.mapView.showsCompass = NO;
[self.view addSubview:self.mapView];
}
I use the code above to show the map in my app. I want to use "self.mapView.showsIndoorMap = YES;" to show the indoor map but it failed. How can i see the indoor map ?

UITapGestureRecognizer EXC_BAD_ACCESS in self-contained UIView subclass

I've used UITapGestureRecognizer tons of times, but in this case I'm getting EXC_BAD_ACCESS when a tap occurs. I think it has to do with the fact that I'm adding it to an Alert-type overlay view. And for some reason the overlay view isn't getting retained even though it's on-screen.
I'm creating the view like this:
HelperView *testHelper = [HelperView helperWithBodyText:#"test text"];
[testHelper presentAtPoint:screenCenter];
The convenience method in HelperView.m looks like this:
+ (id)helperWithBodyText:(NSString*)text
{
return [[self alloc] initWithFrame:CGRectZero bodyText:text];
}
And the rest of the code looks like this:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.container = [[AGWindowView alloc] initAndAddToKeyWindow];
self.container.supportedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;
self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
self.overlay.backgroundColor = [UIColor redColor];
self.overlay.alpha = 0.6;
[self.container addSubviewAndFillBounds:self.overlay]; //this fills the screen with a transparent red color, for testing
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissMe:)];
[self.overlay addGestureRecognizer:tap]; //I want to dismiss the whole view if the overlay is tapped
self.content = [[UIView alloc] initWithFrame:CGRectZero];
}
return self;
}
- (id)initWithFrame:(CGRect)frame bodyText:(NSString*)bodyText
{
self = [self initWithFrame:frame];
if (self) {
//TEST frame
self.content.frame = CGRectMake(0, 0, 217, 134);
// Initialization code
UIImage *bgImage = [[UIImage imageNamed:#"helper-bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(30, 28, 20, 20)];
UIImageView *bgImgView = [[UIImageView alloc] initWithImage:bgImage];
bgImgView.bounds = self.content.frame;
[self.content addSubview:bgImgView];
}
return self;
}
- (void)presentAtPoint:(CGPoint)loc
{
CGPoint newPoint = [self.container convertPoint:loc toView:self.container];
self.content.center = newPoint;
[self.container addSubview:self.content];
}
- (void)dismissMe:(UITapGestureRecognizer*)recognizer
{
//this never happens - I get EXC_BAD_ACCESS when I tap the overlay
}
HelperView is not the view getting displayed and it's not getting retained, but you're using as the target for the gesture recognizer. The AGWindowView property "container" is getting displayed and retained by its superview. Your code needs refactoring since you have this view HelperView that doesn't ever display anything itself, but if you want it to work like this you need to retain HelperView so it doesn't automatically get released. You can do this by assigning it to a strong instance variable.

UIImagePickerController and a small custom preview

I want to use an UIImagePickerController non-modally, with a small square preview. However, I get a big black bar at the bottom of the preview, which I can't get rid of (see the screenshot). Why is it there, and how can I get rid of it?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
_imagePickerVC = [[UIImagePickerController alloc] init];
_imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerVC.mediaTypes = #[ (NSString *)kUTTypeImage ];
_imagePickerVC.wantsFullScreenLayout = NO;
_imagePickerVC.delegate = (id)self;
_imagePickerVC.navigationBarHidden = YES;
_imagePickerVC.allowsEditing = NO;
_imagePickerVC.showsCameraControls = NO;
_imagePickerVC.cameraDevice = UIImagePickerControllerCameraDeviceFront;
CGRect previewFrame = CGRectMake(0, 0, 150, 150);
[_imagePickerVC.view setFrame:previewFrame];
_imagePickerVC.view.autoresizesSubviews = YES;
[self.view addSubview:_imagePickerVC.view];
[_imagePickerVC viewWillAppear:YES];
[_imagePickerVC viewDidAppear:YES];
}
This is a misuse of UIImagePickerController. To make your own image-capture interface, simply use AVFoundation.

How to load custom view in UIStoryBoard?

I am interested to write my custom view, so I created the following xib file:
This is the definition file:
- (void)_baseInit {
NSLog(#"Unseen View loaded");
[self addSubview:[self activityIndicator]];
[self activityIndicator].alpha = 1.0;
[self activityIndicator].frame = CGRectMake(round(([self imageView].frame.size.width - 25) / 2),
round(([self imageView].frame.size.height - 25) / 2), 25, 25);
[self activityIndicator].hidesWhenStopped = YES;
[self showIndicator];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(move:)];
[self imageView].userInteractionEnabled = YES;
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[[self imageView] addGestureRecognizer:panRecognizer];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self _baseInit];
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder])) {
[self _baseInit];
}
return self;
}
I tried to hook it up in my story board:
And I have my MainViewController call this during viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.unseenView = [[[NSBundle mainBundle] loadNibNamed:#"UnseenView" owner:self options:nil] objectAtIndex:0];
self.unseenView.delegate = self;
Unfortunately, nothing is showing up in my simulator literally nothing, not even the text labels.
However I am seeing the following log messages:
2013-02-20 17:37:58.929 Giordano.iPhone[66857:c07] Unseen View loaded
2013-02-20 17:37:58.934 Giordano.iPhone[66857:c07] Unseen View loaded
What am I doing wrong?
It looks like you are preparing your view correctly, but you are not adding it to the view hierarchy. in the viewDidLoad code you need to add this line:
[self.view addSubview:unseenView];

Hidding UILabel on Init

I'm having a problem with this basic code:
-(id)init{
self = [super init];
if(self){
self.mensaje = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:#"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
return self;
}
All the code works fine, except [self.mensaje setHidden:YES];. The Label is always shown at start.
I hope could help me, this is basic, but necessary!!
Good luck!
This code is in the wrong place. You shouldn't be creating and working with views in the initializer of a view controller (assuming the above code is inside a view controller class).
instead, do the following:
- (id)init
{
self = [super init];
if (self) {
// init any state other than views
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mensaje = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:#"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
This also assumes you are using ARC. If not, you need to add autorelease as follows:
self.mensaje = [[[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)] autorelease];

Resources