Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-18-2010, 08:33 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: London
Posts: 15
mrsaxon10 is on a distinguished road
Default Image Picker button playing sound?

Hi

I have been having a very curious problem basically I am making an app. Where a photo can be selected by the image picker that image then becomes the background image of the app.

Their using the UIGestureRecognizerDelegate the user can press on the screen to make a small flower bud appear (Over the background image), when the flower bud is pressed it becomes a flower with a sound to go with it.


However when i run the app their is a problem . When i press on the button that opens the image picker, instead the sound plays. When i remove the code that makes the flowers appear the image picker works fine. Maybe its just too late in the night but I cannot see where i have gone wrong if anyone can point out my mistake that would be a big help

Thanks


Code:
 - (IBAction)barbTn2:(id)sender {


UIImagePickerController *imagePicker;
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate=self;
	UIPopoverController *pop1 = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
	[pop1 setDelegate:self];
	[pop1 presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
	[pop1 setPopoverContentSize:CGSizeMake(320, 400)];
	[imagePicker release];
}



- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
	chosenImage.image=[info objectForKey:
					   UIImagePickerControllerOriginalImage];
	[imagePickerPopoverController dismissPopoverAnimated:YES];
	[imagePickerPopoverController release];
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [imagePickerPopoverController dismissPopoverAnimated:YES];
    [imagePickerPopoverController release];
}



- (void)popoverControllerDidDismissPopover:
(UIPopoverController *)popoverController {
    [popoverController release];
}

	

	




- (void)viewDidLoad {
	[super viewDidLoad];

	[self preparePopSound];
	UITapGestureRecognizer *tapRecognizer = 
	[[UITapGestureRecognizer alloc] 
	 initWithTarget:self 
	 action:@selector(handleTapFrom:)];

	
	[self.view addGestureRecognizer:tapRecognizer];
	[tapRecognizer setNumberOfTapsRequired:1];
	[tapRecognizer release];
	
	
	

}







- (void)handleTapFrom:(UITapGestureRecognizer *)recognizer {
	CGPoint location = [recognizer locationInView:self.view];
	
	UIView *hitView = [self.view hitTest:location withEvent:nil];
	if (hitView != self.view) {
		[(UIImageView *)hitView 
		 setImage:[UIImage imageNamed:@"flower.png"]];
	
		
		
		[self makePopSound];
	
		
		
	} else {
	
		
		
		
		CGRect rect = CGRectMake(location.x - 40, 
								 location.y - 40, 80.0f, 80.0f);
		UIImageView *image = 
		[[UIImageView alloc] initWithFrame:rect];
		[image setImage:[UIImage imageNamed:@"flower2.png"]];
		[image setUserInteractionEnabled: YES];
		
		
		UIPinchGestureRecognizer *pinchRecognizer = 
		[[UIPinchGestureRecognizer alloc] 
		 initWithTarget:self 
		 action:@selector(handlePinchFrom:)];
		[image addGestureRecognizer:pinchRecognizer];
		[pinchRecognizer release];
		
		[self.view addSubview:image];
		[image release];
	
	}
	
}




- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:.75];
	[UIView setAnimationBeginsFromCurrentState:YES];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
	[UIView commitAnimations];
	
	for (UIView *subview in [self.view subviews]) {
		[subview removeFromSuperview];
	}
}


- (void)handlePinchFrom:(UIPinchGestureRecognizer *)recognizer {
	
	CGAffineTransform transform = CGAffineTransformMakeScale([recognizer scale], [recognizer scale]);
	recognizer.view.transform = transform;
    
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:0.65];
	[UIView commitAnimations];
}






-(void)preparePopSound {
	NSURL *url = [NSURL fileURLWithPath:
				  [NSString stringWithFormat:@"%@/open.aif", 
				   [[NSBundle mainBundle] resourcePath]]];
	
	NSError *error;
	player = [[AVAudioPlayer alloc] 
			  initWithContentsOfURL:url error:&error];
	player.numberOfLoops = 0;
}



-(void)makePopSound {
	[player play];
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	
    [super didReceiveMemoryWarning];
	

}

- (void)viewDidUnload {
	
}


- (void)dealloc {
	
	

	
    [chosenImage release];
	
	
	
	
	
    [super dealloc];
}

@end
mrsaxon10 is offline   Reply With Quote
Reply

Bookmarks

Tags
image, picker, sound, uiimagepickercontrolle

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 337
9 members and 328 guests
Absentia, anothermine, Chickenrig, Domele, givensur, heshiming, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0