【发布时间】:2014-05-22 09:53:33
【问题描述】:
我目前正在尝试构建一个图像查看器,它每 30 秒移动到下一张照片,它还允许手动向左/向右滑动到下一张/上一张照片。
到目前为止,我已经构建了两个独立的应用程序,一个具有滑动功能,另一个具有计时器。我已经在网上尝试了许多教程,并且正在寻找可以为我指明正确方向的人。
此代码每三十秒切换一次图像
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIImageView *animatedImageView = [[UIImageView alloc]
initWithFrame:CGRectMake(0, 55, 400, 550)];
[self.view addSubview:animatedImageView];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"IMG_0052.JPG"],
[UIImage imageNamed:@"IMG_0054.JPG"],
[UIImage imageNamed:@"IMG_0081.JPG"],
nil];
animatedImageView.animationDuration = 30.0 * [animatedImageView.animationImages count];
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];
}
第二段代码具有滑动功能,我希望将两者结合起来
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image1 = [UIImage imageNamed:@"workExample.jpg"];
UIImage *image2 = [UIImage imageNamed:@"IMG_0054.JPG"];
UIImage *image3 = [UIImage imageNamed:@"IMG_0052.JPG"];
imageArray = [NSArray arrayWithObjects:image1, image2, image3, nil];
for (int i = 0; i < [imageArray count]; i++) {
//This is to create a imageview for every single pagecontrol
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [imageArray objectAtIndex:i];
[self.scrollView addSubview:imageView];
}
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * [imageArray count], scrollView.frame.size.height);
}
【问题讨论】:
-
启动计时器和scrollToRect:然后当用户滚动时使计时器失效。当他们停止滚动时重新验证它.. ?
标签: ios objective-c uiimageview