创建按钮会导致图像数组

问题描述 投票:0回答:1

我已经按照这个 tutorial 使用 UIScrollView 进行分页,它有一些带有图像的数组。 我想创建一个按钮,将我带到我选择的图像数组(澄清一下:当我点击按钮时,它会将我带到 photo3.png)。 请先查看教程以理解我的意思。 预先感谢

ios arrays xcode pagination uiscrollview
1个回答
2
投票

您是否尝试过使用UIScrollView的以下任务?

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

您只需传递与您要显示的页面的

CGRect
相匹配的
frame

编辑添加代码

-(IBAction)scrollToPageNumberFive:(id)sender {
  int scrollToPage = 5; //just an example
  int scrollToX = 5-1; //because X starts from 0
  [self.scrollView scrollRectToVisible:CGRectMake(scrollToX*self.scrollView.frame.size.width,0,self.scrollView.frame.size.width,self.scrollView.frame.size.height) animated:YES];
}

调用

scrollRectToVisible:animated:
将调用教程中的
scrollViewDidScroll:
方法,该方法将加载和清除适当的页面。

© www.soinside.com 2019 - 2024. All rights reserved.