here is what im trying to accomplish here. I want a image to start from the top of the screen and go to the bottem, then when it gets to the bottem it goes back up again. I am able to get the image to go down by doing this
- (void)viewDidLoad {
[super viewDidLoad];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:4.0];
[image setFrame:CGRectMake(0, 0, 30, 1500)];
[UIView commitAnimations];
if ([image setFrame:CGPoint =(0, 0, 30, 1500)]) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:4.0];
[image setFrame:CGRectMake(0, 0, 30, 0)];
[UIView commitAnimations];
}
}
This if statement doesnt work, im not sure how to make this work. Im very new to using points.
Or maybe a while loop? Any ideas? Thanks Very Much!
Have a good day
This code will not run for a start because this line is not valid
if ([image setFrame:CGPoint =(0, 0, 30, 1500)]) {
I believe you meant to compare the location of the view
if (CGPointEqualToPoint(image.frame.origin, CGPointMake(0, 0))) {
Your image width is also set to 1500
in places which does not seem quite right
The final reason this will not work is because the UIView will look at the net changes in location and realise that the view does not move therefore it won't do anything.
What you would need to do is maybe use blocks like this
float duration = 0.5;
int delay = 0;
[UIView animateWithDuration:duration
delay:delay
options:UIViewAnimationCurveLinear
animations: ^{
image.frame = CGRectMake(0, 460, 30, 30);
} completion:^(BOOL finished) {
[UIView animateWithDuration:duration
delay:delay
options:UIViewAnimationCurveLinear
animations: ^{
image.frame = CGRectMake(0, 0, 30, 30);
} completion:nil];
}];