我正在使用以下代码,以建立一个<条码>。 观点:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
问题在于:我如何实施<条码>NStimer,以便每4秒更换一页?
[NSTimer scheduledTimerWithTimeInterval:4.0f
target:self
selector:@selector(updateCounter:)
userInfo:nil
repeats:YES];
我正在努力撰写最新的宣传方法。 请帮助
- (void)updateCounter:(NSTimer *)theTimer {
NSInteger numberOfViews = 3;
int i = 0; i++;
if (i < numberOfViews) {
yOrigin = i * self.view.frame.size.width;
[scroll scrollRectToVisible:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
}
return; }
OK, so with this code, NSTimer
changes from view 1 to view 2, but it stops, it does not change after the next 4 seconds to view 3. What I want to do is to change from view 1, to view 2, after 4 seconds, then to view 3, after 4 seconds, and so on. I want to have as many views as I need.