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;
Related
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];
}];
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 have code that successfully creates a custom UIBarButtonItem that appears on the navigation bar. I use the code in other view controllers, and it works perfectly, but in the UITableViewController, the button appears as the regular BackButtonItem. Can someone help me out? Here is the code that I use in the viewDidLoad method in all of the viewControllers
#implementation P2OListViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;
UIImage *backButtonImage = [UIImage imageNamed:#"button-back#2x.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, 60, 35);
[backButton addTarget:self
action:#selector(goToMenu:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[UIBarButtonItem alloc]initWithCustomView:backButton];
self.navigationItem.backBarButtonItem = back;
- (void)viewWillAppear:(BOOL)animated {
}
- (void)goToMenu:(id)sender {
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
hide the default backBarButtonItem by setting its hide property to yes
self.navigationItem.hidesBackButton = YES;
in your viewWillAppear
- (void)viewWillAppear:(BOOL)animated
{
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;
UIImage *backButtonImage = [UIImage imageNamed:#"button-back#2x.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, 60, 35);
[backButton addTarget:self
action:#selector(goToMenu:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[UIBarButtonItem alloc]initWithCustomView:backButton];
self.navigationItem.backBarButtonItem = back;
}
if above not works try this & see what happens:
if (!self.navigationItem.backBarButtonItem.hidden) {
self.navigationItem.backBarButtonItem.hidden = YES;
}
else {
NSLog(#"back button already hidden");
}
How can I open a view when I clicked on annotation's button with a navigation button to go back to my mapkit and pass some parameters to the view?
Regards
I have found a solution. Inside:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
Add:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btn addTarget:self action:#selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];
Then have a function to open the desired view:
-(void)pinTouched:(UIButton *)sender
{
myView.transform = CGAffineTransformMakeScale(.01, .01);
[self.view addSubview:myView];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
...
...
...
//important
//otherwise calloutAccessoryControlTapped not called
pin.canShowCallout = YES;
pin.calloutOffset = CGPointMake(-10, -10);
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"some.png"]];
leftIconView.backgroundColor = [UIColor clearColor];
leftIconView.contentMode = UIViewContentModeScaleAspectFit;
leftIconView.frame = CGRectMake(0, 0, 40, 40);
pin.leftCalloutAccessoryView = leftIconView;
....
....
return pin;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
// annotation tapped
float viewWidth = 100;
float viewHeight = 300;
float viewX = 50;
float viewY = 50;
CGRect viewRect = CGRectMake(viewX,viewY, viewWidth, viewHeight);
UIView *viewSub = [[UIView alloc] initWithFrame:viewRect];
viewSub.backgroundColor = [UIColor redColor];
viewSub.tag = 666;
[self.view addSubview:viewSub];
[self.view bringSubviewToFront:viewSub];
}
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];