Noob here: Been working on a project which is essentially one of those so-called soundboard apps, tap a button for a sound. While successfully managed to draw the buttons to rotate correctly in all orientations, I've been unable to combine with AudioServicesPlayAlertSound for the sound effects. Been working with InterfaceBuilder and everything seems connected right, is there something in the code that I'm missing?
Anyway, here is the code for AutosizeViewController.h
#import <UIKit/UIKit.h>
#include <AudioToolbox/AudioToolbox.h>
@interface AutosizeViewController : UIViewController {
UIButton *button1;
UIButton *button2;
UIButton *button3;
UIButton *button4;
UIButton *button5;
UIButton *button6;
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
}
@property (readwrite) CFURLRef soundFileURLRef;
@property (readonly) SystemSoundID soundFileObject;
@property (nonatomic, retain) IBOutlet UIView *button1;
@property (nonatomic, retain) IBOutlet UIView *button2;
@property (nonatomic, retain) IBOutlet UIView *button3;
@property (nonatomic, retain) IBOutlet UIView *button4;
@property (nonatomic, retain) IBOutlet UIView *button5;
@property (nonatomic, retain) IBOutlet UIView *button6;
- (IBAction) playAlertSound;
@end
Here is the code for AutosizeViewController.m
#import "AutosizeViewController.h"
@implementation AutosizeViewController
@synthesize button1;
@synthesize button2;
@synthesize button3;
@synthesize button4;
@synthesize button5;
@synthesize button6;
@synthesize soundFileURLRef;
@synthesize soundFileObject;
#ifdef __IPHONE_3_0
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
#else
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
#endif
if (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
button1.frame = CGRectMake(100, 33, 226, 275);
button2.frame = CGRectMake(440, 33, 226, 275);
button3.frame = CGRectMake(100, 360, 226, 275);
button4.frame = CGRectMake(440, 360, 226, 275);
button5.frame = CGRectMake(100, 693, 226, 275);
button6.frame = CGRectMake(440, 693, 226, 275);
}
else
{
button1.frame = CGRectMake(100, 50, 226, 275);
button2.frame = CGRectMake(400, 50, 226, 275);
button3.frame = CGRectMake(700, 50, 226, 275);
button4.frame = CGRectMake(100, 400, 226, 275);
button5.frame = CGRectMake(400, 400, 226, 275);
button6.frame = CGRectMake(700, 400, 226, 275);
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation || UIInterfaceOrientationPortraitUpsideDown);
}
// Get the main bundle for the app
CFBundleRef mainBundle = CFBundleGetMainBundle ();
// Get the URL to the sound file to play. The file in this case
// is "tap.aiff"
soundFileURLRef = CFBundleCopyResourceURL (mainBundle,CFSTR ("tap"),CFSTR ("aif"),NULL);
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);
- (IBAction) playSystemSound {
AudioServicesPlaySystemSound (self.soundFileObject);
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.button1 = nil;
self.button2 = nil;
self.button3 = nil;
self.button4 = nil;
self.button5 = nil;
self.button6 = nil;
}
- (void) dealloc {
[super dealloc];
AudioServicesDisposeSystemSoundID (self.soundFileObject);
CFRelease (soundFileURLRef);
}
}
@end
Thanks for any help and tips