如何从右到左和从左到右水平滚动图像
how to scroll a image horizontally right to left and left to right
我想从左到右和从右到左滚动图像。表示当图像完成从左向右滚动时,然后自动从右向左滚动启用,然后重复。
就像这张图片。任何想法或任何建议或示例代码将不胜感激。
您应该使用 UIView animate
函数,而不是使用 NSTimer
。
我刚刚尝试了以下代码
在viewDidLoad
UIImage *image = [UIImage imageNamed:@"image.png"];
imageV = [[UIImageView alloc] initWithImage:image];
[self.scrollView addSubview:imageV];
并在 viewDidAppear
[UIView animateWithDuration:3.0 animations:^{
self.scrollView.contentOffset = CGPointMake(imageV.frame.size.width - self.scrollView.frame.size.width, 0);
}];
我想从左到右和从右到左滚动图像。表示当图像完成从左向右滚动时,然后自动从右向左滚动启用,然后重复。
就像这张图片。任何想法或任何建议或示例代码将不胜感激。
您应该使用 UIView animate
函数,而不是使用 NSTimer
。
我刚刚尝试了以下代码
在viewDidLoad
UIImage *image = [UIImage imageNamed:@"image.png"];
imageV = [[UIImageView alloc] initWithImage:image];
[self.scrollView addSubview:imageV];
并在 viewDidAppear
[UIView animateWithDuration:3.0 animations:^{
self.scrollView.contentOffset = CGPointMake(imageV.frame.size.width - self.scrollView.frame.size.width, 0);
}];