I have made a UIImagePicker
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
And I want to add a half circle to to so I do this,
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextBeginPath(gc);
CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1);
CGContextClosePath(gc); // could be omitted
CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor);
CGContextFillPath(gc);
UIView *someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
[someView.layer renderInContext:gc];
[picker setCameraOverlayView:someView];
But then when I show the picker like so
[self presentViewController:picker animated:YES completion:NULL];
I don't see the semicircle? Why is this happening?
Thanks
Hey you are not going on proper way.
Do the below step it will help you...
See the below answer..
https://stackoverflow.com/questions/5552210/uitableviewcells-invalid-context-trying-to-draw
CircleView.h
#import <UIKit/UIKit.h>
#interface CircleView : UIView
#end
CircleView.m
#import "CircleView.h"
#implementation CircleView
- (void)drawRect:(CGRect)rect
{
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextBeginPath(gc);
CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1);
CGContextClosePath(gc); // could be omitted
CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor);
CGContextFillPath(gc);
}
#end
Implimenttion of adding half circle in your imagepicker is here
UIImagePickerController *controller = [[UIImagePickerController alloc]init];
controller.delegate=self;
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:^{
CircleView *someView = [[CircleView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
[someView setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
[controller setCameraOverlayView:someView];
}];
Related
I'm trying to add a simple text label over a video preview. The video preview works fine, but the text label is no where to be found. The compiler isn't giving me any errors or warnings either. I know I'm mixing dot notation in there, but I'm not sure if that's my root cause or not.
This is a clip from my .m file:
#interface AVRecorderDocument ()
#property (retain) AVCaptureVideoPreviewLayer *previewLayer;
#property (nonatomic, strong) NSTextField *labelVideoOverlay;
#end
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
CALayer *previewViewLayer = [[self previewView] layer];
self.labelVideoOverlay = [[NSTextField alloc] initWithFrame:CGRectMake(100, 120, 200, 40)];
self.labelVideoOverlay.stringValue = #"TEST";
self.labelVideoOverlay.backgroundColor = [NSColor blackColor];
self.labelVideoOverlay.textColor = [NSColor whiteColor ];
[previewViewLayer setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
AVCaptureVideoPreviewLayer *newPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[self session]];
[newPreviewLayer setFrame:[previewViewLayer bounds]];
[newPreviewLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
[previewViewLayer addSublayer: self.labelVideoOverlay.layer];
[previewViewLayer addSublayer:newPreviewLayer];
[self setPreviewLayer:newPreviewLayer];
[newPreviewLayer release];
}
It looks like although you've added the video preview as a sublayer, you still need to add the overlay as a subview to your main view. I did something similar like this recently (just with an UIImageView), but the principal should still be the same.
self.overlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"overlaygraphic.png"]];
self.overlayImageView.translatesAutoresizingMaskIntoConstraints = NO;
[[self view] addSubview:self.overlayImageView];
So, you could do something like:
self.labelVideoOverlay = [[NSTextField alloc] initWithFrame:CGRectMake(100, 120, 200, 40)];
self.labelVideoOverlay.stringValue = #"TEST";
self.labelVideoOverlay.backgroundColor = [NSColor blackColor];
self.labelVideoOverlay.textColor = [NSColor whiteColor ];
[[self view] addSubview:self.labelVideoOverlay];
I am trying to call a method to ViewController class form AppDelegate, it enter to the method but the problem is that is not displaying anything , I was looking for, but I canĀ“t find the answer. Some one could help me? thanks
this is the code :
AppDelegate.m
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (mainDelegate.isflagON=TRUE)
{
ViewController *vc=[ViewController new];
[vc pause];
}
}
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *mainDelegate = [[UIApplication sharedApplication] delegate];
if (mainDelegate.isflagON==false)
{
mainDelegate.isflagON=true;
CGSize viewSize = self.view.bounds.size;
// Add this line
GameScene *scene = [[GameScene alloc] initWithSize:viewSize];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.scene = scene;
// Configure the view.
skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Present the scene.
[skView presentScene:scene];
}else
{
[self doPause];
}
}
-(void) imprime
{
[self doPause];
}
- (void)doPause {
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
backImageView = [[UIImageView alloc] initWithFrame:myImageRect];
[backImageView setImage:[UIImage imageNamed:#"dialogBox.png"]];
[self.view addSubview:backImageView];
[self.view sendSubviewToBack:backImageView];
//set the position of the button
buttonContinuar = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonContinuar setBackgroundImage:[UIImage imageNamed:#"dialogButton.png"]
forState:UIControlStateNormal];
buttonContinuar.frame = CGRectMake(40.0f, 50.0f, 120, 35);
[buttonContinuar addTarget:self action:#selector(buttonWasClicked:) forControlEvents:UIControlEventTouchUpInside];
[buttonContinuar setTitle:#"Continuar" forState:UIControlStateNormal];
//add the button to the view
[self.view addSubview:buttonContinuar];
buttonMapa = [UIButton buttonWithType:UIButtonTypeCustom];
//[button setTitle:#"Continuar" forState:UIControlStateNormal];
[buttonMapa setBackgroundImage:[UIImage imageNamed:#"dialogButton.png"]
forState:UIControlStateNormal];
buttonMapa.frame = CGRectMake(40.0f, 85.0f, 120, 35);
[buttonMapa addTarget:self action:#selector(buttonMapaClicked:) forControlEvents:UIControlEventTouchUpInside];
[buttonMapa setTitle:#"Mapa" forState:UIControlStateNormal];
//add the button to the view
[self.view addSubview:buttonMapa];
buttonMenu = [UIButton buttonWithType:UIButtonTypeCustom];
//[button setTitle:#"Continuar" forState:UIControlStateNormal];
[buttonMenu setBackgroundImage:[UIImage imageNamed:#"dialogButton.png"]
forState:UIControlStateNormal];
buttonMenu.frame = CGRectMake(40.0f, 120.0f, 120, 35);
[buttonMenu addTarget:self action:#selector(buttonMenuClicked:) forControlEvents:UIControlEventTouchUpInside];
[buttonMenu setTitle:#"Menu" forState:UIControlStateNormal];
//add the button to the view
[self.view addSubview:buttonMenu];
}
You can try this
- (void)applicationWillEnterForeground:(UIApplication *)application
{
if (mainDelegate.isflagON=TRUE)
{
ViewController *vc=[[ViewController alloc]init];
[vc pause];
}
}
I am tyring to add UISegmentedControl to UIScrolview programmatically.
I am using below code..
I don't why the scrollview is not enabled.
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
scroll.contentSize = CGSizeMake(320, 700);
scroll.showsHorizontalScrollIndicator = YES;
NSArray *menu = [NSArray arrayWithObjects:[UIImage imageNamed:#"Accountimg.png"],[UIImage imageNamed:#"Challengesimg.png"],[UIImage imageNamed:#"Profileimg.png"],[UIImage imageNamed:#"Challengesimg.png"],nil];
UISegmentedControl *menuSegmentedControl = [[UISegmentedControl alloc] initWithItems:menu];
menuSegmentedControl.frame = CGRectMake(0,0,450,40);
menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[scroll addSubview:menuSegmentedControl];
[menuScrollView addSubview:scroll];
[menuSegmentedControl release];
[scroll release];
I am unable to scroll horizontally..
Thanks in advance
UPDATE:
I am able to get the horizontal scroll.
Code updated:
menuSegmentedControl.frame = CGRectMake(0,0,500,35);
menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
menuScrollView.contentSize = CGSizeMake(menuSegmentedControl.frame.size.width, menuSegmentedControl.frame.size.height);
menuScrollView.showsVerticalScrollIndicator = NO;
[menuScrollView addSubview:menuSegmentedControl];
menuScrollView.clipsToBounds = YES;
Thank you.
I am launching detail pages from a UITableView and within that detail page there is an image. I would like it to be zoomable, so I'd like the contents of that detail page to sit inside a scrollView. So far no luck, the labels, textviews and images are fine, but I can't get the ScrollView implemented.
here is my .m: THANKS!
- (void)viewDidLoad {
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.contentSize = CGSizeMake(320, 700);
scrollView.clipsToBounds = YES;
super.view.backgroundColor = [UIColor whiteColor];
[scrollView setUserInteractionEnabled:YES];
self.navigationItem.title = [NSString stringWithFormat:selectedCellItem];
CGRect frame = CGRectMake(0, 0, 10, 10);
self.view = [[UIView alloc] initWithFrame:frame];
self.view.backgroundColor = [UIColor whiteColor];
frame = CGRectMake(0, 320, 10, 10);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
//label.text = selectedCellItem;
label.font=[UIFont fontWithName:#"Verdana-Bold" size:20.0];
label.textAlignment = UITextAlignmentCenter;
[self.view addSubview:label];
[label release];
frame = CGRectMake(0, 320, 320, 60); //Description
UITextView *labelDesc = [[UITextView alloc] initWithFrame:frame];
labelDesc.text = selectedCellDesc;
labelDesc.font=[UIFont fontWithName:#"Verdana" size:12.0];
labelDesc.textAlignment = UITextAlignmentLeft;
//labelDesc.textAlignment = UITextAlignmentTop;
[self.view addSubview:labelDesc];
[labelDesc release];
frame = CGRectMake(0, 0, 320, 320); //Image
UIImageView *imageItem = [[UIImageView alloc] initWithFrame:frame];
[imageItem setImage:[UIImage imageNamed:selectedCellImage]];
// GET THIS ONE WORKING RIGHT>>[imageItem setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#.png", [[NSBundle mainBundle] bundlePath], selectedCellImage]]]; //use
//imageItem = [[UIImageView alloc] initWithContentsOfFile:[NSString stringWithFormat:#"shirt.png", [[NSBundle mainBundle] bundlePath]]];
//labelDesc.font=[UIFont fontWithName:#"Zapfino" size:13.0];
//labelDesc.textAlignment = UITextAlignmentCenter;
imageItem.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageItem];
//[imageItem release];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
I think that you're missing the following line to add the UIScrollView as a subview.
[self.view addSubView:scrollView];
i have implemented the following viewDidLoad() Method:
- (void)viewDidLoad {
[super viewDidLoad];
// loading images into the queue
loadImagesOperationQueue = [[NSOperationQueue alloc] init];
AFOpenFlowView *openFlow = self.view;
theControl = [[UIControl alloc] initWithFrame:self.view.frame];
NSString *imageName;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(10, 10, 40, 40);
[btn addTarget:self action:#selector(testMethode) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:#"<<" forState:UIControlStateNormal];
[btn setHidden:YES];
[theControl addSubview:btn];
for (int i=0; i < 10; i++) {
imageName = [[NSString alloc] initWithFormat:#"cover_%d.jpg", i];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
UIImage *aktuellesImage = imageView.image;
UIImage *scaledImage = [aktuellesImage scaleToSize:CGSizeMake(100.0f, 100.0f)];
[openFlow setImage:scaledImage forIndex:i];
// [(AFOpenFlowView *)self.view setImage:scaledImage forIndex:i];
[imageName release];
[aktuellesImage release];
}
[theControl addSubview:openFlow];
[theControl setUserInteractionEnabled:YES];
[(AFOpenFlowView *)self.view setNumberOfImages:10];
}
And the following touchesEnded() Method:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[btn setHidden:NO];
}
But the touchesEnded doesn't work, and the Button will not shown when i touch the picture, does anybody know what is the Problem???
Greetings Marco
Make sure your view has user interaction enabled in order to register touches. This can be set in your View Controller thusly:
self.view.userInteractionEnabled = YES;