我有UIScrollView
。我将图像添加为子视图。问题是如何制作类似于iOS主屏幕的幻灯片。也许可以通过计算滚动的结束点来完成,如果它的x位置大于scrollView宽度的一半,那么执行UIScrollView setContentOffset:animated:
方法。有什么想法吗?
答案 0 :(得分:0)
委托
@interface ViewController : UIViewController<UIScrollViewDelegate>
滚动型:
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(960.0f, 480.0f); // customize it
和
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pagecontrol.currentPage = page;
}
PageControl值已更改选择器:
- (IBAction)changePage:(id)sender {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pagecontrol.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
}
更多信息:http://www.iosdevnotes.com/2011/03/uiscrollview-paging/