我正在尝试使用垂直滚动创建UIPageControl
。默认情况下,您只能在水平方向上滑动,但如何将其向上滑动?
这是我的代码:
#pragma mark page control setup
- (void)setupPageScroll {
_pageControl.transform = CGAffineTransformMakeRotation(M_PI /2 );
_pageControl.currentPage = 0;
_pageControl.numberOfPages = 3;
[_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width * _pageControl.numberOfPages, _scrollView.frame.size.height)];
_scrollView.delegate = self;
[self createPageWithView:_tower1 forPage:0];
[self createPageWithView:_tower2 forPage:1];
[self createPageWithView:_tower3 forPage:2];
}
- (void)createPageWithView:(UIView *)iview forPage:(int)page
{
UIView *newView = [[UIView alloc] initWithFrame:
CGRectMake(_scrollView.frame.size.width * page, 0, _scrollView.frame.size.width, _scrollView.frame.size.height)];
[newView addSubview:iview];
[_scrollView addSubview:newView];
}
- (IBAction)pageChanged:(id)sender {
CGRect pageRect = CGRectMake(_pageControl.currentPage * _scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height);
[_scrollView scrollRectToVisible: pageRect animated: YES];
}
- (void)scrollViewDidScroll: (UIScrollView *) sView
{
CGFloat offset = _scrollView.contentOffset.x;
CGFloat pageSize = _scrollView.frame.size.width;
int page = floor((offset + (pageSize/2)) / pageSize);
_pageControl.currentPage = page;
}