I'm having difficulty moving an image from left to right. Now i have a situation when i have an infinite animation but it just replaces the current image to another.
here's my code:
-(void)startAnimationTest
{
image.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"pic_1.png"],
[UIImage imageNamed:@"pic_2.png"],
[UIImage imageNamed:@"pic_3.png"], nil];
[image setAnimationDuration:1];
image.animationDuration = 4;
[image startAnimating];
}
thank you,
Eliza
Try adding the images to a scroll view and then animating scrollview on the basis of its content offset. See the sample code attached. Make sure of add a nstimer to call the function repeatdly.
- (void) animateScrollView: (id) sender
{
[UIView beginAnimations:nil context:NULL];
CGPoint contentOffset = scrollView.contentOffset;
contentOffset.x +=3;
[scrollView setContentOffset:contentOffset animated:NO];
[UIView commitAnimations];
if (scrollView.contentOffset.x == (scrollView.bounds.size.width * 5)) {
scrollView.contentOffset = CGPointMake(0, scrollView.bounds.origin.y);
}
}
set timer as follows:
[NSTimer scheduledTimerWithTimeInterval: .03
target: self
selector: @selector(animateScrollView:)
userInfo: nil
repeats: YES];
thats it. Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.