Hi guys! That's my very first post on SOF. I'm a new programmer at objective-c. Heres the "problem" i'm dealing with
I created 2 UIbutton : one to pull an UIImageView from the top of the screen and the other to push it back. I have the code for the action** but i dont know how to relate it to an if-statement if(button1 pressed) then pull view else(button2 pressed) then push view back.
-(void)viewDidLoad{
{super viewDidLoad]
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(200, 0, 90, 30);
[button1 addTarget:self action:@selector(buttonPressed1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(400, 0, 90, 30);
[button2 addTarget:self action:@selector(buttonPressed2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
}
**
-(void)buttonPressed1 {
double speed = 1 / round(random() % 100) + 1.0;
UIImageView *banetteView2 = [[UIImageView alloc] initWithImage:banetteImage];
banetteView2.frame = CGRectMake(100, -740, 568, 790);
banetteView2.opaque = NO;
[self.view addSubview:banetteView2];
[UIView beginAnimations:nil context:banetteView2];
[UIView setAnimationDuration: 2*speed ];
//banetteView2.frame = CGRectMake(100, -1, 568, 790);
UIImageView *banetteView = [[UIImageView alloc] initWithImage:banetteImage];
banetteView.frame = CGRectMake(100, -740, 568, 790);
banetteView.opaque = NO;
banetteView.hidden = YES;
[self.view addSubview:banetteView];
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
UIImageView *banetteView2 = context;
[banetteView2 release];
double speed = 1 / round(random() % 100) + 1.0;
banetteView2.frame = CGRectMake(100, 0, 568, 790);
banetteView2.opaque = NO;
[self.view addSubview:banetteView2];
[UIView beginAnimations:nil context:banetteView2];
[UIView setAnimationDuration: 2*speed ];
//banetteView2.frame = CGRectMake(100, -740, 568, 790);
}