Hi Ole,
I've taken on your suggestions and have visited the dev reference center. Changing the state of the play pause pause button has been a breeze.
However adding my panel subviews to my UIVIEWController and animating is proving very difficult for me (objective -c novice).
First of all when I try to make my panel views I get warnings saying that the panel UIView may not respond to initWithFrame. (initwithframe is a function of UIView ?)
Secondly I can't add an image to my panel UIView. I get warning saying
warning: passing argument 1 of 'addSubview:' from distinct Objective-C type
.
Finally when trying to apply animation to my panel I get errors saying
UIView' may not respond to '-commitAnimations' and any other animation related method I try to add.
Can you help? I think mainly I don't understand why I'm getting these "may not respond to method" warnings seeing as I'm calling the method on the correct type (or so I think)
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// SET UP THE PLAY PAUSE BUTTON
playPause = [UIButton buttonWithType:UIButtonTypeCustom];
playPause.frame = CGRectMake(-20,280, 100,100);
[playPause setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playPause addTarget:self action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];
playing=NO;
//SET UP THE AUDIO PLAYER
NSLog(@"Set up theAudio");
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/DumpTheChump.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
//SETUP THE BOTTOM part of the PANEL
UIImage *panelBottomImage=[UIImage imageNamed:@"panel_bottom.png"];
panelBottom=[UIView initWithFrame:(CGRectMake(-20, 280, 285, 128))];
[panelBottom addSubview:panelBottomImage];
//SETUP THE TOP PART OF THE PANEL. (THE ONE THAT SHOULD SLIDE UP AND DOWN)
UIImage *panelTopImage=[UIImage imageNamed:@"panel_top.png"];
panelTop=[UIView initWithFrame:(CGRectMake(-20, 280, 285, 128))];
[panelTop addSubview:panelTopImage];
[self.view addSubview:panelBottom];
[self.view addSubview:panelTop];
[self.view addSubview:playPause];
// 285*128
}
- (void) buttonPushed:(id)sender
{
NSLog(@"It works!");
switch (playing) {
case NO:
playing=YES;
[audioPlayer play];
[playPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[panelTop beginAnimations:nil context:nil];
[panelTop setAnimationDuration:2];
[panelTop setAnimationDelegate:self];
//UIView setAnimationDidStopSelector:@selector(onAnimationC omplete:finished:context;
// set the position where button will move to
panelTop.frame = CGRectMake(-20, 100, 285, 128);
[panelTop commitAnimations];
break;
case YES:
playing=NO;
[audioPlayer pause];
[playPause setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[panelTop beginAnimations:nil context:nil];
[panelTop setAnimationDuration:2];
[panelTop setAnimationDelegate:self];
//UIView setAnimationDidStopSelector:@selector(onAnimationC omplete:finished:context;
// set the position where button will move to
panelTop.frame = CGRectMake(-20, 280, 285, 128);
[panelTop commitAnimations];
break;
default:
break;
}
}