我的滚动视图中有4页,我有4个按钮。如果用户按下第一个按钮,我想跳到第1页,依此类推其余的三个按钮。我不知道该怎么做。
myview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:myview];
scroll1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll1.pagingEnabled = NO;
NSInteger numberOfViews1 = 8;
float h = 0;
for (int i = 0; i < numberOfViews1; i++) {
CGFloat xOrigin = i * self.view.frame.size.height;
printf("%f\n",xOrigin);
scrollview1 = [[UIView alloc] initWithFrame:CGRectMake(0,xOrigin, self.view.frame.size.width, self.view.frame.size.height)];
scrollview1.backgroundColor = [UIColor colorWithRed:1-h green:1 blue:1 alpha:1];
[scroll1 addSubview:scrollview1];
[scrollview1 release];
h = h + 0.2f;
}
scroll1.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * numberOfViews1);
[self.view addSubview:scroll1];
答案 0 :(得分:1)
使用scrollRectToVisible:animated:如果你知道每个页面在scrollview中开始的y-coord。