I have some code in which i need to translate an UIImageView from the top of an iPad screen to the bottom with one UIButton, then translate it back with an other UIButton using this very UIImageView
I've tried this code below (**) but each time i push the button, its create a new subview.
How can i get through with this?
Thx
(**)
- (void)viewDidLoad {
[super viewDidLoad];
myImage = [UIImage imageNamed:@"myImage.png"];
UIImageView *bmyView = [[UIImageView alloc] initWithImage:bmyImage];
myView.frame = CGRectMake(100, -740, 568, 790);
myView.opaque = NO;
[self.view addSubview:myView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(200, 0, 90, 30);
button.adjustsImageWhenHighlighted = NO;
button.opaque = NO;
[button setTitle:@"Out" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed ) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonPressed {
double speed = 1 / round(random() % 100) + 1.0;
UIImageView *myView =[[UIImageView alloc] initWithImage:myImage];
myView.frame = CGRectMake(100, -740, 568, 790);
myView.opaque = NO;
[self.view addSubview:myView];
[UIView beginAnimations:nil context:myView];
[UIView setAnimationDuration: 2*speed ];
myView.frame = CGRectMake(100, 0, 568, 790);
myView.opaque = NO;
[UIView setAnimationDidStopSelector:@selector(onAnimationC omplete:finished:context

];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete

NSString *)animationID finished

NSNumber *)finished context

void *)context {
UIImageView *myView = context;
myView.frame = CGRectMake(100, 0, 568, 790);
myView.opaque = NO;
[self.view addSubview:myView];
[myView release];
}